Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Element.h

Go to the documentation of this file.
00001 
00002 // MathCore = a WYSIWYG equation editor + a powerful math engine     //
00003 // Copyright (C) 2003 by Francesco Montorsi                          //
00004 //                                                                   //
00005 // This library is free software; you can redistribute it and/or     //
00006 // modify it under the terms of the GNU Lesser General Public        //
00007 // License as published by the Free Software Foundation; either      //
00008 // version 2.1 of the License, or (at your option) any later         //
00009 // version.                                                          //
00010 //                                                                   //
00011 // This library is distributed in the hope that it will be useful,   //
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of    //
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      //
00014 // GNU Lesser General Public License for more details.               //
00015 //                                                                   //
00016 // You should have received a copy of the GNU Lesser General Public  //
00017 // License along with this program; if not, write to the Free        //
00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,   //
00019 // MA 02111-1307, USA.                                               //
00020 //                                                                   //
00021 // For any comment, suggestion or feature request, please contact    //
00022 // the administrator of the project at frm@users.sourceforge.net     //
00023 //                                                                   //
00031 
00032 
00033 
00034 #ifndef ELEMENT_H
00035 #define ELEMENT_H
00036 
00037 
00038 // optimization for GCC compiler
00039 #ifdef __GNUG__
00040 #pragma interface "Element.h"
00041 #endif
00042 
00043 // required includes
00044 #include <wx/memory.h>
00045 #include "mc/Setup.h"
00046 #include "mc/Styles.h"
00047 #include "mc/MathUtils.h"
00048 #include "mc/MathHelpers.h"
00049 #include "wx/xml2.h"
00050 
00051 #include "mc/Object.h"
00052 
00053 
00058 #define mcELEMENTMATH_MAX_EXPDEPTH       4
00059 
00062 #define mcELEMENTMATH_MAX_PROCESS_CYCLES     100
00063 
00064 
00065 #define mcELEMENT_DBG_EXPDEPTH  1  
00066 #define mcELEMENT_DBG_SELECTION  2  
00067 #define mcELEMENT_DBG_ID   4  
00068 
00069 
00073 #define mcFIND_NOFLAGS    0
00074 
00078 #define mcFIND_STRICT    1
00079 
00082 #define mcFIND_PARENT    2
00083 
00084 
00087 #define mcMCF_NOMODIFIERS   0
00088 
00092 #define mcMCF_EXTEND_SELECTION  1
00093 
00094 
00095 // compiler needs to know that mcElementGUI, mcElementMath, mcElementIO
00096 // and mcElement classes exist, before we define the mcElementData class.
00097 mcDEFINE_HELPER_CLASSES(mcElement);
00098 
00099 
00100 // defined later
00101 class mcPolynomial;
00102 class mcMonomial;
00103 extern mcElement mcEmptyElement;
00104 extern mcPolynomial mcEmptyPolynomial;
00105 
00106 
00107 
00108 
00116 class mcElementHelpers : public mcObjectRefData
00117 {
00118  friend class mcElement;
00119 
00120 
00121 #ifdef mcENABLE_DATA
00122 public:
00123 
00129  static mcElement *sdata_pElem[mcNUM_ELEMENT_TYPES];
00130 
00131 
00132 
00137 
00143  static mcElementType gui_isKeyBeginKey(const mcKey &ev);
00144  static mcElementType io_isCharBeginChar(const wxString &str);
00145  static mcElementType io_isTagBeginTag(const wxXml2Node &tag);
00146 
00153  static mcElement data_NewElem(mcElementType type, 
00154         const mcElementHelpers *towrap = NULL);
00155 
00159  static mcElement *data_GetInstanceOf(mcElementType type)
00160   { return sdata_pElem[type]; }
00161 
00164  static wxString data_GetGlobalMemoryInfo();
00165 
00170  static void data_UpdateElemArray();
00171 
00181  static int data_GenID(bool bFirstMember = TRUE);
00182 
00184  static void Init();
00185 
00187  static void Cleanup();
00188 
00190 
00191 
00192 protected:   // DATA variables
00193 
00198  int mdata_nID;
00199 
00202  int mdata_nProperties;
00203 
00204 #endif
00205 
00206 
00207 
00208 #ifdef mcENABLE_GUI
00209 protected:   // GUI variables
00210 
00221  const mcStyleArray *mgui_pStyleArray;
00222 
00228  bool mgui_bSelected;
00229 
00233  wxSize mgui_sz;
00234 
00253  int mgui_nExpDepth;
00254 
00255 public:   // customizable variables
00256 
00260  static wxBrush *sgui_pSelectionBrush;
00261 
00266  static wxBrush *sgui_pActivationBrush;
00267 
00273  static mcStyleArray *sgui_pDefaultStyles;
00274 
00279  static int sgui_nAdditionalActivationSpaceLeftRight;
00280 
00281 #endif
00282 
00283 
00284 public:
00285   
00294 
00295 
00296  // properties which are set by the element itself and are handled by the parent
00297 
00301  #define mcEP_NOPROPERTIES       0
00302 
00305  #define mcEP_NOTIFY_PARENTSIZE_CHANGE   1
00306 
00309  #define mcEP_NOTIFY_NEIGHBOR_CHANGE    2
00310 
00313  #define mcEP_FACTOREOUT_ALLOWED     4
00314 
00318  #define mcEP_INITIALIZED      8
00319 
00320 
00321  // properties which can be set by mcElement-external functions but which must be
00322  // handled by the element.
00323 
00329  #define mcEP_HASEXPONENT       16
00330 
00336  #define mcEP_HASSUBSCRIPT       32
00337 
00342  #define mcEP_NONSTANDARD_BASE      64
00343 
00345  // END OF mcELEMENT PROPERTIES SECTION
00346 
00347 
00348 
00349 public:
00350 
00352  mcElementHelpers();
00353 
00354  virtual ~mcElementHelpers() {}
00355 
00356 
00357 
00358  
00359 #ifdef mcENABLE_DATA
00360 public:
00361 
00365 
00367  virtual void data_AddProperty(int p, void *val1 = NULL, void *val2 = NULL) {
00368 
00369   // m_nProperties stores info as bit array; use OR op
00370   // to add properties, AND op to check if a property is set
00371   mdata_nProperties |= p;
00372  }
00373 
00375  virtual void data_RemoveProperty(int p) {
00376   mdata_nProperties &= ~p;
00377  }
00378 
00380  virtual bool data_hasProperty(int p) const {
00381   return ((mdata_nProperties & p) != 0);
00382  }
00383 
00385 
00386 
00387 
00391 
00393  virtual void data_AddRecursiveProperty(mcElementType t, int p, void *val1 = NULL, void *val2 = NULL);
00394 
00396  virtual void data_RemoveRecursiveProperty(mcElementType t, int p);
00397 
00399  virtual bool data_hasRecursiveProperty(mcElementType t, int p) const;
00400 
00402 
00403 
00404  
00408 
00414  virtual mcElementHelpers *data_Clone() const = 0; 
00415 
00420  virtual int data_GetMemoryInfo() const = 0;
00421 
00425  virtual mcElementType data_GetType() const = 0;
00426 
00428 
00429 
00430 
00434 
00441  virtual void data_DeepCopy(const mcElementHelpers *p);
00442 
00445  virtual bool data_isSameAs(const mcElementHelpers *) const;
00446  
00453  virtual bool data_isAllowedBefore(mcElementType type) const   { return TRUE; }
00454  
00458  virtual bool data_isAllowedAfter(mcElementType type) const   { return TRUE; }
00459 
00467  virtual mcElement &data_GetElemFromID(int id) const;
00468 
00473  virtual void data_OnNeighborChange() {
00474   // default implementation does nothing
00475  }
00476 
00480  virtual void data_Update();
00481 
00492 #ifdef __MCDEBUG__
00493  virtual wxString data_Debug(long flags) const
00494   { return wxT("mcElement\n"); }
00495  
00500  virtual wxString data_GetDebugName() const
00501   { return wxT("mcElement"); }
00502 
00503 #else
00504  // this function should be removed by the linker...
00505  inline wxString data_Debug(long) const 
00506   { return wxEmptyString; }
00507  inline wxString data_GetDebugName() const 
00508   { return wxEmptyString; }
00509 #endif 
00510 
00512 
00513 
00514 
00515 
00520 
00526 #ifdef __MCDEBUG__
00527  virtual void data_Check() const;
00528 #else
00529  // this function should be removed by the linker...
00530  inline wxString data_Check() const { return wxEmptyString; }
00531 #endif
00532 
00542  virtual int data_GetChildrenCount() const  { return 0; }
00543 
00561  virtual const mcElement &data_GetConstChild(int n) const;
00562  
00567  virtual mcElement &data_GetChild(int n);
00568  
00570  virtual void data_SetChild(int idx, const mcElement &newchild) {
00571   // non-container elements should just do nothing...
00572   }
00573 
00578  virtual int data_GetChildIdx(const mcElement &p) const;
00579  
00585  virtual bool data_AddChildrenTo(mcElement p);
00586 
00587  // Called by mcElement's standard functions to update the parent-child
00588  // relationships of member classes.
00589  // Override this function if you need to change parent-relationships.
00590  // virtual void data_UpdateParent()
00591  //
00592  // WARNING: THIS FUNCTION IS USELESS: WHEN AN OBJECT HAS MEMBER CLASSES
00593  //          WHICH ARE TIED TO THE ELEMENT ITSELF AS SIBLINGS OR CHILDREN,
00594  //          IT'S NOT REQUIRED TO UPDATE THEM... see also #m_nExpDepth
00595 
00597 
00598 
00599 
00600 
00604 
00606  int data_GetID() const   { return mdata_nID; }
00607 
00613  void data_Init();
00614 
00620 #ifdef __MCDEBUG__
00621  wxString data_GetDebug(int indent, long flags) const;
00622 #else
00623  // this function should be removed by the linker
00624  inline wxString data_GetDebug(int, long) const 
00625   { return wxEmptyString; }
00626 #endif
00627 
00629 
00630 #endif  // mcENABLE_DATA
00631 
00632 
00633 
00634 
00635 
00636 #ifdef mcENABLE_GUI
00637 protected:
00638 
00641  virtual void gui_Init();
00642 
00643 public:
00644 
00649 
00663  virtual bool gui_isBeginKey(const mcKey &ev) const = 0;
00664 
00672  virtual bool gui_isEndKey(const mcKey &ev) const = 0;
00673 
00675 
00676 
00677 
00678 
00682 
00683  // functions grouped under this section belong to the
00684  // USER INPUT SYSTEM group
00685 
00735     virtual int gui_Draw(wxDC &dc, int x, int y, long flags, const wxPoint &pt) const = 0;
00736 
00745  virtual void gui_DoRecalcSize() = 0;
00746 
00757  virtual int gui_GetRelCursorPos(wxDC &dc, wxPoint *pt) const = 0;
00758 
00771  virtual mcMoveCursorRes gui_MoveCursor(mcMoveCursorFlag flag, long modifiers) = 0;
00772 
00784  virtual int gui_MoveCursorUsingPoint(wxDC &dc, const wxPoint &p) = 0;
00785 
00791  virtual void gui_GetCursorPos(mcCursorPos &) const = 0;
00792 
00797  virtual mcCursorPos gui_GetCursorPos() const
00798   { mcCursorPos ret; gui_GetCursorPos(ret); return ret; }
00799 
00806  virtual void gui_SetCursorPos(const mcCursorPos &code) = 0;
00807 
00823  virtual mcInputRes gui_Input(const mcKey &ev, mcElement *newelem) = 0;
00824 
00826  virtual mcInsertRes gui_Insert(const mcElement &toinsert, mcElement *newelem) = 0;
00827 
00829 
00830 
00831 
00832 
00838 
00844 
00852  virtual void gui_OnSelect(wxDC &, wxRect &rc) {
00853   gui_Select();
00854  }
00855 
00865  virtual mcElement gui_GetSelection() const;
00866 
00874  virtual void gui_DeleteSelection();
00875 
00881  virtual mcElement &gui_GetActiveElem(int x, int y, const wxPoint &pt) const;
00882 
00884 
00885 
00886 
00887 
00891 
00894  virtual void gui_SetStyleArray(const mcStyleArray *p);
00895 
00897  virtual void gui_OnRecalcSize(wxSize old);
00898 
00903  virtual void gui_OnParentSizeChange() {
00904   // default implementation does nothing
00905  }
00906 
00912  virtual void gui_DeepRecalcSize();
00913 
00916  virtual bool gui_isAllSelected() const;
00917 
00920  virtual void gui_SelectAll();
00921 
00929  virtual void gui_DeSelect();
00930 
00944  virtual bool gui_Split(mcElement *p)  { return FALSE; }
00945 
00952  virtual bool gui_MergeWith(const mcElement &) {
00953   return FALSE; // default implementation does nothing
00954  }
00955 
00961  virtual bool gui_isSplittable() const {
00962   return FALSE;
00963  }
00964 
00969  virtual void gui_Select() {
00970 
00971   // we don't need to do anything else: size hasn't changed
00972   mgui_bSelected = TRUE;
00973  }
00974 
00978  virtual bool gui_isSelected() const {
00979   return mgui_bSelected;
00980  }
00981 
00991  virtual bool gui_LetInCursor(mcCursorPos code) {
00992   gui_SetCursorPos(code);
00993   return TRUE;
00994  }
00995 
00999  virtual void gui_RecalcSize();
01000 
01003  int gui_GetExpDepth() const    { return mgui_nExpDepth; }
01004 
01009  virtual wxSize gui_GetSize() const  { return mgui_sz; }
01010 
01013  virtual int gui_GetWidth() const  { return mgui_sz.GetWidth(); }
01014 
01017  virtual int gui_GetHeight() const  { return mgui_sz.GetHeight(); }
01018 
01023  virtual wxSize gui_GetSize() {
01024   if (mgui_sz.GetWidth() == mgui_sz.GetHeight() && 
01025    mgui_sz.GetWidth() == -1)
01026    gui_RecalcSize();
01027   return mgui_sz;
01028  }
01029 
01034  virtual int gui_GetWidth() {
01035   if (mgui_sz.GetWidth() == -1)
01036    gui_RecalcSize();
01037   return mgui_sz.GetWidth();
01038  }
01039 
01043  virtual int gui_GetHeight() {
01044   if (mgui_sz.GetHeight() == -1)
01045    gui_RecalcSize();
01046   return mgui_sz.GetHeight();
01047  }
01048 
01051  virtual int gui_GetYAnchor() const {
01052   return gui_GetSize().GetHeight()/2;
01053  }
01054 
01056 
01057 
01058 
01063 
01067  //static int gui_GetExpDepthFromDrawFlags()  
01068  // { return flags & mcDRW_FLAGS_STARTBIT; }
01069 
01074  static void gui_InitDefaultStyles();
01075 
01080  static void gui_DeleteDefaultStyles();
01081 
01087  //static void gui_SetGlobalStyleArray(const mcStyleArray *);
01088 
01092  //bool SyncStyleWithParent();
01093 
01098  //| [...]   mcElementHelpers::sgui_GetStyle(0).[...]
01100  static const mcStyle *gui_GetDefaultStyle(int n);
01101 
01105  static double gui_GetPointSize();
01106 
01109  static double gui_PointSize2Pixels(double pointsize);
01110 
01114  static double gui_Pixels2PointSize(double pointsize);
01115 
01120  static wxSize gui_GetSizeOf(wxDC *dc, const wxString &str);
01121 
01122  static int gui_GetHeightOf(wxDC *, const wxString &); 
01123  static int gui_GetWidthOf(wxDC *, const wxString &);   
01124 
01126 
01127 
01128 
01132 
01142  virtual void gui_UpdateExpDepth();
01143 
01147  void gui_SetAsExpOf(const mcElement &p);
01148 
01154  void gui_SetAtSameLevelOf(const mcElement &p);
01155 
01158  void gui_SetExpDepth(int n)
01159   { mgui_nExpDepth = n; gui_UpdateExpDepth(); }
01160 
01165  const mcStyle *gui_GetStyle(int n) const;
01166 
01168  const mcStyleArray *gui_GetStyleArray() const
01169   { return mgui_pStyleArray; }
01170 
01179  wxSize gui_GetSizeOfChar(wxDC *dc = NULL, const mcElement &p = mcEmptyElement) const;
01180 
01181  int gui_GetHeightOfChar(wxDC *, const mcElement &) const; 
01182  int gui_GetWidthOfChar(wxDC *, const mcElement &) const;    
01183 
01192  const mcStyle *gui_GetStyleForThis() const;
01193 
01197  void gui_SelectStyle(wxDC &dc) const;
01198 
01204  int gui_GetThickness(wxDC *dc) const;
01205 
01213  int gui_GetBaseOffsety(int h) const;
01214 
01218  int gui_GetSubscriptOffsety(int h) const;
01219 
01221 
01222 #endif  // mcENABLE_GUI
01223 
01224 
01225 
01226 
01227 
01228 
01229 
01230 #ifdef mcENABLE_MATH
01231 protected:  // utils
01232 
01234  virtual void math_Init() {}
01235 
01246  virtual mcElement math_RecursiveFind(int &n, 
01247     const mcElement &p, long flags) const; 
01248 
01251  virtual mcElement math_RecursiveFindInChildrenOnly(int &n, 
01252     const mcElement &p, long flags) const;
01253 
01254 
01255 public:
01256 
01257 
01261 
01268  mcElement math_Find(int n, const mcElement &p, long flags = mcFIND_NOFLAGS) const;
01269 
01272  mcElement math_FindInChildrenOnly(int n, const mcElement &p, long flags = mcFIND_NOFLAGS) const;
01273 
01279  int math_NonRecursiveFindInChildren(int n, const mcElement &p, long flags = mcFIND_NOFLAGS) const;
01280 
01283  virtual int math_GetCountOf(const mcElement &p, long flags = mcFIND_NOFLAGS) const;
01284 
01287  virtual int math_GetCountOfChildrenOnly(const mcElement &p, long flags = mcFIND_NOFLAGS) const;
01288 
01291  virtual int math_GetCountOf(const mcSymbolProperties *sym, long flags = mcFIND_NOFLAGS) const;
01292 
01295  virtual int math_GetCountOf(const mcSymbolArray *arr, long flags = mcFIND_NOFLAGS) const;
01296 
01307  virtual int math_GetCountOfSymbolsType(const mcSymbolArray *arr, long flags = mcFIND_NOFLAGS) const;
01308 
01323  virtual int math_Replace(const mcElement &tofind, int n, long flags,
01324       const mcElement &replacement, bool bAttachChildren);
01325 
01338  virtual bool math_Contains(const mcElement &p, long flags = mcFIND_NOFLAGS) const;  
01339 
01341  //bool math_Contains(const mcElement &p, long flags = mcFIND_NOFLAGS) const;  
01342 
01345  bool math_ContainsOneOf(const mcSymbolArray *) const;
01346 
01348  virtual bool math_ContainsSymbol(const mcSymbolProperties *s, 
01349       const mcPolynomial &exp = mcEmptyPolynomial) const;
01350  virtual bool math_ContainsNumber(const mcRealValue &n, 
01351       const mcPolynomial &exp = mcEmptyPolynomial) const;
01352 
01357  virtual bool math_ContainsUnknowns() const;
01358 
01360  virtual bool math_ContainsConstants() const;
01361 
01363  virtual bool math_ContainsParameters() const;
01364 
01367  virtual bool math_ContainsSymbols() const;
01368 
01370  virtual bool math_ContainsInvalidSymbols() const;
01371 
01373 
01374 
01375  
01380 
01384  static bool math_isExpAllowed(mcElement p);
01385  static bool math_isSubAllowed(mcElement p);   
01386 
01390  virtual mcExpSimRes math_MaxSimplify(long flags);
01391 
01394  virtual bool math_isMaxSimplified(long flags) const;
01395 
01404  virtual int math_GetSymbolList(mcSymbol **, int size, const mcSymbol &tofind) const;
01405  virtual int math_GetSymbolList(mcSymbol **, int size, mcSymbolProperties &tofind) const;
01406 
01409  virtual bool math_isConstant() const;
01410 
01413  virtual bool math_EvaluatesTo(const mcRealValue &val) const
01414   { return math_Evaluate() == val; }
01415 
01418  virtual mcRealValue math_EvaluateAt(const mcSymbolProperties *sym, 
01419           const mcRealValue &symval) const;
01420 
01424  virtual bool math_isFinite() const;
01425  
01428  virtual mcRealValue math_GetTotalLenght() const;
01429 
01437  virtual void math_SimpleAdd(const mcElement &p, bool add = TRUE);
01438  virtual void math_SimpleSubtract(const mcElement &p) { math_SimpleAdd(p, FALSE); }
01439  virtual void math_SimpleMultiplyBy(const mcElement &p);
01440  virtual void math_SimpleDivideBy(const mcElement &p);
01441 
01445  void math_SimpleRaiseTo(const mcPolynomial &);
01446 
01450  bool math_isValidMath() const;
01451 
01458  virtual bool math_isListedBeforeOf(const mcElement &p) const;
01459 
01461 
01462 
01463 
01464 
01468 
01472  virtual mcMathType math_GetMathType() const = 0;
01473   
01509  virtual mcRealValue math_GetLenght() const = 0;
01510  
01523  virtual mcExpSimRes math_Simplify(long flags, mcElement *newelem) = 0;
01524 
01533  virtual mcExpSimRes math_Expand(long flags, mcElement *newelem) = 0;
01534 
01541  virtual bool math_Compare(const mcElement &p, long flags) const = 0;
01542 
01545  virtual bool math_CompareThisOnly(const mcElement &p, long flags) const;
01546 
01551  virtual mcRealValue math_Evaluate() const = 0;
01552 
01554  virtual int math_GetOrderPos() const = 0;
01555 
01561  virtual mcMonomial math_GetFactors() const;
01562 
01564 
01565 
01569 
01574  virtual bool math_CanBeAddedWith(const mcElement &p) const = 0;
01575 
01577  virtual bool math_CanBeMultWith(const mcElement &p) const = 0;
01578 
01580  virtual bool math_CanBeDivBy(const mcElement &p) const = 0;
01581 
01595  virtual mcBasicOpRes math_Add(const mcElement &e, mcElement *pp, bool add = TRUE) = 0;
01596 
01599  mcBasicOpRes math_Subtract(const mcElement &e, mcElement *pp)
01600   { return math_Add(e, pp, FALSE); }
01601 
01606  virtual mcBasicOpRes math_MultiplyBy(const mcElement &e, mcElement *pp) = 0;
01607 
01612  virtual mcBasicOpRes math_DivideBy(const mcElement &e, mcElement *pp) = 0;
01613 
01615  virtual mcMonomial math_GetLCM(const mcElement &) const = 0;
01616  virtual mcMonomial math_GetGCD(const mcElement &) const = 0;
01617 
01619 
01620 
01621 
01625 
01638  virtual mcBasicOpRes math_RaiseTo(const mcPolynomial &) = 0;
01639 
01649  virtual mcBasicOpRes math_MakeReciprocal(mcElement *replacement);
01650 
01655  virtual void math_SetExp(const mcPolynomial &); 
01656 
01658 
01659 
01660 #endif  // mcENABLE_MATH
01661 
01662 
01663 
01664 
01665 
01666 
01667 
01668 #ifdef mcENABLE_IO
01669 protected:
01670 
01672  virtual void io_Init() {}
01673 
01679  virtual void io_PostProcess() {}
01680 
01684  virtual void io_PostProcessChildren();
01685 
01686 public:
01687 
01692  virtual bool io_Init(const wxString &str);
01693 
01697 
01708  virtual bool io_isBeginTag(const wxXml2Node &tag) const = 0;
01709 
01714  virtual bool io_isBeginChar(const wxString &str) const = 0;
01715 
01722  virtual wxXml2Node io_GetMathML(bool bGetPresentation) const = 0;
01723 
01733  virtual wxString io_GetInlinedExpr() const = 0;
01734 
01735 
01744  virtual bool io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr) = 0;
01745 
01766  virtual bool io_ImportInlinedExpr(const wxString &str, int *count, wxString &pErr) = 0; 
01767 
01769 
01770 #endif  // mcENABLE_IO
01771 };
01772 
01773 
01774 
01792 class mcElement : public mcObject
01793 {
01794 protected:
01795 
01801  //void SetExpDepth(int n);
01802  
01803 public:
01804    
01808 
01810  mcObjectRefData *data_MakePrivateCopy();
01811 
01815  void data_Ref(const mcObject &toclone);
01816 
01820  mcElementHelpers *phlp()    { return (mcElementHelpers *)data_MakePrivateCopy(); }
01821 
01826  const mcElementHelpers *chlp() const { return (mcElementHelpers *)data_GetRefData(); }
01827 
01831     bool data_isOk() const     { return (mdata_refData != NULL); }
01832 
01834 
01835 
01836 
01837 public:
01838 
01845  mcElement() {}
01846 
01848  mcElement(const mcElementHelpers *helpers);
01849 
01851  virtual ~mcElement();
01852 
01853 
01854  // as for all mcElement-derived classes, we define through
01855  // macros the following functions:
01856  // - hlp() const      which uses chlp()
01857  // - hlp() non-const  which uses phlp()
01858  // - operator==
01859  // - operator!=
01860  mcDEFINE_HLP_GETTER(mcElement)
01861  mcDEFINE_COMPARISON_OPERATORS(mcElement) 
01862 
01863 
01864  
01865 #ifdef mcENABLE_DATA
01866 public:
01867 
01873  virtual mcElement data_Clone() const
01874   { return mcElement(chlp()); }
01875  
01882  virtual void data_DeepCopy(const mcElement &p) 
01883   { hlp()->data_DeepCopy(p.hlp()); }
01884 
01889  virtual mcElement data_GetNewElemLikeThis() const 
01890   { return mcElementHelpers::data_NewElem(data_GetType()); }
01891 
01905  virtual bool data_isValidContainerFor(mcElementType t) const
01906   { return TRUE; }
01907 
01908 #ifdef __MCDEBUG__
01909 
01913  void data_CheckContainer() const;
01914 
01918  void data_Check() const;
01919 
01924  virtual wxString data_GetDebugName() const
01925   { return wxT("mcElement"); }
01926 
01927  // the wrapper for the data_GetDebug function (which 
01928  // is implemented by the helpers section)
01929  mcWRAPPER wxString data_GetDebug(int n, long f) const
01930   { return hlp()->data_GetDebug(n, f); } 
01931 
01932 #else
01933 
01934  // these functions should be removed by the linker
01935  inline void data_Check() const    {}
01936  inline void data_CheckContainer() const  {}
01937  inline wxString data_GetDebug(int, long) const 
01938   { return wxEmptyString; }
01939  inline wxString data_GetDebugName(int, long) const 
01940   { return wxEmptyString; }
01941 
01942 #endif  // __MCDEBUG__
01943 
01944 
01945  mcWRAPPER void data_AddProperty(int p, void *val1 = NULL, void *val2 = NULL) 
01946   { hlp()->data_AddProperty(p, val1, val2); }
01947  mcWRAPPER void data_RemoveProperty(int p) 
01948   { hlp()->data_RemoveProperty(p); }
01949  mcWRAPPER bool data_hasProperty(int p) const
01950   { return hlp()->data_hasProperty(p); }
01951 
01952  mcWRAPPER void data_AddRecursiveProperty(mcElementType t, int p, 
01953   void *val1 = NULL, void *val2 = NULL)
01954   { hlp()->data_AddRecursiveProperty(t, p, val1, val2); }
01955  mcWRAPPER void data_RemoveRecursiveProperty(mcElementType t, int p)
01956   { hlp()->data_RemoveRecursiveProperty(t, p); }
01957  mcWRAPPER bool data_hasRecursiveProperty(mcElementType t, int p) const
01958   { return hlp()->data_hasRecursiveProperty(t, p); } 
01959 
01960  mcWRAPPER int data_GetChildrenCount() const 
01961   { return hlp()->data_GetChildrenCount(); }
01962  mcWRAPPER const mcElement &data_GetConstChild(int n) const 
01963   { return hlp()->data_GetConstChild(n); }
01964  mcWRAPPER mcElement &data_GetChild(int n)
01965   { return hlp()->data_GetChild(n); }
01966  mcWRAPPER void data_SetChild(int idx, const mcElement &newchild)
01967   { hlp()->data_SetChild(idx, newchild); }
01968  mcWRAPPER int data_GetChildIdx(const mcElement &p) const
01969   { return hlp()->data_GetChildIdx(p); }
01970   mcWRAPPER bool data_AddChildrenTo(mcElement p)
01971   { return hlp()->data_AddChildrenTo(p); }
01972 
01973  mcWRAPPER bool data_isSameAs(const mcElement &p) const
01974   { return hlp()->data_isSameAs(p.hlp()); }
01975  mcWRAPPER void gui_UpdateExpDepth() 
01976   { hlp()->gui_UpdateExpDepth(); }
01977 
01978  mcWRAPPER mcElementType data_GetType() const
01979   { return hlp()->data_GetType(); }
01980  mcWRAPPER int data_GetID() const
01981   { return hlp()->data_GetID(); }
01982  mcWRAPPER int data_GetMemoryInfo() const
01983   { return hlp()->data_GetMemoryInfo(); }
01984 
01985  mcWRAPPER mcElement &data_GetElemFromID(int id) const
01986   { return hlp()->data_GetElemFromID(id); }
01987 
01988  mcWRAPPER void data_Update()
01989   { hlp()->data_Update(); }
01990  mcWRAPPER bool data_isAllowedBefore(mcElementType type) const 
01991    { return hlp()->data_isAllowedBefore(type); }
01992  mcWRAPPER bool data_isAllowedAfter(mcElementType type) const
01993    { return hlp()->data_isAllowedAfter(type); } 
01994 
01995 #endif  // mcENABLE_DATA
01996 
01997 
01998 
01999 
02000 #ifdef mcENABLE_GUI
02001 
02002  mcWRAPPER void gui_SetAsExpOf(const mcElement &p)
02003   { hlp()->gui_SetAsExpOf(p); }
02004  mcWRAPPER void gui_SetAtSameLevelOf(const mcElement &p)
02005   { hlp()->gui_SetAtSameLevelOf(p); }
02006  mcWRAPPER void gui_SetExpDepth(int n)
02007   { hlp()->gui_SetExpDepth(n); }
02008 
02009  mcWRAPPER bool gui_isBeginKey(const mcKey &ev) const
02010   { return hlp()->gui_isBeginKey(ev); } 
02011  mcWRAPPER bool gui_isEndKey(const mcKey &ev) const
02012   { return hlp()->gui_isEndKey(ev); } 
02013     mcWRAPPER int gui_Draw(wxDC &dc, int x, int y, long flags, const wxPoint &pt) const
02014   { return hlp()->gui_Draw(dc, x, y, flags, pt); } 
02015  mcWRAPPER int gui_GetRelCursorPos(wxDC &dc, wxPoint *pt) const
02016   { return hlp()->gui_GetRelCursorPos(dc, pt); } 
02017  mcWRAPPER void gui_GetCursorPos(mcCursorPos &cp) const
02018   { hlp()->gui_GetCursorPos(cp); }
02019  mcWRAPPER mcCursorPos gui_GetCursorPos() const
02020   { return hlp()->gui_GetCursorPos(); }
02021  mcWRAPPER mcElement gui_GetSelection() const
02022   { return hlp()->gui_GetSelection(); }
02023  mcWRAPPER bool gui_isAllSelected() const
02024   { return hlp()->gui_isAllSelected(); }
02025  mcWRAPPER bool gui_isSplittable() const
02026   { return hlp()->gui_isSplittable(); }
02027  mcWRAPPER bool gui_isSelected() const
02028   { return hlp()->gui_isSelected(); }
02029 
02030 
02031  mcWRAPPER void gui_SetStyleArray(const mcStyleArray *p)
02032   { hlp()->gui_SetStyleArray(p); }
02033  mcWRAPPER void gui_OnRecalcSize(wxSize old)
02034   { hlp()->gui_OnRecalcSize(old); }
02035  mcWRAPPER void gui_DoRecalcSize()
02036   { hlp()->gui_DoRecalcSize(); }
02037  mcWRAPPER mcInputRes gui_Input(const mcKey &ev, mcElement *newelem)
02038   { return hlp()->gui_Input(ev, newelem); }
02039  mcWRAPPER mcInsertRes gui_Insert(const mcElement &toinsert, mcElement *newelem)
02040   { return hlp()->gui_Insert(toinsert, newelem); }
02041  mcWRAPPER int gui_MoveCursorUsingPoint(wxDC &dc, const wxPoint &p)
02042   { return hlp()->gui_MoveCursorUsingPoint(dc, p); } 
02043  mcWRAPPER mcMoveCursorRes gui_MoveCursor(mcMoveCursorFlag flag, long modifiers)
02044   { return hlp()->gui_MoveCursor(flag, modifiers); } 
02045  mcWRAPPER void gui_SetCursorPos(const mcCursorPos &code)
02046   { hlp()->gui_SetCursorPos(code); } 
02047 
02048 
02049  mcWRAPPER void gui_DeleteSelection()
02050   { hlp()->gui_DeleteSelection(); }
02051 
02052  mcWRAPPER mcElement &gui_GetActiveElem(int x, int y, const wxPoint &pt) const
02053   { return hlp()->gui_GetActiveElem(x, y, pt); }
02054 
02055  mcWRAPPER void gui_DeepRecalcSize()
02056   { hlp()->gui_DeepRecalcSize(); }
02057 
02058  mcWRAPPER void gui_SelectAll()
02059   { hlp()->gui_SelectAll(); }
02060  mcWRAPPER void gui_DeSelect()
02061   { hlp()->gui_DeSelect(); }
02062  mcWRAPPER void gui_Select()
02063   { hlp()->gui_Select(); }
02064  mcWRAPPER void gui_OnSelect(wxDC &dc, wxRect &rc)
02065   { hlp()->gui_OnSelect(dc, rc); }
02066 
02067  mcWRAPPER bool gui_Split(mcElement *p)  
02068   { return hlp()->gui_Split(p); }
02069  mcWRAPPER bool gui_MergeWith(const mcElement &p)
02070   { return hlp()->gui_MergeWith(p); }
02071 
02072  mcWRAPPER bool gui_LetInCursor(mcCursorPos code)
02073   { return hlp()->gui_LetInCursor(code); }
02074 
02075  mcWRAPPER void gui_RecalcSize()
02076   { hlp()->gui_RecalcSize(); }
02077  mcWRAPPER wxSize gui_GetSize() const  
02078   { return hlp()->gui_GetSize(); }
02079  mcWRAPPER int gui_GetWidth() const  
02080   { return hlp()->gui_GetWidth(); }
02081  mcWRAPPER int gui_GetHeight() const  
02082   { return hlp()->gui_GetHeight(); }
02083 
02084  /*wxSize gui_GetSize()
02085  mcWRAPPER int gui_GetWidth()
02086  mcWRAPPER int gui_GetHeight()*/
02087  mcWRAPPER int gui_GetExpDepth() const
02088   { return hlp()->gui_GetExpDepth(); }
02089 
02090  mcWRAPPER int gui_GetYAnchor() const
02091   { return hlp()->gui_GetYAnchor(); }
02092 
02093  mcWRAPPER const mcStyle *gui_GetStyle(int n) const
02094   { return hlp()->gui_GetStyle(n); }
02095 
02096  mcWRAPPER wxSize gui_GetSizeOfChar(wxDC *dc = NULL, 
02097    const mcElement &p = mcEmptyElement) const
02098   { return hlp()->gui_GetSizeOfChar(dc, p); }
02099 
02100  mcWRAPPER int gui_GetHeightOfChar(wxDC *dc, const mcElement &p) const 
02101   { return hlp()->gui_GetHeightOfChar(dc, p); }
02102  mcWRAPPER int gui_GetWidthOfChar(wxDC *dc, const mcElement &p) const    
02103   { return hlp()->gui_GetWidthOfChar(dc, p); }
02104 
02105  mcWRAPPER const mcStyle *gui_GetStyleForThis() const
02106   { return hlp()->gui_GetStyleForThis(); }
02107 
02108  mcWRAPPER void gui_SelectStyle(wxDC &dc) const
02109   { hlp()->gui_SelectStyle(dc); }
02110  mcWRAPPER int gui_GetThickness(wxDC *dc) const
02111   { return hlp()->gui_GetThickness(dc); }
02112  mcWRAPPER int gui_GetBaseOffsety(int h) const
02113   { return hlp()->gui_GetBaseOffsety(h); }
02114  mcWRAPPER int gui_GetSubscriptOffsety(int h) const
02115   { return hlp()->gui_GetSubscriptOffsety(h); }
02116 
02117 #endif  // mcENABLE_GUI
02118 
02119 
02120 
02121 
02122 #ifdef mcENABLE_MATH
02123 public:
02124 
02125  mcWRAPPER mcElement math_Find(int n, const mcElement &p, long flags = mcFIND_NOFLAGS) const
02126   { return hlp()->math_Find(n, p, flags); }
02127  mcWRAPPER mcElement math_FindInChildrenOnly(int n, const mcElement &p, long flags = mcFIND_NOFLAGS) const
02128   { return hlp()->math_FindInChildrenOnly(n, p, flags); }
02129  mcWRAPPER int math_NonRecursiveFindInChildren(int n, const mcElement &p, long flags = mcFIND_NOFLAGS) const
02130   { return hlp()->math_NonRecursiveFindInChildren(n, p, flags); }
02131  mcWRAPPER int math_GetCountOf(const mcElement &p, long flags = mcFIND_NOFLAGS) const
02132   { return hlp()->math_GetCountOf(p, flags); }
02133  mcWRAPPER int math_GetCountOfChildrenOnly(const mcElement &p, long flags = mcFIND_NOFLAGS) const
02134   { return hlp()->math_GetCountOfChildrenOnly(p, flags); }
02135  mcWRAPPER int math_Replace(const mcElement &tofind, int n, long flags,
02136       const mcElement &replacement, bool bAttachChildren)
02137   { return hlp()->math_Replace(tofind, n, flags, replacement, bAttachChildren); }
02138 
02139  mcWRAPPER int math_GetCountOf(const mcSymbolProperties *sym, long flags = mcFIND_NOFLAGS) const
02140   { return hlp()->math_GetCountOf(sym, flags); }
02141  mcWRAPPER int math_GetCountOf(const mcSymbolArray *arr, long flags = mcFIND_NOFLAGS) const
02142   { return hlp()->math_GetCountOf(arr, flags); }
02143  mcWRAPPER int math_GetCountOfSymbolsType(const mcSymbolArray *arr, long flags = mcFIND_NOFLAGS) const
02144   { return hlp()->math_GetCountOfSymbolsType(arr, flags); }
02145 
02146 
02147  mcWRAPPER bool math_Contains(const mcElement &p, long flags = mcFIND_NOFLAGS) const  
02148   { return hlp()->math_Contains(p, flags); }
02149  mcWRAPPER bool math_ContainsOneOf(const mcSymbolArray *arr) const
02150   { return hlp()->math_ContainsOneOf(arr); }
02151 
02152  mcWRAPPER bool math_ContainsSymbol(const mcSymbolProperties *p, 
02153        const mcPolynomial &exp = mcEmptyPolynomial) const
02154   { return hlp()->math_ContainsSymbol(p, exp); }
02155  mcWRAPPER bool math_ContainsNumber(const mcRealValue &n, 
02156        const mcPolynomial &exp = mcEmptyPolynomial) const
02157   { return hlp()->math_ContainsNumber(n, exp); }
02158 
02159  mcWRAPPER bool math_ContainsUnknowns() const
02160   { return hlp()->math_ContainsUnknowns(); }
02161  mcWRAPPER bool math_ContainsConstants() const
02162   { return hlp()->math_ContainsConstants(); }
02163  mcWRAPPER bool math_ContainsParameters() const
02164   { return hlp()->math_ContainsParameters(); }
02165  mcWRAPPER bool math_ContainsSymbols() const
02166   { return hlp()->math_ContainsSymbols(); }
02167  mcWRAPPER bool math_ContainsInvalidSymbols() const
02168   { return hlp()->math_ContainsInvalidSymbols(); }
02169 
02170  mcWRAPPER mcExpSimRes math_MaxSimplify(long flags)
02171   { return hlp()->math_MaxSimplify(flags); }
02172 
02173  mcWRAPPER bool math_isMaxSimplified(long flags) const
02174   { return hlp()->math_isMaxSimplified(flags); }
02175 
02176  mcWRAPPER int math_GetSymbolList(mcSymbol **arr, int size, const mcSymbol &tofind) const
02177   { return hlp()->math_GetSymbolList(arr, size, tofind); }
02178  mcWRAPPER int math_GetSymbolList(mcSymbol **arr, int size, mcSymbolProperties &tofind) const
02179   { return hlp()->math_GetSymbolList(arr, size, tofind); }
02180 
02181  mcWRAPPER bool math_isConstant() const
02182   { return hlp()->math_isConstant(); }
02183 
02184  mcWRAPPER bool math_EvaluatesTo(const mcRealValue &val) const  
02185   { return hlp()->math_EvaluatesTo(val); }
02186 
02187  mcWRAPPER bool math_isFinite() const
02188   { return hlp()->math_isFinite(); }
02189 
02190  mcWRAPPER mcBasicOpRes math_RaiseTo(const mcPolynomial &p)
02191   { return hlp()->math_RaiseTo(p); }
02192  mcWRAPPER mcBasicOpRes math_MakeReciprocal(mcElement *p)
02193   { return hlp()->math_MakeReciprocal(p); }
02194  mcWRAPPER void math_SetExp(const mcPolynomial &p)
02195   { hlp()->math_SetExp(p); }
02196 
02197 
02198  mcWRAPPER mcRealValue math_GetTotalLenght() const
02199   { return hlp()->math_GetTotalLenght(); }
02200 
02201  mcWRAPPER void math_SimpleAdd(const mcElement &p, bool add = TRUE)
02202   { hlp()->math_SimpleAdd(p, add); }
02203  mcWRAPPER void math_SimpleSubtract(const mcElement &p)  
02204   { hlp()->math_SimpleSubtract(p); }
02205  mcWRAPPER void math_SimpleMultiplyBy(const mcElement &p)
02206   { hlp()->math_SimpleMultiplyBy(p); }
02207  mcWRAPPER void math_SimpleDivideBy(const mcElement &p)
02208   { hlp()->math_SimpleDivideBy(p); }
02209  mcWRAPPER void math_SimpleRaiseTo(const mcPolynomial &pol)
02210   { hlp()->math_SimpleRaiseTo(pol); }
02211 
02212  mcWRAPPER bool math_isValidMath() const
02213   { return hlp()->math_isValidMath(); }
02214 
02215  mcWRAPPER bool math_isListedBeforeOf(const mcElement &p) const
02216   { return hlp()->math_isListedBeforeOf(p); }
02217 
02218  mcWRAPPER mcMathType math_GetMathType() const
02219   { return hlp()->math_GetMathType(); }
02220  mcWRAPPER mcRealValue math_GetLenght() const
02221   { return hlp()->math_GetLenght(); }
02222 
02223  mcWRAPPER mcExpSimRes math_Simplify(long flags, mcElement *newelem)
02224   { return hlp()->math_Simplify(flags, newelem); }
02225  mcWRAPPER mcExpSimRes math_Expand(long flags, mcElement *newelem)
02226   { return hlp()->math_Expand(flags, newelem); }
02227 
02228  mcWRAPPER bool math_Compare(const mcElement &p, long flags) const
02229   { return hlp()->math_Compare(p, flags); }
02230  mcWRAPPER bool math_CompareThisOnly(const mcElement &p, long flags) const
02231   { return hlp()->math_CompareThisOnly(p, flags); }
02232 
02233  mcWRAPPER mcRealValue math_Evaluate() const
02234   { return hlp()->math_Evaluate(); }
02235  mcWRAPPER mcRealValue math_EvaluateAt(const mcSymbolProperties *sym, 
02236            const mcRealValue &symvalue) const
02237   { return hlp()->math_EvaluateAt(sym, symvalue); }
02238 
02239  mcWRAPPER int math_GetOrderPos() const
02240   { return hlp()->math_GetOrderPos(); }
02241 
02242 // mcPolynomial math_GetFactors() const
02243 //  { return hlp()->math_GetFactors(); }
02244 
02245  mcWRAPPER bool math_CanBeAddedWith(const mcElement &p) const
02246   { return hlp()->math_CanBeAddedWith(p); }
02247  mcWRAPPER bool math_CanBeMultWith(const mcElement &p) const
02248   { return hlp()->math_CanBeMultWith(p); }
02249  mcWRAPPER bool math_CanBeDivBy(const mcElement &p) const
02250   { return hlp()->math_CanBeDivBy(p); }
02251 
02252  mcWRAPPER mcBasicOpRes math_Add(const mcElement &e, mcElement *pp, bool add = TRUE)
02253   { return hlp()->math_Add(e, pp, add); }
02254  mcWRAPPER mcBasicOpRes math_Subtract(const mcElement &e, mcElement *pp) 
02255   { return hlp()->math_Subtract(e, pp); }
02256  mcWRAPPER mcBasicOpRes math_MultiplyBy(const mcElement &e, mcElement *pp)
02257   { return hlp()->math_MultiplyBy(e, pp); }
02258  mcWRAPPER mcBasicOpRes math_DivideBy(const mcElement &e, mcElement *pp)
02259   { return hlp()->math_DivideBy(e, pp); }
02260 
02261  // the implementation of these two must be in the source file
02262  // and thus they cannot be inlined...
02263  mcMonomial math_GetLCM(const mcElement &p) const;
02264  mcMonomial math_GetGCD(const mcElement &p) const;
02265  mcMonomial math_GetFactors() const;
02266 
02267  mcElement operator*(const mcElement &m) const
02268  { mcElement ret(*this); ret.math_SimpleMultiplyBy(m); return ret; }
02269  mcElement operator/(const mcElement &m) const
02270  { mcElement ret(*this); ret.math_SimpleDivideBy(m); return ret; }
02271  mcElement operator-(const mcElement &m) const
02272  { mcElement ret(*this); ret.math_SimpleSubtract(m); return ret; }
02273  mcElement operator+(const mcElement &m) const
02274  { mcElement ret(*this); ret.math_SimpleAdd(m); return ret; }
02275 
02276  mcElement operator^(const mcPolynomial &m) const
02277  { mcElement ret(*this); ret.math_RaiseTo(m); return ret; }
02278 
02279  // this operator cannot be inlined...
02280  mcElement operator^(const mcRealValue &m) const;
02281 
02282 
02283  // these operators return references
02284 
02285  mcElement &operator^=(const mcPolynomial &m)
02286  { *this = (*this)^m;return *this; }
02287  mcElement &operator^=(const mcRealValue &m)
02288  { *this = (*this)^m;return *this; }
02289 
02290  mcElement &operator+=(const mcElement &m)  { *this = *this+m;return *this; }
02291  mcElement &operator-=(const mcElement &m)  { *this = *this-m;return *this; }
02292  mcElement &operator*=(const mcElement &m)  { *this = *this*m;return *this; }
02293  mcElement &operator/=(const mcElement &m)  { *this = *this/m;return *this; }
02294 
02295 #endif  // mcENABLE_MATH
02296 
02297 
02298 #ifdef mcENABLE_IO
02299 public:
02300 
02301  mcWRAPPER bool io_isBeginTag(const wxXml2Node &tag) const
02302   { return hlp()->io_isBeginTag(tag); }
02303  mcWRAPPER bool io_isBeginChar(const wxString &str) const
02304   { return hlp()->io_isBeginChar(str); }
02305 
02306  mcWRAPPER wxXml2Node io_GetMathML(bool bGetPresentation) const
02307   { return hlp()->io_GetMathML(bGetPresentation); }
02308 
02309  mcWRAPPER wxString io_GetInlinedExpr() const
02310   { return hlp()->io_GetInlinedExpr(); }
02311 
02312  mcWRAPPER bool io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr)
02313   { return hlp()->io_ImportPresentationMathML(tag, pErr); }
02314  mcWRAPPER bool io_ImportInlinedExpr(const wxString &str, int *count, wxString &pErr) 
02315   { return hlp()->io_ImportInlinedExpr(str, count, pErr); }
02316 
02317 #endif  // mcENABLE_IO
02318 };
02319 
02320 
02321 #endif // ELEMENT_H
02322 


Documentation generated with Doxygen on Sun Feb 6 17:10:45 2005
Visit MathStudio home page for more info

[ Top ]