Salome HOME
bug #155: create profile of splines
[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
32 #include <AIS_InteractiveObject.hxx>
33
34 #include <list>
35 #include <map>
36
37 struct CurveCreator_Section;
38 class CurveCreator_Displayer;
39 class AIS_Shape;
40
41 /**
42  *  The CurveCreator_Curve object is represented as one or more sets of
43  *  connected points; thus CurveCreator_Curve object can contain several
44  *  not connected curves (polylines or b-splines), each such curve has two
45  *  only ends � start and end points � in other words non-manifold curves
46  *  are not supported.
47  */
48 class CURVECREATOR_EXPORT CurveCreator_Curve : public CurveCreator_ICurve
49 {
50 protected:
51   typedef std::list<CurveCreator_Diff> ListDiff;
52
53 public:
54   //! Constructor of the curve.
55   /** The dimension is explicitly specified in the constructor
56    *  and cannot be changed later.
57    */
58   CurveCreator_Curve(const CurveCreator::Dimension theDimension);
59
60   //! Destructor.
61   virtual ~CurveCreator_Curve();
62
63   //! Get the dimension.
64   virtual CurveCreator::Dimension getDimension() const;
65
66   //! Return unique section name
67   virtual std::string getUniqSectionName() const;
68
69   //! Set curve creator Displayer object
70   virtual void setDisplayer( CurveCreator_Displayer* theDisplayer );
71
72   //! Return curve creator Displayer object
73   CurveCreator_Displayer* getDisplayer();
74
75   //! Remove curve creator Displayer object
76   virtual void removeDisplayer();
77
78   /** Set depth of undo operations (unlimited if \a theDepth is -1
79    *  or disabled if \a theDepth is 0)
80    */
81   virtual void setUndoDepth(const int theDepth = -1);
82
83   //! Get depth of undo operations.
84   virtual int getUndoDepth() const;
85
86   virtual void startOperation();
87   virtual void finishOperation();
88
89   /**
90    * This method converts the point index to the index in
91    * an array of coordinates.
92    */
93   virtual int toICoord(const int theIPnt) const;
94
95   //! For internal use only! Undo/Redo are not used here.
96   virtual bool moveSectionInternal(const int theISection,
97                            const int theNewIndex);
98   //! Move section to new position in list
99   virtual bool moveSection(const int theISection,
100                    const int theNewIndex);
101
102 protected:
103   /** This method updates all undo/redo information required to be updated
104    *  after curve modification operation. It returns false if undo/redo
105    *  is disabled and true otherwise.
106    */
107   virtual bool addEmptyDiff();
108
109 public: // TODO: remove public
110   void getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const;
111 protected:  // TODO: remove public
112   void redisplayCurve();
113
114   void convert( const SectionToPointList &thePoints,
115                 std::map<int, std::list<int> > &theConvPoints );
116
117 public:
118   /************   Implementation of INTERFACE methods   ************/
119
120   /***********************************************/
121   /***          Undo/Redo methods              ***/
122   /***********************************************/
123
124   //! Get number of available undo operations
125   virtual int getNbUndo() const;
126
127   //! Undo previous operation
128   virtual bool undo();
129
130   //! Get number of available redo operations
131   virtual int getNbRedo() const;
132
133   //! Redo last previously "undone" operation
134   virtual bool redo();
135
136
137   /***********************************************/
138   /***           Section methods               ***/
139   /***********************************************/
140
141   //! For internal use only! Undo/Redo are not used here.
142   virtual bool clearInternal();
143   //! Clear the polyline (remove all sections)
144   virtual bool clear();
145
146   //! For internal use only! Undo/Redo are not used here.
147   virtual bool joinInternal( const int theISectionTo = -1, 
148                              const int theISectionFrom = -1 );
149   //! Join range of sections to one section (join all sections if -1 is passed in one of arguments)
150   virtual bool join( const int theISectionTo = -1, 
151                      const int theISectionFrom = -1 );
152
153   //! Get number of sections
154   virtual int getNbSections() const;
155
156   //! For internal use only! Undo/Redo are not used here.
157   virtual int addSectionInternal( const std::string &theName, 
158                                   const CurveCreator::SectionType theType,
159                                   const bool theIsClosed,
160                                   const CurveCreator::Coordinates &thePoints);
161   //! Add a new section.
162   virtual int addSection( const std::string &theName, 
163                            const CurveCreator::SectionType theType,
164                            const bool theIsClosed );
165   //! Add a new section.
166   virtual int addSection( const std::string &theName, 
167                            const CurveCreator::SectionType theType,
168                            const bool theIsClosed,
169                            const CurveCreator::Coordinates &thePoints);
170   
171   //! For internal use only! Undo/Redo are not used here.
172   virtual bool removeSectionInternal( const int theISection );
173   //! Removes the given sections.
174   virtual bool removeSection( const int theISection );
175
176   //! Get "closed" flag of the specified section
177   virtual bool isClosed( const int theISection ) const;
178
179   //! For internal use only! Undo/Redo are not used here.
180   virtual bool setClosedInternal( const int theISection, 
181                                   const bool theIsClosed );
182   /**
183    *  Set "closed" flag of the specified section (all sections if
184    *  \a theISection is -1).
185    */
186   virtual bool setClosed( const int theISection, 
187                           const bool theIsClosed );
188
189   //! Returns specifyed section name
190   virtual std::string getSectionName( const int theISection ) const;
191
192   //! For internal use only! Undo/Redo are not used here.
193   virtual bool setSectionNameInternal( const int theISection, 
194                                        const std::string& theName );
195   /** Set name of the specified section */
196   virtual bool setSectionName( const int theISection, 
197                                const std::string& theName );
198
199   //! Get type of the specified section
200   virtual CurveCreator::SectionType getSectionType( const int theISection ) const;
201
202   //! For internal use only! Undo/Redo are not used here.
203   virtual bool setSectionTypeInternal( const int theISection, 
204                                        const CurveCreator::SectionType theType );
205   /**
206    *  Set type of the specified section (or all sections
207    *  if \a theISection is -1).
208    */
209   virtual bool setSectionType( const int theISection, 
210                                const CurveCreator::SectionType theType );
211
212
213   /***********************************************/
214   /***           Point methods                 ***/
215   /***********************************************/
216
217   //! For internal use only! Undo/Redo are not used here.
218   virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap );
219   /**
220    *  Add one point to the specified section starting from the given theIPnt index
221    *  (or at the end of points if \a theIPnt is -1).
222    */
223   virtual bool addPoints( const CurveCreator::Coordinates &theCoords,
224                           const int theISection,
225                           const int theIPnt = -1 );
226
227   //! For internal use only! Undo/Redo are not used here.
228   virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap );
229    //! Set coordinates of specified point
230   virtual bool setPoint( const int theISection,
231                          const int theIPnt,
232                          const CurveCreator::Coordinates& theNewCoords );
233
234   //! Set coordinates of specified points from different sections
235   virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords);
236
237   //! For internal use only! Undo/Redo are not used here.
238   virtual bool removePointsInternal( const SectionToPointList &thePoints );
239   /** Remove point with given id */
240   virtual bool removePoint( const int theISection, const int theIPnt = -1 );
241
242   //! Remove several points from different sections with given ids
243   virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs);
244
245   //! Get coordinates of specified point
246   virtual CurveCreator::Coordinates getPoint( const int theISection, 
247                                               const int theIPnt ) const;
248
249   /**
250    * Get points of a section (the total points in Curve if theISection is equal to -1)..
251    */
252   virtual CurveCreator::Coordinates getPoints( const int theISection = -1 ) const;
253
254
255   /**
256    *  Get number of points in specified section or (the total number of points
257    *  in Curve if theISection is equal to -1).
258    */
259   virtual int getNbPoints( const int theISection ) const;
260
261
262   /***********************************************/
263   /***       Presentation methods              ***/
264   /***********************************************/
265   virtual ListAISObjects constructWire();
266
267   /**
268    *  Get the curve AIS object
269    */
270   virtual Handle_AIS_InteractiveObject getAISObject() const;
271
272 public:
273   bool                            myIsLocked;
274   CurveCreator::Sections          mySections;   //!< curve data
275   CurveCreator::Dimension         myDimension;  //!< curve dimension
276   CurveCreator_Displayer*         myDisplayer;  //!< curve displayer
277   AIS_Shape*                      myAISShape;   //!< AIS shape
278
279 private:
280
281   int                             myNbUndos;
282   int                             myNbRedos;
283   ListDiff::iterator              myCurrenPos;
284   ListDiff                        myListDiffs;
285   int                             myUndoDepth;
286   int                             myOpLevel;
287 };
288
289 #endif