Salome HOME
PAL10125 - by double click on reference original object becomes selected
[modules/gui.git] / src / GLViewer / GLViewer_Tools.h
1 // File:      GLViewer_Tools.h
2 // Created:   April, 2005
3 // Author:    OCC team
4 // Copyright (C) CEA 2005
5
6 #ifndef GLVIEWER_TOOLS_H
7 #define GLVIEWER_TOOLS_H
8
9 #ifdef WNT
10 #include "windows.h"
11 #endif
12
13 #include "GLViewer.h"
14 #include "GLViewer_Defs.h"
15
16 class GLViewer_LineField;
17
18 /****************************************************************************
19 **  Class:   GLViewer_Tools 
20 **  Descr:   Tools for Viewer
21 **  Module:  GLViewer
22 **  Created: UI team, 27.10.05
23 *****************************************************************************/
24 class GLVIEWER_API GLViewer_Tools
25 {
26 public:
27         //GLViewer_Tools();
28         //virtual ~GLViewer_Tools();
29   //static 
30
31 };
32
33 //! Dimension of line
34 enum FieldDim
35 {
36   FD_X = 0, /*along x axis*/
37   FD_Y      /*along y axis*/
38 };
39
40 /*!
41   Class GLViewer_LineList 
42   Tools for distinct line
43   This class implmented interface for segment operations:
44   add, cut, remove and etc.
45   Memory does not changed and allocated only one time
46 */
47 class GLViewer_LineList  
48 {
49 public:
50   GLViewer_LineList( int  );
51   virtual ~GLViewer_LineList();
52
53   //! Returns number of segments
54   int         count() const { return mySegmentNumber; }
55   //! Returns real size
56   int         size() const { return myRealSize; }
57   
58   bool        addSegment( double coord1, double coord2 );
59   bool        removeSegment( int index );
60   bool        removeSegment( double coord1, double coord2 );
61
62   bool        readSegment( int index, double& coord1, double& coord2 );
63
64   //! Returns index of segment, else -1
65   int         contains( double thePoint ) const;
66
67   //! Sets level of segments
68   void        setMainCoord( double theVal ) { myMainCoord = theVal; }
69   double      mainCoord() const { return myMainCoord; }
70
71   void        clear();
72   void        print();
73
74   void        show( FieldDim );
75   
76   GLViewer_LineList& operator = ( GLViewer_LineList );
77
78 private:
79   double*     myArray;
80   int         myRealSize;
81   int         mySegmentNumber;
82
83   double      myMainCoord;
84 };
85
86 /*! struct GraphNode describe node in algorithm on rare grid*/
87 struct GraphNode
88 {
89   int       myCount;
90   FieldDim  myDim;
91   int       myLineIndex;
92   int       mySegmentindex;
93   int       prevNodeIndex; //feedback for searching for solution
94 };
95
96 /*! struct SearchPoint describe node for solving algorithm*/
97 struct SearchPoint
98 {
99   int       myXLineIndex;
100   int       myXSegmentIndex;
101   int       myYLineIndex;
102   int       myYSegmentIndex;
103   int       mySolveIndex;
104 };
105
106 /*! Class  GLViewer_LineField 
107 * Tools for solving algorithm of finding shortest path on rare grid with minimum of 
108 * line turns number
109 */
110 class GLViewer_LineField
111 {
112 public:
113   //!Searched point
114   enum  FieldPoint
115   {
116     FP_Start = 0,
117     FP_End = 1
118   };
119
120   //! Status of interation
121   enum IterationStatus
122   {
123     IS_ERROR = 0,
124     IS_LOOP,
125     IS_NOT_SOLVED,
126     IS_SOLVED
127   };
128
129   //! Final status of solving
130   enum EndStatus
131   {
132     ES_ERROR = 0,
133     ES_LOOP,
134     ES_SOLVED
135   };
136
137   GLViewer_LineField();
138   GLViewer_LineField( const int theMAXSize, const int xn, const int yn );
139   virtual ~GLViewer_LineField();
140
141   //! Adds new line
142   /*!best way, if line is already sorted*/
143   void                addLine( FieldDim, GLViewer_LineList* );
144   //! Calls previous
145   void                addLine( FieldDim theDim, double theMC, double theBegin, double theEnd );
146   
147   //! Adds new line and sorted field
148   /*! Returns position*/
149   int                 insertLine( FieldDim theDim, GLViewer_LineList*, int thePosition );
150   //! Calls previous
151   int                 insertLine( FieldDim theDim, double theMC, double theBegin, double theEnd, int thePosition );
152
153   //! Returns other dimension
154   static FieldDim     invertDim( FieldDim );
155
156   //! Returns line by index and dimension
157   GLViewer_LineList*  getLine( int index, FieldDim );
158
159   //! Nullifys field and sets same continued segments
160   void                setBorders( double X1, double X2, double Y1, double Y2 );
161   //! Cut rectangle in grid
162   void                addRectangle( double top, double right, double bottom, double left );
163
164   //! returns arrey of intersects indexes with \param theLL
165   int*                intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL , int& theSize );
166
167   void                print();
168
169   void                show();  
170
171   int                 getDimSize( FieldDim );
172   //! Returns number of segment
173   int                 segmentNumber();
174
175   //! Sets start/end search point
176   bool                setPoint( FieldPoint, double x, double y );
177
178   //! Optimize field
179   /*! Removes all multiple segments*/
180   void                optimize();
181   //! Some prepare actions
182   /*! Needs call setPoint before*/
183   void                initialize();
184   //! Main method
185   EndStatus           startAlgorithm();
186
187   //! Returns solution and size of solution
188   double*             solution( int& size );
189
190 protected:
191   //! One iteration of algorithm
192   void                iteration();
193   //! Checks for complete status
194   IterationStatus     checkComplete();  
195
196   //! Finds LileList by counts and returns indexes
197   int*                findByCount( int& theParam );
198   //! Finds LileList by segment and dimension
199   int                 findBySegment( FieldDim, int coord1, int coord2, bool inCurArray = true );
200
201   //! Returns current solution array
202   GraphNode*          getCurArray();
203   //! Returns 
204   GraphNode*          getSecArray();
205
206   //! Returns maximum segment number
207   int                 maxSegmentNum();
208
209   //! Returns list of LileList by dimension
210   GLViewer_LineList** getLLArray( FieldDim );
211
212 private:
213   GLViewer_LineList**    myXLineArray,
214                    **    myYLineArray;
215
216   int           myXSize,
217                 myYSize;
218
219   GraphNode*    myGraphArray1,
220            *    myGraphArray2;
221   int           myCurArrayIndex;
222
223   SearchPoint   myStartPoint,
224                 myEndPoint;
225   int           myCurCount;
226 };
227
228 #endif //GLVIEWER_TOOLS_H