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