Salome HOME
Copyright update 2022
[modules/geom.git] / src / CurveCreator / CurveCreator_ICurve.hxx
1 // Copyright (C) 2013-2022  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_ICurve.hxx
21 // Author:      Alexander KOVALEV and Alexander SOLOVYOV
22
23 #ifndef _CurveCreator_ICurve_HeaderFile
24 #define _CurveCreator_ICurve_HeaderFile
25
26 #include "CurveCreator.hxx"
27 #include "CurveCreator_Macro.hxx"
28
29 #include <TColgp_HArray1OfPnt.hxx>
30 #include <AIS_InteractiveObject.hxx>
31
32 #include <deque>
33 #include <vector>
34 #include <string>
35 #include <list>
36
37 namespace CurveCreator
38 {
39   //! Type of the section
40   enum SectionType
41   {
42     Polyline,
43     Spline,
44   };
45
46   //! Dimension of the curve
47   enum Dimension
48   {
49     Dim2d = 2,
50     Dim3d = 3
51   };
52
53 }
54
55 //! The type represents the interface to the curve section.
56 struct CURVECREATOR_EXPORT CurveCreator_ISection
57 {
58   //! The destructor.
59   virtual ~CurveCreator_ISection() {}
60
61   //! Calculates the different points of the section.
62   virtual Handle(TColgp_HArray1OfPnt) GetDifferentPoints( int theDimension ) const = 0;
63 };
64
65 /**
66  *  The CurveCreator_ICurve object is represented as one or more sets of
67  *  connected points; thus CurveCreator_ICurve object can contain several
68  *  not connected curves (polylines or b-splines), each such curve has two
69  *  only ends "start and end points" in other words non-manifold curves
70  *  are not supported.
71  */
72 class CURVECREATOR_EXPORT CurveCreator_ICurve
73 {
74 public:
75   typedef std::pair<int,int> SectionToPoint;
76   typedef std::deque<SectionToPoint> SectionToPointList;
77
78   typedef std::deque< std::pair< SectionToPoint, CurveCreator::Coordinates > > SectionToPointCoordsList;
79
80 public:
81   /***********************************************/
82   /***          Undo/Redo methods              ***/
83   /***********************************************/
84
85   //! The destructor.
86   virtual ~CurveCreator_ICurve() {}
87
88   //! Get number of available undo operations
89   virtual int getNbUndo() const = 0;
90
91   //! Undo previous operation
92   virtual bool undo() = 0;
93
94   //! Get number of available redo operations
95   virtual int getNbRedo() const = 0;
96
97   //! Redo last previously "undone" operation
98   virtual bool redo() = 0;
99
100
101   /***********************************************/
102   /***           Section methods               ***/
103   /***********************************************/
104
105   //! Clear the polyline (remove all sections)
106   virtual bool clear() = 0;
107
108   //! Join list of sections to one section (join all if the list is empty)
109   // The first section in the list is a leader, another sections are joined to it
110   virtual bool join( const std::list<int>& theSections ) = 0;
111
112   //! Get number of sections
113   virtual int getNbSections() const = 0;
114
115   //! Add a new section.
116   virtual int addSection( const std::string& theName, 
117                            const CurveCreator::SectionType theType,
118                            const bool theIsClosed ) = 0;
119
120   //! Removes the given sections.
121   virtual bool removeSection( const int theISection ) = 0;
122
123   //! Get "closed" flag of the specified section
124   virtual bool isClosed( const int theISection ) const = 0;
125
126   /**
127    *  Set "closed" flag of the specified section (all sections if
128    *  \a theISection is -1).
129    */
130   virtual bool setClosed( const int theISection, 
131                           const bool theIsClosed ) = 0;
132
133   //! Returns specifyed section name
134   virtual std::string getSectionName( const int theISection ) const = 0;
135
136   /** Set name of the specified section */
137   virtual bool setSectionName( const int theISection, 
138                                const std::string& theName ) = 0;
139
140   //! Get type of the specified section
141   virtual CurveCreator::SectionType getSectionType( const int theISection ) const = 0;
142
143   /**
144    *  Set type of the specified section (or all sections
145    *  if \a theISection is -1).
146    */
147   virtual bool setSectionType( const int theISection, 
148                                const CurveCreator::SectionType theType ) = 0;
149
150   //! Returns the curve section with the index.
151   virtual const CurveCreator_ISection* getSection(
152     const int theSectionIndex) const = 0;
153
154   //! Returns the curve section with the index.
155   virtual CurveCreator_ISection* getSection(const int theSectionIndex) = 0;
156
157
158   /***********************************************/
159   /***           Point methods                 ***/
160   /***********************************************/
161
162   //! Get the dimension.
163   virtual CurveCreator::Dimension getDimension() const = 0;
164
165   /**
166    *  Insert one or several points to the specified section starting from the given theIPnt index
167    *  (or add these at the end of section points if \a theIPnt is -1).
168    */
169   virtual bool addPoints( const CurveCreator::Coordinates& theCoords,
170                           const int theISection,
171                           const int theIPnt = -1 ) = 0;
172
173   //! Set coordinates of specified point
174   virtual bool setPoint( const int theISection,
175                          const int theIPnt,
176                          const CurveCreator::Coordinates& theNewCoords ) = 0;
177   
178   //! Set coordinates of specified points from different sections
179   virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
180                                  const bool theIsToSaveDiff = true ) = 0;
181
182   //! Remove point with given id
183   virtual bool removePoint( const int theISection, const int theIPnt = -1 ) = 0;
184   //! Remove several points from different sections
185   virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs) = 0;
186
187   //! Get coordinates of specified point
188   virtual CurveCreator::Coordinates getPoint( const int theISection, 
189                                       const int theIPnt ) const = 0;
190
191   /**
192    * Get points of a section (the total points in Curve if theISection is equal to -1)..
193    */
194   virtual Handle(TColgp_HArray1OfPnt) GetDifferentPoints( int theISection = -1 ) const = 0;
195
196   /**
197    *  Get number of points in specified section or (the total number of points
198    *  in Curve if theISection is equal to -1).
199    */
200   virtual int getNbPoints( const int theISection ) const = 0;
201
202   /**
203    * Set skip sorting flag. If the flag is true - points sorting will be skipped.
204    */
205   virtual void setSkipSorting( const bool ) = 0;
206
207   /**
208    * Indicates whether the points can be sorted.
209    */
210   virtual bool canPointsBeSorted() = 0;
211
212   /**
213    * Saves points coordinates difference.
214    * \param theOldCoords the old points coordinates
215    */
216   virtual void saveCoordDiff( const SectionToPointCoordsList &theOldCoords ) = 0;
217
218   /***********************************************/
219   /***       Presentation methods              ***/
220   /***********************************************/
221
222   virtual Handle(AIS_InteractiveObject) getAISObject( const bool theNeedToBuild = false ) const = 0;
223
224 protected:
225   virtual void constructAISObject() = 0;
226
227 };
228
229 #endif