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