Salome HOME
new files added
[modules/gui.git] / src / GLViewer / GLViewer_Tools.h
1 // File:      GLViewer_Tools.h
2 // Created:   April, 2005
3 // Author:    OCC team
4
5 #ifndef GLVIEWER_TOOLS_H
6 #define GLVIEWER_TOOLS_H
7
8 #ifdef WNT
9 #include "windows.h"
10 #endif
11
12 #include "GLViewer.h"
13 #include "GLViewer_Defs.h"
14
15 class GLViewer_LineField;
16
17 /****************************************************************************
18 **  Class:   GLViewer_Tools 
19 **  Descr:   Tools for Viewer
20 **  Module:  GLViewer
21 **  Created: UI team, 27.10.05
22 *****************************************************************************/
23 class GLVIEWER_API GLViewer_Tools
24 {
25 public:
26         //GLViewer_Tools();
27         //virtual ~GLViewer_Tools();
28   //static 
29
30 };
31
32 enum FieldDim
33 {
34   FD_X = 0,
35   FD_Y = 1
36 };
37
38 /****************************************************************************
39 **  Class:   GLViewer_LineList 
40 **  Descr:   Tools for distinct line
41 **  Module:  GLViewer
42 **  Created: UI team, 27.10.05
43 *****************************************************************************/
44 class GLViewer_LineList  
45 {
46 public:
47         GLViewer_LineList( int  );
48         virtual ~GLViewer_LineList();
49
50   int         count() const { return mySegmentNumber; }
51   int         size() const { return myRealSize; }
52
53   bool        addSegment( double coord1, double coord2 );
54   bool        removeSegment( int index );
55   bool        removeSegment( double coord1, double coord2 );
56
57   bool        readSegment( int index, double&, double& );
58
59   int         contains( double thePoint ) const;
60
61   void        setMainCoord( double theVal ) { myMainCoord = theVal; }
62   double      mainCoord() const { return myMainCoord; }
63
64   void        clear();
65   void        print();
66
67   void        show( FieldDim );
68   
69   GLViewer_LineList& operator = ( GLViewer_LineList );
70
71 private:
72   double*     myArray;
73   int         myRealSize;
74   int         mySegmentNumber;
75
76   double      myMainCoord;
77 };
78
79 struct GraphNode
80 {
81   int       myCount;
82   FieldDim  myDim;
83   int       myLineIndex;
84   int       mySegmentindex;
85   int       prevNodeIndex; //feedback for searching for solution
86 };
87
88 struct SearchPoint
89 {
90   int       myXLineIndex;
91   int       myXSegmentIndex;
92   int       myYLineIndex;
93   int       myYSegmentIndex;
94   int       mySolveIndex;
95 };
96
97 /****************************************************************************
98 **  Class:   GLViewer_LineField 
99 **  Descr:   Tools for solving 
100 **  Module:  GLViewer
101 **  Created: UI team, 27.10.05
102 *****************************************************************************/
103 class GLViewer_LineField
104 {
105 public:
106   enum  FieldPoint
107   {
108     FP_Start = 0,
109     FP_End = 1
110   };
111
112   enum IterationStatus
113   {
114     IS_ERROR = 0,
115     IS_LOOP,
116     IS_NOT_SOLVED,
117     IS_SOLVED
118   };
119
120   enum EndStatus
121   {
122     ES_ERROR = 0,
123     ES_LOOP,
124     ES_SOLVED
125   };
126
127   GLViewer_LineField();
128   GLViewer_LineField( const int theMAXSize, const int xn, const int yn );
129   virtual ~GLViewer_LineField();
130
131   //best way, if line is already sorted
132   void                addLine( FieldDim, GLViewer_LineList* );
133   void                addLine( FieldDim theDim, double theMC, double theBegin, double theEnd );
134 //  void                addLine( FieldDim, double theMainCoord, double theBegin, double theEnd ):
135   
136   int                 insertLine( FieldDim theDim, GLViewer_LineList*, int thePosition ); // return position
137   int                 insertLine( FieldDim theDim, double theMC, double theBegin, double theEnd, int thePosition ); // return position
138
139   static FieldDim     invertDim( FieldDim );
140
141   GLViewer_LineList*  getLine( int index, FieldDim );
142
143   void                setBorders( double X1, double X2, double Y1, double Y2 );
144   void                addRectangle( double top, double right, double bottom, double left );
145
146   int*                intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL , int& theSize );
147
148   void                print();
149
150   void                show();  
151
152   int                 getDimSize( FieldDim );
153   int                 segmentNumber();
154
155   bool                setPoint( FieldPoint, double, double );
156
157   void                optimize();
158   void                initialize();//needs call setPoint before
159   EndStatus           startAlgorithm();//main method
160
161   double*             solution( int& );
162
163 protected:
164   void                iteration();
165   IterationStatus     checkComplete();  
166
167   int*                findByCount( int& theParam );
168   int                 findBySegment( FieldDim, int, int, bool inCurArray = true );
169
170   GraphNode*          getCurArray();
171   GraphNode*          getSecArray();
172
173   int                 maxSegmentNum();
174
175   GLViewer_LineList** getLLArray( FieldDim );
176
177 private:
178   GLViewer_LineList**    myXLineArray,
179                    **    myYLineArray;
180
181   int           myXSize,
182                 myYSize;
183
184   GraphNode*    myGraphArray1,
185            *    myGraphArray2;
186   int           myCurArrayIndex;
187
188   SearchPoint   myStartPoint,
189                 myEndPoint;
190   int           myCurCount;
191 };
192
193 #endif //GLVIEWER_TOOLS_H