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 mcEXPCONTAINER_H 00035 #define mcEXPCONTAINER_H 00036 00037 // optimization for GCC compiler 00038 #ifdef __GNUG__ 00039 #pragma interface "ExpContainer.h" 00040 #endif 00041 00042 // required includes 00043 #include "mc/ExpElement.h" 00044 00045 00046 00047 mcDEFINE_HELPER_CLASSES(mcExpContainer) 00048 00049 00050 00051 00052 00053 00054 class mcExpContainerHelpers : public mcExpElementHelpers 00055 { 00056 #ifdef mcENABLE_DATA 00057 protected: // DATA variables 00058 00060 mcPolynomial m_eContent; 00061 00062 #endif 00063 00064 00065 #ifdef mcENABLE_GUI 00066 protected: 00067 00069 int mgui_nCursorPos; 00070 00072 #define mcEXPCONTAINER_LEFTMOST 1 00073 00075 #define mcEXPCONTAINER_INSIDEEXPR 2 00076 00078 #define mcEXPCONTAINER_RIGHTMOST 3 00079 00080 #endif 00081 00082 00083 00084 00085 00086 public: 00087 00088 mcExpContainerHelpers() { 00089 mdata_bExpEnabled = TRUE; 00090 mdata_bSubEnabled = FALSE; // do not allow subscripts 00091 } 00092 00093 virtual ~mcExpContainerHelpers() {} 00094 00095 00096 protected: 00097 00098 void gui_Init() { 00099 mcExpElementHelpers::gui_Init(); 00100 00101 // cursor begins inside the ExpContainer 00102 mgui_nCursorPos = mcEXPCONTAINER_INSIDEEXPR; 00103 } 00104 00105 00106 00107 #ifdef mcENABLE_DATA 00108 public: 00109 00110 int data_GetChildrenCount() const { 00111 return mcExpElementHelpers::data_GetChildrenCount() + 00112 (data_GetContent() != mcEmptyPolynomial); 00113 } 00114 00115 const mcElement &data_GetConstChild(int n) const { 00116 mcRETURN_ELEMENT_CHILD(n, mcExpElementHelpers); 00117 if (n == 0 && data_GetContent() != mcEmptyElement) 00118 return data_GetContent(); 00119 return mcEmptyElement; 00120 } 00121 00122 void data_SetChild(int n, const mcElement &newchild) { 00123 mcSET_ELEMENT_CHILD(n, mcExpElementHelpers, newchild); 00124 if (n == 0) { 00125 mcASSERT(newchild.data_GetType() == mcET_POLYNOMIAL, wxT("Invalid new child")); 00126 data_SetContent(newchild); 00127 } 00128 } 00129 00130 00131 void data_DeepCopy(const mcElementHelpers *p) { 00132 const mcExpContainerHelpers *b = (const mcExpContainerHelpers *)p; 00133 00134 // deep copy the contents 00135 data_GetContent().data_DeepCopy(b->data_GetContent()); 00136 mcExpElementHelpers::data_DeepCopy(p); 00137 } 00138 00139 bool data_isSameAs(const mcElementHelpers *p) const { 00140 if (!mcElementHelpers::data_isSameAs(p)) 00141 return FALSE; 00142 00143 const mcExpContainerHelpers *ed = (const mcExpContainerHelpers *)p; 00144 if (m_eContent != ed->m_eContent) return FALSE; 00145 return TRUE; 00146 } 00147 00148 wxString data_GetDebugName() const 00149 { return wxT("mcExpContainer"); } 00150 00151 00154 virtual void data_SetContent(const mcPolynomial &p) { 00155 data_GetContent().data_DeleteAll(); 00156 data_GetContent().data_AddElements( 00157 p.hlp()->data_GetArray(), p.hlp()->data_GetCount(), -1, TRUE); 00158 } 00159 00161 mcPolynomial &data_GetContent() { return m_eContent; } 00162 const mcPolynomial &data_GetContent() const { return m_eContent; } 00163 00164 /* mcPolynomialHelpers *data_GetContentHlp() { return m_eContent.hlp(); } 00165 const mcPolynomialHelpers *data_GetContentHlp() const { return m_eContent.hlp(); } 00166 */ 00167 00169 virtual void data_AddElements(mcElement *p, int num, int pos = -1, bool bOverwrite = FALSE) { 00170 00171 // just call the math_AddElements function of the content 00172 data_GetContent().data_AddElements(p, num, pos, bOverwrite); 00173 } 00174 00176 virtual mcElement data_AddNewElement(mcElementType t, bool bOverwrite = FALSE, 00177 int pos = -1) { 00178 00179 // just call the math_AddNewElement function of the content 00180 return data_GetContent().data_AddNewElement(t, bOverwrite, pos); 00181 } 00182 00183 #endif // mcENABLE_DATA 00184 00185 00186 00187 00188 #ifdef mcENABLE_GUI 00189 public: 00190 00192 virtual int gui_GetSpaceAboveBelow() const { return 0; } 00193 00194 // space between begin symbol and content, and between the 00195 // content and the end symbol 00196 virtual int gui_GetSpaceLeftRight() const { return 0; } 00197 00201 virtual mcInputRes gui_HandleContentInput(mcInputRes, mcElement *); 00202 00203 00204 00209 00210 virtual int gui_GetContentOffsetX() const = 0; 00211 virtual int gui_GetContentOffsetY() const = 0; 00212 00213 virtual bool gui_isLeftPosEnabled() const = 0; 00214 virtual bool gui_isRightPosEnabled() const = 0; 00215 00216 virtual void gui_DrawContainer(wxDC &dc, int x, int y, long flags, const wxPoint &p) const = 0; 00217 00219 00220 00221 00227 00229 void gui_UpdateExpDepth() { 00230 00231 // update content 00232 data_GetContent().gui_SetAtSameLevelOf(this); 00233 00234 // and the exponent/subscript... 00235 mcExpElementHelpers::gui_UpdateExpDepth(); 00236 } 00237 00240 virtual bool gui_DrawAsActiveOverBase() const { 00241 return FALSE; 00242 } 00243 00245 virtual mcElement gui_GetBaseSelection() const { 00246 return data_GetContent().gui_GetSelection(); 00247 } 00248 00249 virtual bool gui_isBaseEndKey(const mcKey &ev) const; 00250 virtual int gui_BaseMoveCursorUsingPoint(wxDC &, const wxPoint &); 00251 virtual int gui_GetBaseRelCursorPos(wxDC &, wxPoint *) const; 00252 virtual mcMoveCursorRes gui_BaseMoveCursor(mcMoveCursorFlag flag, long modifiers); 00253 virtual mcInputRes gui_BaseInput(const mcKey &ke, mcElement *pnew); 00254 virtual mcInsertRes gui_BaseInsert(const mcElement &, mcElement *); 00255 virtual void gui_GetBaseCursorPos(mcCursorPos &) const; 00256 virtual int gui_DrawBase(wxDC &cd, int x, int y, long flags, const wxPoint &p) const; 00257 virtual int gui_GetYAnchor() const; 00258 00259 virtual void gui_OnBaseSelect(wxDC &dc, wxRect &rc); 00260 virtual void gui_SetBaseCursorPos(const mcCursorPos &); 00261 virtual void gui_EditBase(); 00262 00264 00265 #endif // mcENABLE_GUI 00266 00267 00268 00269 00270 #ifdef mcENABLE_MATH 00271 public: 00272 00277 00278 //bool hasSameContentOf(const mcElement &p) const; 00279 bool math_CompareThisOnly(const mcElement &p, long flags) const; 00280 00281 bool math_CanBeDivBy(const mcElement &) const; 00282 bool math_CanBeMultWith(const mcElement &) const; 00283 bool math_CanBeAddedWith(const mcElement &) const; 00284 00285 mcBasicOpRes math_Add(const mcElement &, mcElement *p, bool add); 00286 //mcBasicOpRes math_Subtract(const mcElement &, mcElement *p); 00287 mcBasicOpRes math_DivideBaseOnlyBy(const mcElement &, mcElement *p); 00288 mcBasicOpRes math_MultiplyBaseOnlyBy(const mcElement &, mcElement *p); 00289 00290 mcRealValue math_GetBaseLenght() const { return 0; } 00291 00292 mcRealValue math_EvaluateBase() const 00293 { return data_GetContent().math_Evaluate(); } 00294 mcMathType math_GetBaseMathType() const 00295 { return data_GetContent().math_GetMathType(); } 00296 00297 mcExpSimRes math_SimplifyBase(long flags, mcElement *newelem); 00298 mcExpSimRes math_ExpandBase(long flags, mcElement *newelem); 00299 mcExpSimRes math_SimplifyBaseExp(long flags, mcElement *pnew); 00300 00302 00303 00304 virtual mcExpSimRes math_SimplifyContents(long flags, mcElement *newelem) = 0; 00305 virtual mcExpSimRes math_ExpandContents(long flags, mcElement *newelem) = 0; 00306 virtual mcPolynomial math_GetRaisedContents() const; 00307 virtual mcMonomial math_GetFactors() const; 00308 00309 /*mcMonomial math_GetLCM(const mcElement &p) const 00310 { return data_GetContent().math_GetLCM(p); } 00311 mcMonomial math_GetGCD(const mcElement &p) const 00312 { return data_GetContent().math_GetGCD(p); }*/ 00313 00314 #endif // mcENABLE_MATH 00315 00316 00317 00318 00319 00320 #ifdef mcENABLE_IO 00321 protected: 00322 00324 virtual wxString io_GetMathMLPresentationTag() const { return wxEmptyString; } 00325 00326 public: 00327 bool io_isBeginTag(const wxXml2Node &tag) const { 00328 if (tag.GetName() == io_GetMathMLPresentationTag()) 00329 return TRUE; 00330 return FALSE; 00331 } 00332 00333 // MATH ML IO functions 00334 wxXml2Node io_GetBaseMathML(bool bGetPresentation) const; 00335 bool io_ImportPresentationMathML(wxXml2Node tag, wxString &pErr); 00336 00337 #endif // mcENABLE_IO 00338 }; 00339 00340 00350 class mcExpContainer : public mcExpElement 00351 { 00352 mcDEFINE_ABSTRACT_CLASS(ExpContainer, mcExpElement); 00353 00354 public: 00355 00356 bool data_isValidContainerFor(mcElementType t) const 00357 { return t == mcET_BRACKET || t == mcET_RADICAL; } 00358 00359 mcWRAPPER void data_SetContent(const mcPolynomial &p) 00360 { hlp()->data_SetContent(p); } 00361 mcWRAPPER void data_AddElements(mcElement *p, int num, int pos = -1, bool bOverwrite = FALSE) 00362 { hlp()->data_AddElements(p, num, pos, bOverwrite); } 00363 mcWRAPPER mcElement data_AddNewElement(mcElementType t, bool bOverwrite = FALSE, int pos = -1) 00364 { return hlp()->data_AddNewElement(t, bOverwrite, pos); } 00365 00366 mcWRAPPER mcPolynomial &data_GetContent() { return hlp()->data_GetContent(); } 00367 mcWRAPPER const mcPolynomial &data_GetConstContent() const { return hlp()->data_GetContent(); } 00368 }; 00369 00370 00371 #endif // mcEXPCONTAINER_H 00372
[ Top ] |