]> SALOME platform Git repositories - modules/yacs.git/blob - src/lineconn2d/LineConn2d_Model.h
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / lineconn2d / LineConn2d_Model.h
1 // File:      LineConn2d_Model.h
2 // Created:   03.08.05 20:08:48
3 // Author:    Alexander GRIGORIEV
4 // Copyright: Open Cascade 2005
5
6
7 #ifndef LineConn2d_Model_HeaderFile
8 #define LineConn2d_Model_HeaderFile
9
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>
15
16 #include <NCollection_Vector.hxx>
17
18 class LineConn2d_Path;
19
20 ///  Data Model for Line Connection algorithm.
21
22 class LineConn2d_Model
23 {
24  public:
25   // ---------- PUBLIC METHODS ----------
26
27   /// Empty constructor
28   Standard_EXPORT LineConn2d_Model ();
29
30   /// Destructor
31 //  Standard_EXPORT virtual ~LineConn2d_Model ();
32
33   /**
34    * Create a new Object in the model. This is the exclusive way to create
35    * new objects.
36    * @return
37    *   the index of the new object, always positive
38    */
39   Standard_EXPORT Standard_Integer AddObject    ();
40
41   /**
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
44    * new ports.
45    * @remark
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.
48    * @return
49    *   the index of the new Port, always positive or 0 on error.
50    */
51   Standard_EXPORT Standard_Integer AddPoort     (const Standard_Integer iObj,
52                                                  const gp_XY&           thePnt,
53                                                  const gp_Dir2d&        theDir);
54
55   /**
56    * Create a new Connection in the model. This method checks the validity of
57    * indices provided as parameters.
58    * @param iPort1
59    *   index of the first Port
60    * @param iPort2
61    *   index of the second Port
62    * @return
63    *   index of the new Connection (always positive) or 0 on error.
64    */
65   Standard_EXPORT Standard_Integer AddConnection(const Standard_Integer iPort1,
66                                                  const Standard_Integer iPort2);
67
68   /**
69    * Query of the i-th Connection in the Model. You should be careful to provide
70    * a correct parameter value.
71    * @param i
72    *   index of the object, in the range 1 .. NbConnections inclusive
73    * @return
74    *   const Connection reference
75    */
76   inline const LineConn2d_Connection& operator()(const Standard_Integer i) const
77   { return myConnections(i); }
78
79   /**
80    * Query of the i-th Connection in the Model, non-const interface.
81    * You should be careful to provide a correct parameter value.
82    * @param i
83    *   index of the object, in the range 1 .. NbConnections() inclusive
84    * @return
85    *   Connection reference
86    */
87   inline LineConn2d_Connection&     operator()  (const Standard_Integer i)
88   { return myConnections(i); }
89
90   /**
91    * Query the i-th Object in the Model (const interface).
92    * You should be careful to provide a correct parameter value.
93    * @param i
94    *   index of the object, in the range 1 .. NbObjects() inclusive
95    * @return
96    *   const Object reference
97    */
98   inline const LineConn2d_Object&   Object      (const Standard_Integer i) const
99   { return myObjects(i); }
100
101   /**
102    * Query the i-th Object in the Model.
103    * You should be careful to provide a correct parameter value.
104    * @param i
105    *   index of the object, in the range 1 .. NbObjects() inclusive
106    * @return
107    *   Object reference
108    */
109   inline LineConn2d_Object&         ChangeObject(const Standard_Integer i)
110   { return myObjects(i); }
111
112   /**
113    * Query the i-th Port in the Model (const interface).
114    * You should be careful to provide a correct parameter value.
115    * @param i
116    *   index of the object, in the range 1 .. NbPorts() inclusive
117    * @return
118    *   const Port reference
119    */
120   inline const LineConn2d_Port&     Port        (const Standard_Integer i) const
121   { return myPorts(i); }
122
123   /**
124    * Query the i-th Port in the Model.
125    * You should be careful to provide a correct parameter value.
126    * @param i
127    *   index of the object, in the range 1 .. NbPorts() inclusive
128    * @return
129    *   Port reference
130    */
131   inline LineConn2d_Port&           ChangePort  (const Standard_Integer i)
132   { return myPorts(i); }
133
134   /**
135    * Query the number of currently stored objects.
136    */
137   inline Standard_Integer           NbObjects () const
138   { return myObjects.Length() - 1; }
139
140   /**
141    * Query the number of currently stored objects.
142    */
143   inline Standard_Integer           NbPorts     () const
144   { return myPorts.Length() - 1; }
145
146   /**
147    * Query the number of currently stored connections.
148    */
149   inline Standard_Integer           NbConnections () const
150   { return myConnections.Length() - 1; }
151
152   /**
153    * Set the Tolerance value.
154    */
155   inline void                       SetTolerance (const Standard_Real theTol)
156   { myTolerance = theTol; }
157
158   /**
159    * Query the Tolerance value.
160    */
161   inline Standard_Real              Tolerance   () const
162   { return myTolerance; }
163
164   /**
165    * Set the port length parameter. By default it is equal to 2 * Tolerance().
166    */
167   inline void                       SetPortLength (const Standard_Real theLen)
168   { myPortLength = theLen; }
169
170   /**
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.
177    */
178   inline void                       SetSearchDepth(const Standard_Real theDep)
179   { mySearchDepth = ::Max (0.1, theDep); }
180
181   /**
182    * Query the Tree structure. Should be called after Update().
183    */
184   inline const LineConn2d_BoxTree&  GetTree     () const
185   { return myTree; }
186   
187   /**
188    * Update the internal structures (including those of each contained Object)
189    * when all data have been loaded.
190    */
191   Standard_EXPORT void              Update      ();
192
193   /**
194    * Query the bounding box of the Model. Should be called after Update().
195    */
196   inline const LineConn2d_Box&      Box         () const
197   { return myTreeBox; }
198
199   /**
200    * Query the sum of the width and the height of the Model Box.
201    */
202   Standard_EXPORT Standard_Real     HalfPerimeter () const;
203
204   /**
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.
209    */ 
210   Standard_EXPORT const Handle_NCollection_BaseAllocator&
211                                     TempAlloc   () const;
212
213   /**
214    * Calculate the connections on already initialized Model.
215    */
216   Standard_EXPORT Standard_Boolean  Compute     ();
217
218  private:
219   Standard_Boolean createPath (LineConn2d_Path&                 thePath,
220                                const gp_XY&                     theStart,
221                                const Standard_Integer           iSide) const;
222
223   void             pathOutline(NCollection_List<Standard_Real>& outList,
224                                const LineConn2d_Path            thePath,
225                                const Standard_Integer           theSide);
226
227   Standard_Boolean checkPort  (const LineConn2d_Port& thePort) const;
228
229   // ---------- PRIVATE (prohibited) METHODS ----------
230
231   /// Copy constructor
232   LineConn2d_Model (const LineConn2d_Model& theOther);
233
234   /// Assignment operator
235   LineConn2d_Model& operator = (const LineConn2d_Model& theOther);
236
237  private:
238   // ---------- PRIVATE FIELDS ----------
239
240   /**
241    * Allocator to manage allocations of all contained object data.
242    */
243   const Handle_NCollection_IncAllocator         myAlloc;
244
245   /**
246    * Allocator to manage allocations of all temporary data.
247    */
248   Handle_NCollection_IncAllocator               myTempAlloc;
249
250   /**
251    * Container of all Objects.
252    */
253   NCollection_Vector <LineConn2d_Object>        myObjects;
254
255   /**
256    * Container of all Connections.
257    */
258   NCollection_Vector <LineConn2d_Connection>    myConnections;
259
260   /**
261    * Container of all Ports.
262    */
263   NCollection_Vector <LineConn2d_Port>          myPorts;
264
265   /**
266    * Tree of bounding boxes indexing the Objects.
267    */
268   LineConn2d_BoxTree                            myTree;
269
270   /**
271    * Bounding box including all objects and port locations. Initialized in
272    * the method Update().
273    */
274   LineConn2d_Box                                myTreeBox;
275
276   /**
277    * Tolerance value: the minimal distance from path segments model Objects.
278    */
279   Standard_Real                                 myTolerance;
280
281   /**
282    * Length of the short line connecting a port with the connection trajectory.
283    */
284   Standard_Real                                 myPortLength;
285
286   /**
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
291    * its propagation.
292    */
293   Standard_Real                                 mySearchDepth;
294
295   // temporary fields, used inside the method Compute()
296   Standard_Real                                 _PortLen;       ///< temporary
297   gp_XY                                         _PntTgt;        ///< temporary
298   LineConn2d_Segment                            _SegTgtPort;    ///< temporary
299
300  public:
301 // Declaration of CASCADE RTTI
302 //DEFINE_STANDARD_RTTI (LineConn2d_Model)
303 };
304
305 // Definition of HANDLE object using Standard_DefineHandle.hxx
306 //DEFINE_STANDARD_HANDLE (LineConn2d_Model, )
307
308
309 #endif