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