1 // Copyright (C) 2013-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: CurveCreator_Curve.hxx
21 // Author: Sergey KHROMOV
23 #ifndef _CurveCreator_Curve_HeaderFile
24 #define _CurveCreator_Curve_HeaderFile
26 #include "CurveCreator_ICurve.hxx"
28 #include "CurveCreator_Macro.hxx"
29 #include "CurveCreator.hxx"
30 #include "CurveCreator_Diff.hxx"
35 struct CurveCreator_Section;
36 class CurveCreator_Displayer;
38 class AIS_InteractiveObject;
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
48 class CURVECREATOR_EXPORT CurveCreator_Curve : public CurveCreator_ICurve
51 typedef std::list<CurveCreator_Diff> ListDiff;
54 //! Constructor of the curve.
55 /** The dimension is explicitly specified in the constructor
56 * and cannot be changed later.
58 CurveCreator_Curve(const CurveCreator::Dimension theDimension);
61 virtual ~CurveCreator_Curve();
63 //! Get the dimension.
64 virtual CurveCreator::Dimension getDimension() const;
66 //! Return unique section name
67 virtual std::string getUniqSectionName() const;
69 //! Set curve creator Displayer object
70 virtual void setDisplayer( CurveCreator_Displayer* theDisplayer );
72 //! Return curve creator Displayer object
73 CurveCreator_Displayer* getDisplayer();
75 //! Remove curve creator Displayer object
76 virtual void removeDisplayer();
78 /** Set depth of undo operations (unlimited if \a theDepth is -1
79 * or disabled if \a theDepth is 0)
81 virtual void setUndoDepth(const int theDepth = -1);
83 //! Get depth of undo operations.
84 virtual int getUndoDepth() const;
86 virtual void startOperation();
87 virtual void finishOperation();
90 * This method converts the point index to the index in
91 * an array of coordinates.
93 virtual int toICoord(const int theIPnt) const;
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);
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.
107 virtual bool addEmptyDiff();
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);
115 /************ Implementation of INTERFACE methods ************/
117 /***********************************************/
118 /*** Undo/Redo methods ***/
119 /***********************************************/
121 //! Get number of available undo operations
122 virtual int getNbUndo() const;
124 //! Undo previous operation
127 //! Get number of available redo operations
128 virtual int getNbRedo() const;
130 //! Redo last previously "undone" operation
134 /***********************************************/
135 /*** Section methods ***/
136 /***********************************************/
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();
143 //! For internal use only! Undo/Redo are not used here.
144 virtual bool joinInternal( const std::list<int>& theSections );
146 //! Join list of sections to one section (join all if the list is empty)
147 // The first section in the list is a leader, another sections are joined to it
148 virtual bool join( const std::list<int>& theSections );
150 //! Get number of sections
151 virtual int getNbSections() const;
153 //! For internal use only! Undo/Redo are not used here.
154 virtual int addSectionInternal( const std::string &theName,
155 const CurveCreator::SectionType theType,
156 const bool theIsClosed,
157 const CurveCreator::Coordinates &thePoints);
158 //! Add a new section.
159 virtual int addSection( const std::string &theName,
160 const CurveCreator::SectionType theType,
161 const bool theIsClosed );
162 //! Add a new section.
163 virtual int addSection( const std::string &theName,
164 const CurveCreator::SectionType theType,
165 const bool theIsClosed,
166 const CurveCreator::Coordinates &thePoints);
168 //! For internal use only! Undo/Redo are not used here.
169 virtual bool removeSectionInternal( const int theISection );
170 //! Removes the given sections.
171 virtual bool removeSection( const int theISection );
173 //! Get "closed" flag of the specified section
174 virtual bool isClosed( const int theISection ) const;
176 //! For internal use only! Undo/Redo are not used here.
177 virtual bool setClosedInternal( const int theISection,
178 const bool theIsClosed );
180 * Set "closed" flag of the specified section (all sections if
181 * \a theISection is -1).
183 virtual bool setClosed( const int theISection,
184 const bool theIsClosed );
186 //! Returns specifyed section name
187 virtual std::string getSectionName( const int theISection ) const;
189 //! For internal use only! Undo/Redo are not used here.
190 virtual bool setSectionNameInternal( const int theISection,
191 const std::string& theName );
192 /** Set name of the specified section */
193 virtual bool setSectionName( const int theISection,
194 const std::string& theName );
196 //! Get type of the specified section
197 virtual CurveCreator::SectionType getSectionType( const int theISection ) const;
199 //! For internal use only! Undo/Redo are not used here.
200 virtual bool setSectionTypeInternal( const int theISection,
201 const CurveCreator::SectionType theType );
203 * Set type of the specified section (or all sections
204 * if \a theISection is -1).
206 virtual bool setSectionType( const int theISection,
207 const CurveCreator::SectionType theType );
209 //! A virtual method.
210 const CurveCreator_ISection* getSection(const int theSectionIndex) const
212 if (theSectionIndex >= 0 && theSectionIndex < mySections.size())
214 return (CurveCreator_ISection*)mySections[theSectionIndex];
219 //! A virtual method.
220 CurveCreator_ISection* getSection(const int theSectionIndex)
222 return (CurveCreator_ISection*)mySections[theSectionIndex];
225 /***********************************************/
226 /*** Point methods ***/
227 /***********************************************/
229 //! For internal use only! Undo/Redo are not used here.
230 virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap );
232 * Add one point to the specified section starting from the given theIPnt index
233 * (or at the end of points if \a theIPnt is -1).
235 virtual bool addPoints( const CurveCreator::Coordinates &theCoords,
236 const int theISection,
237 const int theIPnt = -1 );
239 //! For internal use only! Undo/Redo are not used here.
240 virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap );
241 //! Set coordinates of specified point
242 virtual bool setPoint( const int theISection,
244 const CurveCreator::Coordinates& theNewCoords );
246 //! Set coordinates of specified points from different sections
247 virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
248 const bool theIsToSaveDiff = true );
250 //! For internal use only! Undo/Redo are not used here.
251 virtual bool removePointsInternal( const SectionToPointList &thePoints );
252 /** Remove point with given id */
253 virtual bool removePoint( const int theISection, const int theIPnt = -1 );
255 //! Remove several points from different sections with given ids
256 virtual bool removeSeveralPoints( const SectionToPointList &theSectionToPntIDs);
258 //! Get coordinates of specified point
259 virtual CurveCreator::Coordinates getPoint( const int theISection,
260 const int theIPnt ) const;
263 * Get points of a section (the total points in Curve if theISection is equal to -1)..
265 virtual Handle(TColgp_HArray1OfPnt) GetDifferentPoints( int theISection = -1 ) const;
267 CurveCreator::Coordinates getCoords( int theISection = -1 ) const;
271 * Get number of points in specified section or (the total number of points
272 * in Curve if theISection is equal to -1).
274 virtual int getNbPoints( const int theISection ) const;
277 * Set skip sorting flag. If the flag is true - points sorting will be skipped.
279 virtual void setSkipSorting( const bool theIsToSkip );
282 * Indicates whether the points can be sorted.
284 virtual bool canPointsBeSorted();
287 * Saves points coordinates difference.
288 * \param theOldCoords the old points coordinates
290 virtual void saveCoordDiff( const SectionToPointCoordsList &theOldCoords );
292 /***********************************************/
293 /*** Presentation methods ***/
294 /***********************************************/
296 * Get the curve AIS object
298 virtual Handle(AIS_InteractiveObject) getAISObject( const bool theNeedToBuild = false) const;
302 * Removes the points from the section. It sortes the points and remove them
303 * in the decreasing order
304 * \param theSectionId a section index
305 * \param thePointIds a list of section points
307 bool removeSectionPoints( const int theSectionId,
308 const std::list<int>& thePointIds );
310 * Converts the list of pairs of section to point into map of a section to list of points
311 * \param thePoints an source list
312 * \param theConvPoints a converted map
314 void convert( const SectionToPointList &thePoints,
315 std::map<int, std::list<int> > &theConvPoints );
318 virtual void constructAISObject();
325 CurveCreator::Sections mySections; //!< curve data
326 CurveCreator::Dimension myDimension; //!< curve dimension
327 CurveCreator_Displayer* myDisplayer; //!< curve displayer
328 Quantity_Color myPointAspectColor;
329 Quantity_Color myCurveColor;
336 ListDiff::iterator myCurrenPos;
337 ListDiff myListDiffs;
340 AIS_Shape* myAISShape; //!< AIS shape