Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / lineconn2d / LineConn2d_Path.h
1 // File:      LineConn2d_Path.h
2 // Created:   11.08.05 15:08:00
3 // Author:    Alexander GRIGORIEV
4 // Copyright: Open Cascade 2005
5
6
7 #ifndef LineConn2d_Path_HeaderFile
8 #define LineConn2d_Path_HeaderFile
9
10 #include <LineConn2d_Segment.h>
11 #include <LineConn2d.h>
12 #include <NCollection_List.hxx>
13
14 class LineConn2d_Model;
15
16 /**
17  * Single path as temporary object created during the calculation of
18  * connections. It can be treated as:
19  * @li Segment having a definite orientation, origin and length. or
20  * @li 2D box along that segment, with a width equal to the model tolerance, or
21  * @li Node of the tree of Paths created during the calculations.
22  */
23
24 class LineConn2d_Path : public LineConn2d_Segment
25 {
26  public:
27   // ---------- PUBLIC METHODS ----------
28
29   /// Empty Constructor.
30   Standard_EXPORT LineConn2d_Path ();
31
32   /// Constructor.
33   Standard_EXPORT LineConn2d_Path  (const gp_XY&             theStart,
34                                     const gp_XY&             theEnd,
35                                     const LineConn2d_Model&  theModel,
36                                     const LineConn2d::Orient theOri =
37                                                         LineConn2d::Indefinite);
38   /**
39    * Query the Width.
40    */
41   Standard_EXPORT Standard_Real Width           () const;
42
43   /**
44    * Query the parent.
45    */
46   inline const LineConn2d_Path& Parent          () const
47   { return * myParent; }
48
49   /**
50    * Query the orientation, according to the given Side
51    * @param theSide
52    *   Defines the side on which the orientation is calculated.
53    *   @li Left : -1
54    *   @li Front:  0
55    *   @li Right: +1
56    */
57   Standard_EXPORT LineConn2d::Orient Orientation (const Standard_Integer theSide
58                                                         = 0) const;
59
60   /**
61    * Query the limitation of the Path.
62    * @return
63    *   @li -1: limited on the left;
64    *   @li  0: limited on the front or unlimited;
65    *   @li  1: limited on the right.
66    */
67   inline Standard_Integer       Limitation      () const
68   { return myLimitation; }
69
70   /**
71    * Query the direction according to the given Side.
72    * @param theSide
73    *   Defines the side on which the direction is calculated.
74    *   @li Left : -1
75    *   @li Front:  0
76    *   @li Right: +1
77    * @return
78    *   Unit vector of the corresponding direction.
79    */
80   Standard_EXPORT gp_XY         Direction       (const Standard_Integer theSide
81                                                    = 0) const;
82
83   /**
84    * Query the price associated with the end of the current Path.
85    * The price is calculated by the method Evaluate().
86    * The algorithm:
87    * - the distance is calculated as sum of absolute distances along X and Y.
88    * - the distance contribution to the price is percent of the half-perimeter
89    *   of the Model box.
90    * - each change of orientation gives the contribution of PriceOfBreak points.
91    */
92   inline Standard_Integer       Price           () const
93   { return myPriceLen + myPriceDist; }
94
95   /**
96    * Create a Path in the given direction. The Path stops at an Object or
97    * at the boundary of the Model.
98    * @param outPath
99    *   Created object.
100    * @param theModel
101    *   Used to provide the set of Objects, to properly stop the Path.
102    * @param theStart
103    *   Beginning of the Path.
104    * @param theOrient
105    *   Orientation of the Path.
106    * @param isRoot
107    *   True indicates the the root path is built.
108    * @return
109    *   True on success.
110    */
111   static Standard_EXPORT Standard_Boolean
112                         createPath      (LineConn2d_Path&         outPath,
113                                          const LineConn2d_Model&  theModel,
114                                          const gp_XY&             theStart,
115                                          const LineConn2d::Orient theOrient,
116                                          const Standard_Boolean   isRoot);
117
118   /**
119    * Evaluate the price of the trajectory where the current Path is the last
120    * one. This is done by incrementing the price of the Parent by the addition
121    * due to this Path element.
122    * <p>This method also checks if the path ends on theTarget, if yes then it
123    * sets the flag myIsComplete. 
124    * @param theTarget
125    *   Target point of the path sequence (the end of the calculated connection) 
126    */
127   Standard_EXPORT Standard_Integer
128                         Evaluate        (const gp_XY& theTarget);
129
130   /**
131    * Add the branch path. This method sets the Parent field in theBranch
132    * @param theBranch
133    *   Path added as branch to the current one.
134    * @param theTarget
135    *   Target point for price evaluation (method Evaluate is called with it).
136    */
137   Standard_EXPORT void  AddBranch       (LineConn2d_Path&       theBranch,
138                                          const gp_XY&           theTarget);
139
140   /**
141    * Query if the Path is completed.
142    */
143   inline Standard_Boolean
144                         IsComplete      () const
145   { return myIsComplete; }
146
147   /**
148    * Project orthogonally the given point on the Path segment.
149    * @param theResult
150    *   Output parameter, the projection point belonging to the inside of
151    *   the Path segment (only updated if the method returns True).
152    * @param thePoint
153    *   The given point to be projected.
154    * @return
155    *   True if the projection is found inside the Path segment
156    */
157   Standard_EXPORT Standard_Boolean ProjectPoint
158                                         (gp_XY&         theResult,
159                                          const gp_XY&   thePoint) const;
160
161   /**
162    * Price contributon of one path break (change of orientation)
163    */
164   static inline Standard_Integer
165                         PriceOfBreak    ()
166   { return 300; }
167
168  protected:
169   // ---------- PROTECTED METHODS ----------
170
171
172  private:
173   // ---------- PRIVATE FIELDS ----------
174   const LineConn2d_Model                * myModel;
175   const LineConn2d_Path                 * myParent;
176   NCollection_List <LineConn2d_Path>    myBranches;
177   Standard_Integer                      myPriceLen;
178   Standard_Integer                      myPriceDist;
179   Standard_Integer                      myLimitation; ///< -1, 0(def) or 1
180   LineConn2d::Orient                    myOrient;
181   Standard_Boolean                      myIsComplete;
182
183   friend class LineConn2d_PathIterator;
184 };
185
186
187 #endif