1 // File: LineConn2d_Model.h
2 // Created: 03.08.05 20:08:48
3 // Author: Alexander GRIGORIEV
4 // Copyright: Open Cascade 2005
7 #ifndef LineConn2d_Model_HeaderFile
8 #define LineConn2d_Model_HeaderFile
10 #include <LineConn2d_Object.h>
11 #include <LineConn2d_Connection.h>
12 #include <LineConn2d_Port.h>
13 #include <LineConn2d_BoxTree.h>
14 #include <NCollection_List.hxx>
16 #include <NCollection_Vector.hxx>
18 class LineConn2d_Path;
20 /// Data Model for Line Connection algorithm.
22 class LineConn2d_Model
25 // ---------- PUBLIC METHODS ----------
28 Standard_EXPORT LineConn2d_Model ();
31 // Standard_EXPORT virtual ~LineConn2d_Model ();
34 * Create a new Object in the model. This is the exclusive way to create
37 * the index of the new object, always positive
39 Standard_EXPORT Standard_Integer AddObject ();
42 * Create a new Port in the model. This method checks the validity of
43 * indices provided as parameters. It is the exclusive way to create
46 * Thanks to Windows Platform SDK, AddPort is a kinda reserved word, we
47 * others cannot use it as identifier. So the method name is not mistyped.
49 * the index of the new Port, always positive or 0 on error.
51 Standard_EXPORT Standard_Integer AddPoort (const Standard_Integer iObj,
53 const gp_Dir2d& theDir);
56 * Create a new Connection in the model. This method checks the validity of
57 * indices provided as parameters.
59 * index of the first Port
61 * index of the second Port
63 * index of the new Connection (always positive) or 0 on error.
65 Standard_EXPORT Standard_Integer AddConnection(const Standard_Integer iPort1,
66 const Standard_Integer iPort2);
69 * Query of the i-th Connection in the Model. You should be careful to provide
70 * a correct parameter value.
72 * index of the object, in the range 1 .. NbConnections inclusive
74 * const Connection reference
76 inline const LineConn2d_Connection& operator()(const Standard_Integer i) const
77 { return myConnections(i); }
80 * Query of the i-th Connection in the Model, non-const interface.
81 * You should be careful to provide a correct parameter value.
83 * index of the object, in the range 1 .. NbConnections() inclusive
85 * Connection reference
87 inline LineConn2d_Connection& operator() (const Standard_Integer i)
88 { return myConnections(i); }
91 * Query the i-th Object in the Model (const interface).
92 * You should be careful to provide a correct parameter value.
94 * index of the object, in the range 1 .. NbObjects() inclusive
96 * const Object reference
98 inline const LineConn2d_Object& Object (const Standard_Integer i) const
99 { return myObjects(i); }
102 * Query the i-th Object in the Model.
103 * You should be careful to provide a correct parameter value.
105 * index of the object, in the range 1 .. NbObjects() inclusive
109 inline LineConn2d_Object& ChangeObject(const Standard_Integer i)
110 { return myObjects(i); }
113 * Query the i-th Port in the Model (const interface).
114 * You should be careful to provide a correct parameter value.
116 * index of the object, in the range 1 .. NbPorts() inclusive
118 * const Port reference
120 inline const LineConn2d_Port& Port (const Standard_Integer i) const
121 { return myPorts(i); }
124 * Query the i-th Port in the Model.
125 * You should be careful to provide a correct parameter value.
127 * index of the object, in the range 1 .. NbPorts() inclusive
131 inline LineConn2d_Port& ChangePort (const Standard_Integer i)
132 { return myPorts(i); }
135 * Query the number of currently stored objects.
137 inline Standard_Integer NbObjects () const
138 { return myObjects.Length() - 1; }
141 * Query the number of currently stored objects.
143 inline Standard_Integer NbPorts () const
144 { return myPorts.Length() - 1; }
147 * Query the number of currently stored connections.
149 inline Standard_Integer NbConnections () const
150 { return myConnections.Length() - 1; }
153 * Set the Tolerance value.
155 inline void SetTolerance (const Standard_Real theTol)
156 { myTolerance = theTol; }
159 * Query the Tolerance value.
161 inline Standard_Real Tolerance () const
162 { return myTolerance; }
165 * Set the port length parameter. By default it is equal to 2 * Tolerance().
167 inline void SetPortLength (const Standard_Real theLen)
168 { myPortLength = theLen; }
171 * Sets the value of mySearchDepth. The lower this value, the faster the
172 * calculations, though for some connections the process may fail due to
173 * not enough search depth allowed. Roughly, this parameter means the number
174 * of breaks (direction changes) above the minimal, allowed for each branch
175 * to propagate with new paths.
176 * <p> The default value of this parameter is 4.
178 inline void SetSearchDepth(const Standard_Real theDep)
179 { mySearchDepth = ::Max (0.1, theDep); }
182 * Query the Tree structure. Should be called after Update().
184 inline const LineConn2d_BoxTree& GetTree () const
188 * Update the internal structures (including those of each contained Object)
189 * when all data have been loaded.
191 Standard_EXPORT void Update ();
194 * Query the bounding box of the Model. Should be called after Update().
196 inline const LineConn2d_Box& Box () const
197 { return myTreeBox; }
200 * Query the sum of the width and the height of the Model Box.
202 Standard_EXPORT Standard_Real HalfPerimeter () const;
205 * Query the allocator for temporary data. This allocator should be used
206 * ONLY from the code called in Compute(); the allocator is destroyed in
207 * the end of Compute, so please take care that no references to any
208 * allocated objects are propagated at the moment when Compute() terminates.
210 Standard_EXPORT const Handle_NCollection_BaseAllocator&
214 * Calculate the connections on already initialized Model.
216 Standard_EXPORT Standard_Boolean Compute ();
219 Standard_Boolean createPath (LineConn2d_Path& thePath,
220 const gp_XY& theStart,
221 const Standard_Integer iSide) const;
223 void pathOutline(NCollection_List<Standard_Real>& outList,
224 const LineConn2d_Path thePath,
225 const Standard_Integer theSide);
227 Standard_Boolean checkPort (const LineConn2d_Port& thePort) const;
229 // ---------- PRIVATE (prohibited) METHODS ----------
232 LineConn2d_Model (const LineConn2d_Model& theOther);
234 /// Assignment operator
235 LineConn2d_Model& operator = (const LineConn2d_Model& theOther);
238 // ---------- PRIVATE FIELDS ----------
241 * Allocator to manage allocations of all contained object data.
243 const Handle_NCollection_IncAllocator myAlloc;
246 * Allocator to manage allocations of all temporary data.
248 Handle_NCollection_IncAllocator myTempAlloc;
251 * Container of all Objects.
253 NCollection_Vector <LineConn2d_Object> myObjects;
256 * Container of all Connections.
258 NCollection_Vector <LineConn2d_Connection> myConnections;
261 * Container of all Ports.
263 NCollection_Vector <LineConn2d_Port> myPorts;
266 * Tree of bounding boxes indexing the Objects.
268 LineConn2d_BoxTree myTree;
271 * Bounding box including all objects and port locations. Initialized in
272 * the method Update().
274 LineConn2d_Box myTreeBox;
277 * Tolerance value: the minimal distance from path segments model Objects.
279 Standard_Real myTolerance;
282 * Length of the short line connecting a port with the connection trajectory.
284 Standard_Real myPortLength;
287 * Parameter of the algorithm implemented in Compute(): the maximal price
288 * interval in which the tree us updated by new paths. This value is
289 * multiplied by LineConn2d_Path::PriceOfBreak(), so the rough meaning of
290 * this field is the number of extra breaks allowed for each branch during
293 Standard_Real mySearchDepth;
295 // temporary fields, used inside the method Compute()
296 Standard_Real _PortLen; ///< temporary
297 gp_XY _PntTgt; ///< temporary
298 LineConn2d_Segment _SegTgtPort; ///< temporary
301 // Declaration of CASCADE RTTI
302 //DEFINE_STANDARD_RTTI (LineConn2d_Model)
305 // Definition of HANDLE object using Standard_DefineHandle.hxx
306 //DEFINE_STANDARD_HANDLE (LineConn2d_Model, )