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

MathSystem.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 //                                                                   //
00030 
00031 
00032 
00033 #ifndef MATHSYSTEM_H
00034 #define MATHSYSTEM_H
00035 
00036 // optimization for GCC compiler
00037 #ifdef __GNUG__
00038 #pragma interface "MathSystem.h"
00039 #endif
00040 
00041 // required includes
00042 #include "mc/MathLine.h"
00043 
00044 
00046 #define mcMATHSYSTEM_MAXLINES    32
00047 
00048 // global objects
00049 class mcMathSystem;
00050 extern mcMathSystem mcEmptySystem;
00051 
00052 
00056 class mcMathSystemHelpers : public mcAbstractArray, public mcElementHelpers,
00057        public mcDoubleBufferedElement
00058 {
00059 #ifdef mcENABLE_GUI
00060 protected:  // member variables
00061 
00064  int mgui_nSel;
00065 
00069  int mgui_nLastActive;
00070 
00073  int mgui_nCurrentActive;
00074 
00076  wxSize mgui_szSymbol;
00077 
00078 
00080  wxFont mgui_fLastFont;
00081 
00083  int mgui_nLastWidth;
00084 
00085 #endif
00086 
00087 
00088 public:
00089  mcMathSystemHelpers() {}
00090  virtual ~mcMathSystemHelpers() {}
00091 
00092  void gui_Init() {
00093   mgui_nSel = mgui_nLastWidth = 0;
00094   mgui_nLastActive = -1;
00095   mgui_nCurrentActive = -1;
00096   mcElementHelpers::gui_Init();
00097  }
00098 
00099 
00100 
00101 #ifdef mcENABLE_DATA
00102 public:
00103 
00104 #ifdef __MCDEBUG__
00105 
00107  void data_Check() const;
00108 
00109 #else
00110  
00111  inline void data_Check() const {}
00112 
00113 #endif  // __MCDEBUG__
00114 
00117  void data_DeepCopy(const mcElementHelpers *p);
00118 
00119  int data_GetChildrenCount() const
00120   { return mcAbstractArray::data_GetCount(); }
00121  const mcElement &data_GetConstChild(int n) const
00122   { return *((const mcElement *)(data_GetItem(n))); } 
00123 
00124  // these functions are used to link the children functions
00125  // defined above with the mcAbstractArray functions/terminology.
00126  mcElement &data_Get(int n)
00127   { return data_GetChild(n); }
00128  const mcElement &data_Get(int n) const
00129   { return data_GetConstChild(n); } 
00130  mcElement &data_GetLast()
00131   { return data_Get(data_GetCount()-1); }
00132  const mcElement &data_GetLast() const
00133   { return data_Get(data_GetCount()-1); }
00134  int data_GetCount() const
00135   { return data_GetChildrenCount(); }
00136 
00137 #endif  // mcENABLE_DATA
00138 
00139 
00140 
00141 #ifdef mcENABLE_GUI
00142 protected:
00143 
00146  virtual bool gui_DrawHorizontally() const = 0;
00147  virtual bool gui_DrawVertically() const = 0;
00148 
00149  virtual int gui_GetSpaceAboveBelow() const = 0;
00150  virtual int gui_GetSpaceLeftRight() const = 0;
00151  virtual int gui_GetSpaceBetween() const = 0; 
00152 
00153 public: 
00154 
00160 
00161  mcElement &gui_GetFocus()
00162   { return data_Get(mgui_nSel); }
00163  const mcElement &gui_GetFocus() const
00164   { return data_Get(mgui_nSel); }
00165 
00166  mcDoubleBufferedElement *gui_Get(int n)
00167   { return dynamic_cast<mcDoubleBufferedElement*>(data_Get(n).hlp()); }
00168  const mcDoubleBufferedElement *gui_Get(int n) const
00169   { return dynamic_cast<const mcDoubleBufferedElement*>(data_Get(n).chlp()); }
00170 
00172 
00173 
00174 
00179  
00180  int gui_UpdateBmp(int x, int y, long flags, const wxPoint &p);
00181  int gui_ForceBmpUpdate(int x, int y, long flags, const wxPoint &p);
00182  int gui_DrawBmp(wxDC &dc, int x, int y) const;
00183 
00184  void gui_SetMask(const wxColour &col);
00185  void gui_SetBmpBackgroundBrush(const wxBrush &);
00186 
00187  bool gui_NeedsRefresh() const;
00188  
00190 
00191 
00192 
00196 
00199  virtual void gui_DrawSystemSymbols(wxDC &dc, int x, int y, long flags) const = 0;
00200 
00204  virtual void gui_RecalcSymbolSize() = 0;
00205 
00207 
00208 
00209 
00213 
00217  virtual int gui_GetXOf(int n) const;
00218 
00222  virtual int gui_GetYOf(int n) const;
00223 
00225  virtual int gui_GetXOfSymbol(int n) const;
00226 
00228  virtual int gui_GetYOfSymbol(int n) const;
00229 
00231  wxRect gui_GetRectOf(int n) const;
00232 
00235  int gui_GetElemContaining(const wxPoint &pt) const;
00236 
00238  virtual wxSize gui_GetSymbolSize() const
00239   { return mgui_szSymbol; }
00240 
00246  wxPoint gui_GetRelCursorPos(wxDC &dc, int x, int y, int *height) const;
00247 
00250  void gui_CheckSelLineIdx();
00251 
00255  wxBitmap gui_GetBmp() const;
00256 
00258  int gui_GetFocusIdx() const 
00259   { return mgui_nSel; }
00260 
00263  void gui_SetFocusIdx(int n)
00264   { mgui_nSel = n; }
00265 
00269  bool gui_isSymbolToDraw() const 
00270  { return data_GetCount() >= 2; }
00271 
00273 
00274 
00275 
00276 
00280  
00281  // these does not apply to a mcMathSystem
00282  bool gui_isBeginKey(const mcKey &key) const 
00283   { return FALSE; }
00284  bool gui_isEndKey(const mcKey &key) const
00285   { return FALSE; }
00286 
00287  void gui_DoRecalcSize();
00288  void gui_SetCursorPos(const mcCursorPos &code);
00289  void gui_OnSelect(wxDC &dc, wxRect &rc);
00290  int gui_GetRelCursorPos(wxDC &dc, wxPoint *pt) const;
00291  int gui_MoveCursorUsingPoint(wxDC &dc, const wxPoint &pos);
00292  int gui_Draw(wxDC &dc, int x, int y, long flags, const wxPoint &pt) const; 
00293  void gui_GetCursorPos(mcCursorPos &) const;
00294  mcInputRes gui_Input(const mcKey &ev, mcElement *newelem);
00295  mcInsertRes gui_Insert(const mcElement &, mcElement *);
00296  mcMoveCursorRes gui_MoveCursor(mcMoveCursorFlag flag, long modifiers);
00297  
00298 /*
00299  mcElement &gui_GetActiveElem(int x, int y, const wxPoint &pt);
00300  mcElement data_GetElemFromID(int id);
00301 */
00302 
00304  //void gui_DeleteSelection();
00305 
00307  void gui_UpdateExpDepth();
00308 
00310 
00311 
00312 
00316 
00317  /*void gui_MultiplyBySel() {
00318   gui_GetSelLine()->gui_MultiplyBySel();
00319  }
00320 
00321  void gui_MoveSel() {
00322   gui_GetSelLine()->gui_MoveSel();
00323  }
00324 
00325  wxArrayString gui_GetPossibleOpOnSel(mcMathMngCmd *pID) {
00326   return gui_GetSelLine()->gui_GetPossibleOpOnSel(pID);
00327  }
00328 
00329  wxArrayString math_GetPossibleOp(mcMathMngCmd *pID, int n = 0) {
00330   return data_GetLine(n)->gui_GetPossibleOp(pID);
00331  }
00332 
00333  void gui_ExecCmdOnSel(mcMathMngCmd n) {
00334   gui_GetSelLine()->gui_ExecCmdOnSel(n);
00335  }*/
00336 
00338  wxString gui_GetSelInlinedExpr() const;
00339 
00341 
00342 #endif  // mcENABLE_GUI
00343 
00344 
00345 
00346 #ifdef mcENABLE_MATH
00347 protected:
00348   
00351  mcExpSimRes math_ExpSimAllLines(bool simp = TRUE);
00352 
00353 public:
00354 
00358 
00361  mcBasicOpRes math_MultiplyBy(const mcElement &, mcElement *);
00362 
00365  mcBasicOpRes math_DivideBy(const mcElement &, mcElement *);
00366  mcBasicOpRes math_Add(const mcElement &, mcElement *, bool);
00367  mcBasicOpRes math_Subtract(const mcElement &, mcElement *);
00368 
00369  mcBasicOpRes math_RaiseTo(const mcPolynomial &);
00370 
00371  mcExpSimRes math_Simplify(long flags, mcElement *);
00372  mcExpSimRes math_Expand(long flags, mcElement *);
00373 
00376  mcRealValue math_Evaluate(int n = -1) const;
00377 
00378  bool math_isMaxSimplified() const;
00379  //bool math_isConstant() const;
00380 
00381 /* mcElement math_Find(int n, const mcElement &tofind, long flags,
00382        int *pos = NULL, int *entry = NULL) const;
00383  int math_GetCountOf(const mcElement &tocount, long flags) const;
00384  int math_Replace(const mcElement &tofind, int n, long flags,
00385   const mcElement &rep, bool bAttachChildren);*/
00386 
00387  mcIntegerValue math_GetMathSystemDegreeFor(const mcSymbolProperties *unk) const;
00388  
00389  mcRealValue math_GetLenght() const;
00390  //mcRealValue math_GetTotalLenght() const;
00391 
00392  //bool math_isComplete() const;
00393 
00395  virtual mcMathSystemType math_GetMathSystemType() const = 0;
00396 
00399  mcMathType math_GetMathType() const;
00400 
00401  bool math_Compare(const mcElement &, long flags) const; 
00402 
00403 
00404  // these does not have sense for a mcMathSystem
00405  mcRealValue math_Evaluate() const  { return 0.0; }
00406  int math_GetOrderPos() const   { return 0; }
00407 
00408  bool math_CanBeAddedWith(const mcElement &p) const { return FALSE; }
00409  bool math_CanBeMultWith(const mcElement &p) const { return FALSE; }
00410  bool math_CanBeDivBy(const mcElement &p) const  { return FALSE; }
00411 
00412  mcMonomial math_GetLCM(const mcElement &) const  { return mcEmptyMonomial; }
00413  mcMonomial math_GetGCD(const mcElement &) const  { return mcEmptyMonomial; }
00414 
00416 
00417 #endif  // mcENABLE_MATH
00418 
00419 
00420 
00421 #ifdef mcENABLE_IO
00422 protected:
00423 
00426  int io_FilterInlinedExpr(wxString &);
00427 
00428 public:
00429 
00433 
00437  bool io_ImportInlinedExpr(const wxString &str, int *count, wxString &perr);
00438 
00442  bool io_ImportInlinedExpr(const wxString &str)
00443  { wxString tmp; return io_ImportInlinedExpr(str, NULL, tmp); }
00444 
00446  wxString io_GetInlinedExpr() const;
00447 
00449  wxXml2Node io_GetMathML(bool bGetPresentation) const;
00450 
00452  bool io_ImportPresentationMathML(wxXml2Node pDoc, wxString &pErr);
00453 
00454  virtual wxString io_GetInlinedExprOfLogicalOperator() const = 0;
00455  virtual bool io_ImportToken(const wxString &str, wxString *perr) = 0;
00456 
00457 
00458  // USELESS ??
00459  
00461  wxString io_GetInlinedExprOfLogicalOperator(mcLogicOperator op, 
00462          bool shortversion = FALSE) const;
00463 
00465  wxString io_GetInlinedExprOfAllLogicalOp() const;
00466 
00467 
00468  // these does not have sense for a mcMathSystem
00469  bool io_isBeginTag(const wxXml2Node &tag) const  { return FALSE; }
00470  bool io_isBeginChar(const wxString &str) const   { return FALSE; }
00471 
00473 
00474 #endif  // mcENABLE_IO
00475 };
00476 
00477 
00481 class mcMathSystem : public mcElement
00482 {
00483  mcDEFINE_ABSTRACT_CLASS(MathSystem, mcElement);
00484 
00485 public:
00486 
00487  bool data_isValidContainerFor(mcElementType t) const
00488   { return t == mcET_MATHORSYSTEM || t == mcET_MATHANDSYSTEM; }
00489 
00490 
00491 #ifdef mcENABLE_DATA
00492 public:
00493 
00494  mcWRAPPER mcElement &data_Get(int n)
00495   { return hlp()->data_Get(n); }
00496  mcWRAPPER const mcElement &data_Get(int n) const
00497   { return hlp()->data_Get(n); }
00498  mcWRAPPER mcElement &data_GetLast()
00499   { return hlp()->data_GetLast(); }
00500  mcWRAPPER const mcElement &data_GetLast() const
00501   { return hlp()->data_GetLast(); }
00502  
00503  mcWRAPPER int data_GetCount() const
00504   { return hlp()->data_GetCount(); } 
00505  mcWRAPPER void data_Insert(mcAbstractItem *pointer, int n)
00506   { hlp()->data_Insert(pointer, n); }
00507  mcWRAPPER void data_SetItem(mcAbstractItem *pointer, int n)
00508   { hlp()->data_SetItem(pointer, n); }
00509  mcWRAPPER void data_RemoveAt(int idx, int count = 1)
00510   { hlp()->data_RemoveAt(idx, count); }
00511  mcWRAPPER void data_Remove(const mcAbstractItem *p)
00512   { hlp()->data_Remove(p); }
00513  mcWRAPPER void data_Clear()
00514   { hlp()->data_Clear(); }
00515  mcWRAPPER bool data_isEmpty() const 
00516   { return hlp()->data_isEmpty(); } 
00517  mcWRAPPER int data_Find(const mcAbstractItem *pointer) const
00518   { return hlp()->data_Find(pointer); } 
00519  mcWRAPPER mcAbstractItem *data_Detach(int idx)
00520   { return hlp()->data_Detach(idx); } 
00521 
00522 #endif  // mcENABLE_DATA
00523 
00524 
00525 #ifdef mcENABLE_GUI
00526 public:
00527 
00528  mcWRAPPER int gui_UpdateBmp(int x, int y, long flags, const wxPoint &p)
00529   { return hlp()->gui_UpdateBmp(x, y, flags, p); } 
00530  mcWRAPPER int gui_ForceBmpUpdate(int x, int y, long flags, const wxPoint &p)
00531   { return hlp()->gui_ForceBmpUpdate(x, y, flags, p); } 
00532  mcWRAPPER int gui_DrawBmp(wxDC &dc, int x, int y) const
00533   { return hlp()->gui_DrawBmp(dc, x, y); }
00534 
00535  mcWRAPPER bool gui_NeedsRefresh() const
00536   { return hlp()->gui_NeedsRefresh(); }
00537  mcWRAPPER void gui_SetMask(const wxColour &c)
00538   { hlp()->gui_SetMask(c); }
00539  mcWRAPPER void gui_SetBmpBackgroundBrush(const wxBrush &c)
00540   { hlp()->gui_SetBmpBackgroundBrush(c); }
00541 
00542  mcWRAPPER void gui_SetFocusIdx(int n)
00543   { hlp()->gui_SetFocusIdx(n); }
00544  mcWRAPPER int gui_GetFocusIdx() const
00545   { return hlp()->gui_GetFocusIdx(); }
00546 
00547  mcWRAPPER wxPoint gui_GetRelCursorPos(wxDC &dc, int x, int y, int *height) const
00548   { return hlp()->gui_GetRelCursorPos(dc, x, y, height); }
00549  
00550  mcWRAPPER wxBitmap gui_GetBmp() const
00551   { return hlp()->gui_GetBmp(); }
00552  
00553  mcWRAPPER wxString gui_GetSelInlinedExpr() const
00554   { return hlp()->gui_GetSelInlinedExpr(); }
00555 
00556 #endif  // mcENABLE_GUI
00557 
00558 
00559 #ifdef mcENABLE_IO
00560 public:
00561 
00562  mcWRAPPER bool io_ImportInlinedExpr(const wxString &str)
00563   { return hlp()->io_ImportInlinedExpr(str); }
00564  mcWRAPPER bool io_ImportInlinedExpr(const wxString &str, int *count, wxString &err)
00565   { return hlp()->io_ImportInlinedExpr(str, count, err); }
00566 
00567 #endif  // mcENABLE_IO
00568 
00569 
00570 #ifdef mcENABLE_MATH
00571 public:
00572 
00573  mcWRAPPER mcMathSystemType math_GetMathSystemType() const
00574   { return hlp()->math_GetMathSystemType(); }
00575 
00576 #endif  // mcENABLE_MATH
00577 };
00578 
00579 
00580 #endif  // MATHSYSTEM_H
00581 


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

[ Top ]