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

MathMng.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 MATHMNG_H
00034 #define MATHMNG_H
00035 
00036 // optimization for GCC compiler
00037 #ifdef __GNUG__
00038 #pragma interface "MathMng.h"
00039 #endif
00040 
00041 // required includes
00042 #include "mc/Polynomial.h"
00043 
00044 
00051 class mcMathMngHelpers : public mcElementHelpers
00052 {
00053  mcDEFINE_REFERENCE_DATA(mcMathMng, mcET_MATHMNG);
00054 
00055 #ifdef mcENABLE_DATA
00056 protected:  // internal variables
00057 
00059  mcPolynomial mdata_eLMember;
00060  
00062  mcPolynomial mdata_eRMember;
00063 
00065  mcMathMngType mdata_nDataType;
00066 
00067 #endif
00068 
00069 
00070 #ifdef mcENABLE_GUI
00071 protected:
00072  
00077  int mgui_nCursorPos;
00078  
00079 #define mcMATHMNG_LEFT  0  
00080 #define mcMATHMNG_RIGHT  1  
00081 
00082 
00083  wxSize mgui_szSeparator;
00084 
00085 public:    // customizable variables
00086  
00089  static int sgui_nSpaceAroundSeparator;
00090  
00093  static int sgui_nSpaceLeftRight;
00094 
00100  
00101  static mcStyleArray *sgui_pNormalStyles;  
00102  static mcStyleArray *sgui_pSmallStyles;   
00103  static mcStyleArray *sgui_pBigStyles;   
00104 
00106 
00107  static mcMathMngCmd sgui_cmd[mcMMC_LAST];
00108 
00109 #endif
00110 
00111  
00112 public:
00113  
00115  mcMathMngHelpers() { data_Init(); }
00116  virtual ~mcMathMngHelpers() {}
00117  
00118 
00119 protected:
00120 
00121  void data_Init() {
00122   mdata_nDataType = mcMMT_EXPRESSION;
00123   mcElementHelpers::data_Init();
00124  }
00125 
00126  void gui_Init() {  
00127   mgui_nCursorPos = mcMATHMNG_LEFT;
00128   
00129   // the style array *must* always be valid !
00130   mgui_pStyleArray = sgui_pNormalStyles;  
00131   mcElementHelpers::gui_Init();
00132  }
00133 
00134  
00135 
00136 #ifdef mcENABLE_DATA
00137 protected:   // internal functions
00138 
00139  void data_GetConstSourceDest(const mcPolynomialHelpers **s, 
00140     const mcPolynomialHelpers **d, bool toleft) const;
00141 
00142  void data_GetSourceDest(mcPolynomialHelpers **s, mcPolynomialHelpers **d, bool toleft)
00143   { data_GetConstSourceDest((const mcPolynomialHelpers **)s, 
00144    (const mcPolynomialHelpers **)d, toleft); }
00145 
00146 public:
00147 
00148 #ifdef __MCDEBUG__
00149 
00151  void data_Check() const;
00152  
00154  virtual wxString data_Debug(long flags) const;
00155 
00156 #endif
00157 
00158  int data_GetChildrenCount() const {
00159   // we _always_ have both a left & a right member
00160   return mcElementHelpers::data_GetChildrenCount()+2;
00161  }
00162 
00163  const mcElement &data_GetConstChild(int n) const {
00164   mcRETURN_ELEMENT_CHILD(n, mcElementHelpers);
00165   if (n == 0)
00166    return data_GetLeftMem();
00167   if (n == 1)
00168    return data_GetRightMem();
00169   return mcEmptyElement;
00170  } 
00171 
00174  void data_DeepCopy(const mcElementHelpers *mm); 
00175 
00178  virtual void data_SetFilter(const mcFilter *p);
00179 
00184  virtual void data_SetMember(bool left, const mcPolynomial &, 
00185         mcMathMngType newtype = mcMMT_EQUATION);
00186 
00187  const mcPolynomial &data_GetLeftMem() const    { return mdata_eLMember; }
00188  const mcPolynomial &data_GetRightMem() const   { return mdata_eRMember; }
00189  mcPolynomial &data_GetLeftMem()       { return mdata_eLMember; }
00190  mcPolynomial &data_GetRightMem()      { return mdata_eRMember; }
00191 
00192 #endif  // mcENABLE_DATA
00193 
00194 
00195 
00196 #ifdef mcENABLE_GUI
00197 protected:
00198 
00204  void gui_GetConstSelectionSourceDest(const mcPolynomialHelpers **s, const mcPolynomialHelpers **d) const;
00205  void gui_GetSelectionSourceDest(mcPolynomialHelpers **s, mcPolynomialHelpers **d)
00206   { gui_GetConstSelectionSourceDest((const mcPolynomialHelpers **)s, (const mcPolynomialHelpers **)d); }
00207 
00212  static bool gui_isRelationalOp(const mcKey &key);
00213 
00214 
00215 public:
00216 
00220 
00229  static void gui_InitStyles();
00230 
00236  static void gui_DeleteStyles();
00237  
00241  wxSize gui_GetSeparatorSize() const
00242   { return mgui_szSeparator; }
00243 
00247  void gui_RecalcSeparatorSize();
00248 
00249  int gui_GetXOfSeparator(int centerLine = -1) const;
00250  int gui_GetYOfSeparator(int centerLine = -1) const;
00251 
00252  int gui_GetXOfLeftMem() const;
00253  int gui_GetYOfLeftMem() const;
00254 
00255  int gui_GetXOfRightMem() const;
00256  int gui_GetYOfRightMem() const;
00257 
00258  void gui_SelectSeparatorStyle(wxDC &) const;
00259  int gui_GetYAnchor() const; 
00260 
00261  wxRect gui_GetRectOfLeftMem() const;
00262  wxRect gui_GetRectOfRightMem() const;
00263 
00264  mcPolynomial &gui_GetFocusMem()
00265   { return (mgui_nCursorPos == mcMATHMNG_LEFT) ? mdata_eLMember : mdata_eRMember; }
00266 
00267  const mcPolynomial &gui_GetFocusMem() const
00268   { return (mgui_nCursorPos == mcMATHMNG_LEFT) ? mdata_eLMember : mdata_eRMember; }
00269 
00271 
00272 
00273 
00274 
00278  
00279  // these does not apply to a mcMathSystem
00280  bool gui_isBeginKey(const mcKey &key) const 
00281   { return FALSE; }
00282  bool gui_isEndKey(const mcKey &key) const
00283   { return FALSE; }
00284  
00289  virtual int gui_Draw(wxDC &h, int x, int y, long flags, const wxPoint &p) const;
00290  
00293  virtual mcInputRes gui_Input(const mcKey &key, mcElement *);
00294  
00295  mcInsertRes gui_Insert(const mcElement &, mcElement *);
00296 
00297  virtual mcMoveCursorRes gui_MoveCursor(mcMoveCursorFlag flag, long modifiers);
00298  virtual int gui_GetRelCursorPos(wxDC &dc, wxPoint *pt) const;
00299  virtual void gui_SetCursorPos(const mcCursorPos &code);
00300  virtual void gui_GetCursorPos(mcCursorPos &) const;
00301  virtual int gui_MoveCursorUsingPoint(wxDC &, const wxPoint &);
00302  virtual void gui_OnSelect(wxDC &dc, wxRect &rc);
00303  virtual void gui_DoRecalcSize();
00304 
00312  virtual mcElement &gui_GetActiveElem(int x, int y, const wxPoint &pt);
00313 
00317  virtual mcElement gui_GetSelection() const;
00318 
00320  virtual void gui_DeleteSelection();
00321 
00324  virtual void gui_UpdateExpDepth();
00325 
00327 
00328 
00329 
00333 
00334  virtual void gui_MultiplyBySel(bool bDivide = FALSE);
00335  virtual void gui_MoveSel();
00336  virtual void gui_AddSubSel();
00337 
00338  virtual void gui_ExecCmdOnSel(mcMathMngCmdID);
00339  virtual void gui_GetPossibleOperations(mcMathMngCmdID *) const;
00340 
00341  virtual wxArrayString gui_GetPossibleOpOnSel(mcMathMngCmd *) const;
00342 
00344  
00345 #endif  // mcENABLE_GUI
00346 
00347 
00348 
00349 #ifdef mcENABLE_MATH
00350 protected:
00351 
00354  static mcMathMngRelationalOp math_GetRelationalOpFor(mcMathMngType type);
00355 
00358  static mcMathMngType math_GetMathTypeFor(mcMathMngRelationalOp type);
00359 
00365  static mcMathMngType math_GetMathTypeFrom(const mcKey &);
00366 
00367 public:
00368 
00372 
00373  // functions working with mcPolynomials
00374  mcBasicOpRes math_Add(const mcElement &, mcElement *, bool add);
00375  mcBasicOpRes math_MultiplyBy(const mcElement &, mcElement *);
00376  mcBasicOpRes math_DivideBy(const mcElement &e, mcElement *pp);
00377  mcBasicOpRes math_Subtract(const mcElement &, mcElement *);
00378 
00379  bool math_Compare(const mcElement &p, long flags) const;
00380 
00381  // functions working with mcMonomials
00382  void math_MultiplyBy(const mcMonomial &);
00383  void math_DivideBy(const mcMonomial &);
00384  void math_MultiplyBy(int nID);
00385 
00389  void math_MoveSymbols(const mcSymbolArray *arr, bool toLeft);
00390  void math_MoveSymbol(const mcSymbolProperties *sym, bool toLeft);
00391  void math_MoveFreeFrom(const mcSymbolProperties *sym, bool toLeft);
00392  void math_MoveUnknowns(bool toLeft);
00393  void math_MoveConstants(bool toLeft);
00394  void math_MoveParameters(bool toLeft);
00395  void math_MoveNonSymbol(bool toLeft);
00396  void math_MoveAll(bool toleft);
00397  void math_Move(int mathidx, bool toleft);
00398  
00399  mcBasicOpRes math_RaiseTo(const mcPolynomial &p);
00400  
00401  void math_RaiseTo(const mcRealValue &);
00402  void math_RaiseTo(int nID);
00403  void math_RaiseToSel();
00404 
00405  mcExpSimRes math_Simplify(long flags, mcElement *)
00406   { return math_Simplify(flags, flags); }
00407  mcExpSimRes math_Expand(long flags, mcElement *)
00408   { return math_Expand(flags, flags); }
00409 
00410  mcExpSimRes math_Simplify(long lflags, long rflags);
00411  mcExpSimRes math_Expand(long lflags, long rflags);
00412 
00413  bool math_isMaxSimplified() const;
00414  bool math_isConstant() const;
00415  bool math_isFactorized() const;
00416 
00417  mcRealValue math_Evaluate() const; 
00418  mcRealValue math_GetLenght() const;
00419  mcRealValue math_GetTotalLenght() const;
00420  
00421 
00422  mcIntegerValue math_GetMaxDegreeFor(const mcSymbolProperties *sym) const;
00423 
00425  int math_Replace(const mcElement &tofind, int occ, long flags, 
00426      const mcElement &replacement, bool addchildren);
00427 
00428  int math_GetCountOf(const mcElement &tocount, long flags) const;
00429 
00430  bool math_CompareThisOnly(const mcElement &, long flags) const;
00431 
00435  mcElement math_Find(int n, const mcElement &tofind, long flags, int *pos = NULL) const;
00436  
00438  /*mcElement math_Find(int n, const mcElement &tofind, long flags, int *pos = NULL)
00439   { return (mcElementHelpers *)math_Find(n, tofind, bStrict, pos); }*/
00440 
00441  //bool math_Contains(const mcElement &p, long flags = mcFIND_NOFLAGS) const;
00442  bool math_ContainsSymbol(const mcSymbolProperties *sym) const;
00443  bool math_ContainsNumber(const mcRealValue &sym) const;
00444 
00445  bool math_ContainsInvalidSymbols() const;
00446  int math_GetSymbolList(mcSymbol **, int size, 
00447   const mcSymbol &tofind, bool left = TRUE) const;
00448 
00449  void math_FactoreOutAll(bool bForceUseless);
00450  void math_FactoreOut(const mcSymbolProperties *, const mcPolynomial &pol, bool bForceUseless);
00451  void math_FactoreOutFreeOf(const mcSymbolProperties *, const mcPolynomial &pol, bool bForceUseless);
00452 
00455  mcMathMngType math_GetMathMngType() const
00456   { return mdata_nDataType; }
00457 
00462  void math_SetMathType(mcMathMngType newtype)
00463   { mdata_nDataType = newtype; }
00464 
00467  mcMathType math_GetMathType() const;
00468 
00469 
00470  // these does not have sense for a mcMathSystem
00471  int math_GetOrderPos() const   { return 0; }
00472 
00473  bool math_CanBeAddedWith(const mcElement &p) const { return FALSE; }
00474  bool math_CanBeMultWith(const mcElement &p) const { return FALSE; }
00475  bool math_CanBeDivBy(const mcElement &p) const  { return FALSE; }
00476 
00477  mcMonomial math_GetLCM(const mcElement &) const  { return mcEmptyMonomial; }
00478  mcMonomial math_GetGCD(const mcElement &) const  { return mcEmptyMonomial; }
00479 
00481 
00482 #endif  // mcENABLE_MATH
00483 
00484 
00485  
00486 #ifdef mcENABLE_IO
00487 public:
00488 
00492  
00494  virtual wxXml2Node io_GetMathML(bool bGetPresentation) const;
00495 
00497  virtual wxString io_GetInlinedExpr() const;
00498  
00500  virtual bool io_ImportPresentationMathML(wxXml2Node tag, wxString &err);
00501 
00503  virtual bool io_ImportInlinedExpr(const wxString &str, int *count, wxString &perr);
00504 
00506  wxString io_GetSeparatorSymbol(bool bUseSpecialChars = TRUE) const;
00507 
00508 
00509  // these does not have sense for a mcMathSystem
00510  bool io_isBeginTag(const wxXml2Node &tag) const  { return FALSE; }
00511  bool io_isBeginChar(const wxString &str) const   { return FALSE; }
00512 
00514 
00515 #endif  // mcENABLE_IO
00516 };
00517 
00518 
00519 
00524 class mcMathMng : public mcElement
00525 {
00526  mcDEFINE_MAIN_CLASS(MathMng, mcElement);
00527 
00528 protected:
00529 
00530  void data_Init(const mcPolynomial &left, const mcPolynomial &right)
00531  { data_GetLeftMem()=left; data_GetRightMem()=right; 
00532   math_SetMathType(mcMMT_EQUATION); }
00533 
00534 public:
00535 
00536  mcMathMng(const mcPolynomial &left, const mcPolynomial &right)
00537  { data_SetRefData(new mcMathMngHelpers()); data_Init(left, right); }
00538 
00539 
00540  bool data_isValidContainerFor(mcElementType t) const
00541   { return t == mcET_MATHMNG; }
00542 
00543  mcWRAPPER const mcPolynomial &data_GetLeftMem() const
00544   { return hlp()->data_GetLeftMem(); }
00545  mcWRAPPER const mcPolynomial &data_GetRightMem() const
00546   { return hlp()->data_GetRightMem(); }
00547  mcWRAPPER mcPolynomial &data_GetLeftMem()
00548   { return hlp()->data_GetLeftMem(); }
00549  mcWRAPPER mcPolynomial &data_GetRightMem()
00550   { return hlp()->data_GetRightMem(); }
00551  mcWRAPPER void data_SetFilter(const mcFilter *p)
00552   { hlp()->data_SetFilter(p); }
00553 
00554 
00555 
00556  mcWRAPPER void gui_MoveSel()
00557   { hlp()->gui_MoveSel(); }
00558  mcWRAPPER wxArrayString gui_GetPossibleOpOnSel(mcMathMngCmd *p) const
00559   { return hlp()->gui_GetPossibleOpOnSel(p); }
00560  mcWRAPPER void gui_GetPossibleOperations(mcMathMngCmdID *p) const
00561   { hlp()->gui_GetPossibleOperations(p); }
00562  mcWRAPPER void gui_MultiplyBySel()
00563   { hlp()->gui_MultiplyBySel(); }
00564  mcWRAPPER void gui_ExecCmdOnSel(mcMathMngCmdID n)
00565   { hlp()->gui_ExecCmdOnSel(n); }
00566 
00567  
00568  mcWRAPPER const mcPolynomial &gui_GetFocusMem() const
00569   { return hlp()->gui_GetFocusMem(); }
00570  mcWRAPPER mcPolynomial &gui_GetFocusMem()
00571   { return hlp()->gui_GetFocusMem(); }
00572 
00573 
00574  mcWRAPPER mcMathMngType math_GetMathMngType() const
00575   { return hlp()->math_GetMathMngType(); }
00576  mcWRAPPER mcExpSimRes math_Simplify(long flags, long rflags)
00577   { return hlp()->math_Simplify(flags, rflags); }
00578  mcWRAPPER mcExpSimRes math_Expand(long flags, long rflags)
00579   { return hlp()->math_Expand(flags, rflags); }
00580 
00581  mcWRAPPER void math_MoveConstants(bool toleft)
00582   { hlp()->math_MoveConstants(toleft); }
00583  mcWRAPPER void math_MoveParameters(bool toleft)
00584   { hlp()->math_MoveParameters(toleft); }
00585  mcWRAPPER void math_MoveUnknowns(bool toleft)
00586   { hlp()->math_MoveUnknowns(toleft); }
00587  mcWRAPPER void math_MoveNonSymbol(bool toleft)
00588   { hlp()->math_MoveNonSymbol(toleft); }
00589  mcWRAPPER void math_MoveSymbol(const mcSymbolProperties *sym, bool toleft)
00590   { hlp()->math_MoveSymbol(sym, toleft); }
00591  mcWRAPPER void math_MoveFreeFrom(const mcSymbolProperties *sym, bool toleft)
00592   { hlp()->math_MoveFreeFrom(sym, toleft); }
00593  mcWRAPPER void math_MoveAll(bool toleft)
00594   { hlp()->math_MoveAll(toleft); }
00595 
00596  mcWRAPPER void math_FactoreOutAll(bool bForceUseless)
00597   { hlp()->math_FactoreOutAll(bForceUseless); }
00598  mcWRAPPER void math_FactoreOut(const mcSymbolProperties *sym, const mcPolynomial &pol, bool bForceUseless)
00599   { hlp()->math_FactoreOut(sym, pol, bForceUseless); }
00600  mcWRAPPER void math_FactoreOutFreeOf(const mcSymbolProperties *sym, const mcPolynomial &pol, bool bForceUseless)
00601   { hlp()->math_FactoreOutFreeOf(sym, pol, bForceUseless); }
00602 
00603  mcWRAPPER mcIntegerValue math_GetMaxDegreeFor(const mcSymbolProperties *p) const
00604   { return hlp()->math_GetMaxDegreeFor(p); }
00605  mcWRAPPER mcElement math_Find(int n, const mcElement &tofind, 
00606        long flags, int *pos = NULL) const
00607   { return hlp()->math_Find(n, tofind, flags, pos); }
00608  mcWRAPPER void math_SetMathType(mcMathMngType t)
00609   { hlp()->math_SetMathType(t); }
00610 
00611  mcWRAPPER bool math_isFactorized() const
00612   { return hlp()->math_isFactorized(); }
00613 };
00614 
00615 #endif // MATHMNG_H
00616 


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

[ Top ]