Salome HOME
Old development made for salome Hydro:
[modules/geom.git] / src / CurveCreator / CurveCreator_Curve.hxx
1 // Copyright (C) 2013-2020  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 #include <NCollection_IndexedDataMap.hxx>
35
36 struct CurveCreator_Section;
37 class CurveCreator_Displayer;
38 class AIS_Shape;
39 class AIS_InteractiveObject;
40 class Quantity_Color;
41 class TopoDS_Shape;
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   //! For internal use only! Undo/Redo are not used here.
98   virtual bool moveSectionInternal(const int theISection,
99                            const int theNewIndex);
100   //! Move section to new position in list
101   virtual bool moveSection(const int theISection,
102                    const int theNewIndex);
103
104 protected:
105   /** This method updates all undo/redo information required to be updated
106    *  after curve modification operation. It returns false if undo/redo
107    *  is disabled and true otherwise.
108    */
109   virtual bool addEmptyDiff();
110
111 public: // TODO: remove public
112   void getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const;
113 protected:  // TODO
114   void redisplayCurve(bool preEraseAllObjects = true);
115
116 public:
117   /************   Implementation of INTERFACE methods   ************/
118
119   /***********************************************/
120   /***          Undo/Redo methods              ***/
121   /***********************************************/
122
123   //! Get number of available undo operations
124   virtual int getNbUndo() const;
125
126   //! Undo previous operation
127   virtual bool undo();
128
129   //! Get number of available redo operations
130   virtual int getNbRedo() const;
131
132   //! Redo last previously "undone" operation
133   virtual bool redo();
134
135
136   /***********************************************/
137   /***           Section methods               ***/
138   /***********************************************/
139
140   //! For internal use only! Undo/Redo are not used here.
141   virtual bool clearInternal();
142   //! Clear the polyline (remove all sections)
143   virtual bool clear();
144
145   //! set erase-all state
146   //! if true => erase all objects from viever, else remove only the current curve
147   void SetEraseAllState(bool toEraseAll);
148
149   //! get erase-all state
150   //! if true => erase all objects from viever, else remove only the current curve
151   bool GetEraseAllState() const;
152
153   //! For internal use only! Undo/Redo are not used here.
154   virtual bool joinInternal( const std::list<int>& theSections );
155
156   //! Join list of sections to one section (join all if the list is empty)
157   // The first section in the list is a leader, another sections are joined to it
158   virtual bool join( const std::list<int>& theSections );
159
160   //! Get number of sections
161   virtual int getNbSections() const;
162
163   //! For internal use only! Undo/Redo are not used here.
164   virtual int addSectionInternal( const std::string &theName,
165                                   const CurveCreator::SectionType theType,
166                                   const bool theIsClosed,
167                                   const CurveCreator::Coordinates &thePoints,
168                                   const Quantity_Color& aColor);
169   //! Add a new section.
170   virtual int addSection( const std::string &theName,
171                            const CurveCreator::SectionType theType,
172                            const bool theIsClosed );
173   //! Add a new section.
174   virtual int addSection( const std::string &theName,
175                            const CurveCreator::SectionType theType,
176                            const bool theIsClosed,
177                            const CurveCreator::Coordinates &thePoints);
178
179   //! For internal use only! Undo/Redo are not used here.
180   virtual bool removeSectionInternal( const int theISection );
181   //! Removes the given sections.
182   virtual bool removeSection( const int theISection );
183
184   //! Get "closed" flag of the specified section
185   virtual bool isClosed( const int theISection ) const;
186
187   //! For internal use only! Undo/Redo are not used here.
188   virtual bool setClosedInternal( const int theISection,
189                                   const bool theIsClosed );
190   /**
191    *  Set "closed" flag of the specified section (all sections if
192    *  \a theISection is -1).
193    */
194   virtual bool setClosed( const int theISection,
195                           const bool theIsClosed );
196
197   //! Sets color of section by index
198   virtual bool setColorSection(  int SectInd, Quantity_Color theNewColor );
199
200   //! For internal use only! Undo/Redo are not used here.
201   virtual void setColorSectionInternal( int SectInd, Quantity_Color theNewColor );
202
203   virtual Quantity_Color getLastRemovedColor() const;
204
205   virtual void popLastRemovedColor();
206
207   //! Gets color of section by index
208   virtual Quantity_Color getColorSection( int SectInd ) const;
209
210   //! Returns specifyed section name
211   virtual std::string getSectionName( const int theISection ) const;
212
213   //! For internal use only! Undo/Redo are not used here.
214   virtual bool setSectionNameInternal( const int theISection,
215                                        const std::string& theName );
216   /** Set name of the specified section */
217   virtual bool setSectionName( const int theISection,
218                                const std::string& theName );
219
220   //! Get type of the specified section
221   virtual CurveCreator::SectionType getSectionType( const int theISection ) const;
222
223   //! For internal use only! Undo/Redo are not used here.
224   virtual bool setSectionTypeInternal( const int theISection,
225                                        const CurveCreator::SectionType theType );
226   /**
227    *  Set type of the specified section (or all sections
228    *  if \a theISection is -1).
229    */
230   virtual bool setSectionType( const int theISection,
231                                const CurveCreator::SectionType theType );
232
233   //! A virtual method.
234   const CurveCreator_ISection* getSection(const int theSectionIndex) const
235   {
236     if (theSectionIndex >= 0 && theSectionIndex < (int)mySections.size())
237     {
238       return (CurveCreator_ISection*)mySections[theSectionIndex];
239     }
240     return NULL;
241   }
242
243   //! A virtual method.
244   CurveCreator_ISection* getSection(const int theSectionIndex)
245   {
246     return (CurveCreator_ISection*)mySections[theSectionIndex];
247   }
248
249   /***********************************************/
250   /***           Point methods                 ***/
251   /***********************************************/
252
253   //! For internal use only! Undo/Redo are not used here.
254   virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap );
255   /**
256    *  Add one point to the specified section starting from the given theIPnt index
257    *  (or at the end of points if \a theIPnt is -1).
258    */
259   virtual bool addPoints( const CurveCreator::Coordinates &theCoords,
260                           const int theISection,
261                           const int theIPnt = -1 );
262
263   //! For internal use only! Undo/Redo are not used here.
264   virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap );
265    //! Set coordinates of specified point
266   virtual bool setPoint( const int theISection,
267                          const int theIPnt,
268                          const CurveCreator::Coordinates& theNewCoords );
269
270   //! Set coordinates of specified points from different sections
271   virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
272                                  const bool theIsToSaveDiff = true );
273
274   //! For internal use only! Undo/Redo are not used here.
275   virtual bool removePointsInternal( const SectionToPointList &thePoints );
276   /** Remove point with given id */
277   virtual bool removePoint( const int theISection, const int theIPnt = -1 );
278
279   //! Remove several points from different sections with given ids
280   virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs);
281
282   //! Get coordinates of specified point
283   virtual CurveCreator::Coordinates getPoint( const int theISection,
284                                               const int theIPnt ) const;
285
286   /**
287    * Get points of a section (the total points in Curve if theISection is equal to -1)..
288    */
289   virtual Handle(TColgp_HArray1OfPnt) GetDifferentPoints( int theISection = -1 ) const;
290
291   CurveCreator::Coordinates getCoords( int theISection = -1 ) const;
292
293
294   /**
295    *  Get number of points in specified section or (the total number of points
296    *  in Curve if theISection is equal to -1).
297    */
298   virtual int getNbPoints( const int theISection ) const;
299
300    /**
301    * Set skip sorting flag. If the flag is true - points sorting will be skipped.
302    */
303   virtual void setSkipSorting( const bool theIsToSkip );
304
305   /**
306    * Indicates whether the points can be sorted.
307    */
308   virtual bool canPointsBeSorted();
309
310   /**
311    * Saves points coordinates difference.
312    * \param theOldCoords the old points coordinates
313    */
314   virtual void saveCoordDiff( const SectionToPointCoordsList &theOldCoords );
315
316   /***********************************************/
317   /***       Presentation methods              ***/
318   /***********************************************/
319   /**
320    *  Get the curve AIS object
321    */
322   virtual Handle(AIS_InteractiveObject) getAISObject( const bool theNeedToBuild = false) const;
323
324 protected:
325   /**
326    *  Removes the points from the section. It sortes the points and remove them
327    * in the decreasing order
328    * \param theSectionId a section index
329    * \param thePointIds a list of section points
330    */
331   bool removeSectionPoints( const int theSectionId,
332                             const std::list<int>& thePointIds );
333   /**
334    * Converts the list of pairs of section to point into map of a section to list of points
335    * \param thePoints an source list
336    * \param theConvPoints a converted map
337    */
338   void convert( const SectionToPointList &thePoints,
339                 std::map<int, std::list<int> > &theConvPoints );
340
341 protected:
342   virtual void constructAISObject();
343
344 protected:
345   bool                            mySkipSorting;
346   AIS_Shape*                      myAISShape;   //!< AIS shape
347
348 public:
349   bool                            myIsLocked;
350   CurveCreator::Sections          mySections;   //!< curve data
351   CurveCreator::Dimension         myDimension;  //!< curve dimension
352   CurveCreator_Displayer*         myDisplayer;  //!< curve displayer
353   Quantity_Color myPointAspectColor;
354   //Quantity_Color myCurveColor;
355   double myLineWidth;
356   NCollection_IndexedDataMap<int, TopoDS_Shape> mySect2Shape;
357   std::vector<int> myCurSectInd;
358
359 private:
360
361   int                             myNbUndos;
362   int                             myNbRedos;
363   ListDiff::iterator              myCurrenPos;
364   ListDiff                        myListDiffs;
365   int                             myUndoDepth;
366   int                             myOpLevel;
367   bool                            myEraseAll;
368   std::vector<Quantity_Color>     myRemColors;
369 };
370
371 #endif