Salome HOME
OCC functionality moving out from the widget
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Curve.hxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:        CurveCreator_Curve.hxx
21 // Author:      Sergey KHROMOV
22
23 #ifndef _CurveCreator_Curve_HeaderFile
24 #define _CurveCreator_Curve_HeaderFile
25
26 #include "CurveCreator_ICurve.hxx"
27
28 #include "CurveCreator_Macro.hxx"
29 #include "CurveCreator.hxx"
30 #include "CurveCreator_Diff.hxx"
31 #include "CurveCreator_AISCurve.hxx"
32
33 #include <AIS_Point.hxx>
34 #include <AIS_Line.hxx>
35 #include <AIS_InteractiveObject.hxx>
36
37 #include <list>
38 #include <map>
39
40 struct CurveCreator_Section;
41 class CurveCreator_Displayer;
42
43 /**
44  *  The CurveCreator_Curve object is represented as one or more sets of
45  *  connected points; thus CurveCreator_Curve object can contain several
46  *  not connected curves (polylines or b-splines), each such curve has two
47  *  only ends � start and end points � in other words non-manifold curves
48  *  are not supported.
49  */
50 class CURVECREATOR_EXPORT CurveCreator_Curve : public CurveCreator_ICurve
51 {
52 protected:
53   typedef std::list<CurveCreator_Diff> ListDiff;
54
55 public:
56   //! Constructor of the curve.
57   /** The dimension is explicitly specified in the constructor
58    *  and cannot be changed later.
59    */
60   CurveCreator_Curve(const CurveCreator::Dimension theDimension);
61
62   //! Destructor.
63   virtual ~CurveCreator_Curve();
64
65   //! Get the dimension.
66   virtual CurveCreator::Dimension getDimension() const;
67
68   //! Return unique section name
69   virtual std::string getUniqSectionName() const;
70
71   //! Set curve creator Displayer object
72   virtual void setDisplayer( CurveCreator_Displayer* theDisplayer );
73
74   //! Return curve creator Displayer object
75   CurveCreator_Displayer* getDisplayer();
76
77   //! Remove curve creator Displayer object
78   virtual void removeDisplayer();
79
80   /** Set depth of undo operations (unlimited if \a theDepth is -1
81    *  or disabled if \a theDepth is 0)
82    */
83   virtual void setUndoDepth(const int theDepth = -1);
84
85   //! Get depth of undo operations.
86   virtual int getUndoDepth() const;
87
88   virtual void startOperation();
89   virtual void finishOperation();
90
91   /**
92    * This method converts the point index to the index in
93    * an array of coordinates.
94    */
95   virtual int toICoord(const int theIPnt) const;
96
97   ListAISObjects constructSection( int theISection ) const;
98
99   //! For internal use only! Undo/Redo are not used here.
100   virtual bool moveSectionInternal(const int theISection,
101                            const int theNewIndex);
102   //! Move section to new position in list
103   virtual bool moveSection(const int theISection,
104                    const int theNewIndex);
105
106 protected:
107   /** This method updates all undo/redo information required to be updated
108    *  after curve modification operation. It returns false if undo/redo
109    *  is disabled and true otherwise.
110    */
111   virtual bool addEmptyDiff();
112
113   Handle_AIS_Point getAISPoint( int theISection, int theIPoint ) const;
114   Handle_AIS_Line  getAISLine( int theISection, int theIPoint1, int theIPoint2 ) const;
115 public: // temporary
116   void getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const;
117 protected:  // temporary
118   void redisplayCurve();
119
120   void convert( const SectionToPointList &thePoints,
121                 std::map<int, std::list<int> > &theConvPoints );
122
123 public:
124   /************   Implementation of INTERFACE methods   ************/
125
126   /***********************************************/
127   /***          Undo/Redo methods              ***/
128   /***********************************************/
129
130   //! Get number of available undo operations
131   virtual int getNbUndo() const;
132
133   //! Undo previous operation
134   virtual bool undo();
135
136   //! Get number of available redo operations
137   virtual int getNbRedo() const;
138
139   //! Redo last previously "undone" operation
140   virtual bool redo();
141
142
143   /***********************************************/
144   /***           Section methods               ***/
145   /***********************************************/
146
147   //! For internal use only! Undo/Redo are not used here.
148   virtual bool clearInternal();
149   //! Clear the polyline (remove all sections)
150   virtual bool clear();
151
152   //! For internal use only! Undo/Redo are not used here.
153   virtual bool joinInternal( const int theISectionTo = -1, 
154                              const int theISectionFrom = -1 );
155   //! Join range of sections to one section (join all sections if -1 is passed in one of arguments)
156   virtual bool join( const int theISectionTo = -1, 
157                      const int theISectionFrom = -1 );
158
159   //! Get number of sections
160   virtual int getNbSections() const;
161
162   //! For internal use only! Undo/Redo are not used here.
163   virtual int addSectionInternal( const std::string &theName, 
164                                   const CurveCreator::SectionType theType,
165                                   const bool theIsClosed,
166                                   const CurveCreator::Coordinates &thePoints);
167   //! Add a new section.
168   virtual int addSection( const std::string &theName, 
169                            const CurveCreator::SectionType theType,
170                            const bool theIsClosed );
171   //! Add a new section.
172   virtual int addSection( const std::string &theName, 
173                            const CurveCreator::SectionType theType,
174                            const bool theIsClosed,
175                            const CurveCreator::Coordinates &thePoints);
176   
177   //! For internal use only! Undo/Redo are not used here.
178   virtual bool removeSectionInternal( const int theISection );
179   //! Removes the given sections.
180   virtual bool removeSection( const int theISection );
181
182   //! Get "closed" flag of the specified section
183   virtual bool isClosed( const int theISection ) const;
184
185   //! For internal use only! Undo/Redo are not used here.
186   virtual bool setClosedInternal( const int theISection, 
187                                   const bool theIsClosed );
188   /**
189    *  Set "closed" flag of the specified section (all sections if
190    *  \a theISection is -1).
191    */
192   virtual bool setClosed( const int theISection, 
193                           const bool theIsClosed );
194
195   //! Returns specifyed section name
196   virtual std::string getSectionName( const int theISection ) const;
197
198   //! For internal use only! Undo/Redo are not used here.
199   virtual bool setSectionNameInternal( const int theISection, 
200                                        const std::string& theName );
201   /** Set name of the specified section */
202   virtual bool setSectionName( const int theISection, 
203                                const std::string& theName );
204
205   //! Get type of the specified section
206   virtual CurveCreator::SectionType getSectionType( const int theISection ) const;
207
208   //! For internal use only! Undo/Redo are not used here.
209   virtual bool setSectionTypeInternal( const int theISection, 
210                                        const CurveCreator::SectionType theType );
211   /**
212    *  Set type of the specified section (or all sections
213    *  if \a theISection is -1).
214    */
215   virtual bool setSectionType( const int theISection, 
216                                const CurveCreator::SectionType theType );
217
218
219   /***********************************************/
220   /***           Point methods                 ***/
221   /***********************************************/
222
223   //! For internal use only! Undo/Redo are not used here.
224   virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap );
225   /**
226    *  Add one point to the specified section starting from the given theIPnt index
227    *  (or at the end of points if \a theIPnt is -1).
228    */
229   virtual bool addPoints( const CurveCreator::Coordinates &theCoords,
230                           const int theISection,
231                           const int theIPnt = -1 );
232
233   //! For internal use only! Undo/Redo are not used here.
234   virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap );
235    //! Set coordinates of specified point
236   virtual bool setPoint( const int theISection,
237                          const int theIPnt,
238                          const CurveCreator::Coordinates& theNewCoords );
239
240   //! Set coordinates of specified points from different sections
241   virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords);
242
243   //! For internal use only! Undo/Redo are not used here.
244   virtual bool removePointsInternal( const SectionToPointList &thePoints );
245   /** Remove point with given id */
246   virtual bool removePoint( const int theISection, const int theIPnt = -1 );
247
248   //! Remove several points from different sections with given ids
249   virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs);
250
251   //! Get coordinates of specified point
252   virtual CurveCreator::Coordinates getPoint( const int theISection, 
253                                               const int theIPnt ) const;
254
255   /**
256    * Get points of a section (the total points in Curve if theISection is equal to -1)..
257    */
258   virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const;
259
260
261   /**
262    *  Get number of points in specified section or (the total number of points
263    *  in Curve if theISection is equal to -1).
264    */
265   virtual int getNbPoints( const int theISection ) const;
266
267
268   /***********************************************/
269   /***       Presentation methods              ***/
270   /***********************************************/
271   virtual ListAISObjects constructWire() const;
272
273 public:
274   Handle(CurveCreator_AISCurve)   myAISCurve;
275   bool                            myIsLocked;
276   CurveCreator::Sections          mySections;   //!< curve data
277   CurveCreator::Dimension         myDimension;  //!< curve dimension
278   CurveCreator_Displayer*         myDisplayer;  //!< curve displayer
279
280 private:
281
282   int                             myNbUndos;
283   int                             myNbRedos;
284   ListDiff::iterator              myCurrenPos;
285   ListDiff                        myListDiffs;
286   int                             myUndoDepth;
287   int                             myOpLevel;
288 };
289
290 #endif