summaryrefslogtreecommitdiff
path: root/src/Graphic3d/Graphic3d_StructureManager.cxx
blob: eba5ac443a97b73d3d69a3e7d0565baad362cc6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

#define XTRACE

// File         Graphic3d_StructureManager.cxx
// Created      Mars 1992
// Author       NW,JPB,CAL

//-Copyright    MatraDatavision 1991,1992

//-Version      

//-Design       Declaration of variables specific to managers

//-Warning      Manager manages a set of structures

//-References   

//-Language     C++ 2.0

//-Declarations

// for the class
#include <Graphic3d_StructureManager.ixx>
#include <Graphic3d_StructureManager.pxx>
static Standard_Boolean Initialisation = Standard_True;
static int StructureManager_ArrayId[StructureManager_MAX];
static Standard_Integer StructureManager_CurrentId = 0;

#include <Graphic3d_Structure.pxx>
#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>

//-Aliases

//-Global data definitions

//      -- l'identifieur du manager
//      MyId                    :       Standard_Integer;

//      -- le mode de mise a jour de l'affichage
//      MyUpdateMode            :       TypeOfUpdate;

//      -- les differents contextes de primitives
//      MyAspectLine3d          :       AspectLine3d;
//      MyAspectText3d          :       AspectText3d;
//      MyAspectMarker3d        :       AspectMarker3d;
//      MyAspectFillArea3d      :       AspectFillArea3d;

//      -- les structures affichees
//      MyDisplayedStructure    :       SequenceOfStructure;

//      -- les structures mises en evidence
//      MyHighlightedStructure  :       SequenceOfStructure;

//      -- les structures visibles
//      MyVisibleStructure      :       SequenceOfStructure;

//      -- les structures detectables
//      MyPickStructure         :       SequenceOfStructure;

//      -- le generateur d'identificateurs de structures
//      MyStructGenId           :       GenId;

//-Constructors

Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Aspect_GraphicDevice)& aDevice):
MyDisplayedStructure (),
MyHighlightedStructure (),
MyVisibleStructure (),
MyPickStructure () {

Standard_Real Coef;
Standard_Integer i;
Standard_Boolean NotFound       = Standard_True;
Standard_Integer Limit  = Graphic3d_StructureManager::Limit ();

        /* Initialize PHIGS and start up */
        if (Initialisation) {

                Initialisation = Standard_False;
                /* table to manage IDs of StructureManager */
                for (i=1; i<=Limit; i++) StructureManager_ArrayId[i]    = 0;

                StructureManager_CurrentId      = 1;
                StructureManager_ArrayId[1]     = 1;

        }
        else {
                for (i=1; i<=Limit && NotFound; i++)
                        if (StructureManager_ArrayId[i] == 0) {
                                NotFound        = Standard_False;
                                StructureManager_CurrentId      = i;
                                StructureManager_ArrayId[i]     = 1;
                        }

                if (NotFound)
                        Graphic3d_InitialisationError::Raise
                                        ("Too many ViewManagers are defined");
        }

        Coef            = (Structure_IDMIN+Structure_IDMAX)/Limit;
        Aspect_GenId theGenId(
          Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId-1)),
          Standard_Integer (Structure_IDMIN+Coef*StructureManager_CurrentId-1));
        MyStructGenId   = theGenId;

        MyId                    = StructureManager_CurrentId;

        MyAspectLine3d          = new Graphic3d_AspectLine3d ();
        MyAspectText3d          = new Graphic3d_AspectText3d ();
        MyAspectMarker3d        = new Graphic3d_AspectMarker3d ();
        MyAspectFillArea3d      = new Graphic3d_AspectFillArea3d ();

        MyUpdateMode            = Aspect_TOU_WAIT;
        MyGraphicDevice         = aDevice;

}

//-Destructors

void Graphic3d_StructureManager::Destroy () {

#ifdef TRACE
        cout << "Graphic3d_StructureManager::Destroy (" << MyId << ")\n";
        cout << flush;
#endif

        MyDisplayedStructure.Clear ();
        MyHighlightedStructure.Clear ();
        MyVisibleStructure.Clear ();
        MyPickStructure.Clear ();
        StructureManager_ArrayId[MyId]  = 0;

}

//-Methods, in order

void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) {

        MyUpdateMode    = AType;

}

Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const {

        return (MyUpdateMode);

}

void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {

        MyAspectLine3d          = CTX;

}

void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {

        MyAspectFillArea3d      = CTX;

}

void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {

        MyAspectText3d          = CTX;

}

void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {

        MyAspectMarker3d        = CTX;

}

void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {

        CTXL    = MyAspectLine3d;
        CTXT    = MyAspectText3d;
        CTXM    = MyAspectMarker3d;
        CTXF    = MyAspectFillArea3d;

}

Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {

        return (MyAspectLine3d);

}

Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {

        return (MyAspectText3d);

}

Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {

        return (MyAspectMarker3d);

}

Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {

        return (MyAspectFillArea3d);

}

void Graphic3d_StructureManager::Remove (const Standard_Integer AnId) {

#ifdef TRACE
        cout << "Graphic3d_StructureManager::Remove " << AnId << "\n" << flush;
#endif

        MyStructGenId.Free (AnId);

}

void Graphic3d_StructureManager::Visible (const Handle(Graphic3d_Structure)& AStructure) {

  MyVisibleStructure.Add(AStructure);

}

void Graphic3d_StructureManager::Invisible (const Handle(Graphic3d_Structure)& AStructure) {

  MyVisibleStructure.Remove(AStructure);
 
}

void Graphic3d_StructureManager::Detectable (const Handle(Graphic3d_Structure)& AStructure) {

  MyPickStructure.Add(AStructure);

}

void Graphic3d_StructureManager::Undetectable (const Handle(Graphic3d_Structure)& AStructure) {

  MyPickStructure.Remove(AStructure);
 
}

void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {

  SG.Assign(MyDisplayedStructure);

  //JMBStandard_Integer Length  = MyDisplayedStructure.Length ();

  //JMBfor (Standard_Integer i=1; i<=Length; i++)
  //JMB SG.Add (MyDisplayedStructure.Value (i));

}

Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {

Standard_Integer Length = MyDisplayedStructure.Extent ();

        return (Length);

}

//Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {

//return (MyDisplayedStructure.Value (AnIndex));

//}

void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {

  SG.Assign(MyHighlightedStructure);

}

void Graphic3d_StructureManager::PickStructures (Graphic3d_MapOfStructure& SG) const {

  SG.Assign(MyPickStructure);

}

void Graphic3d_StructureManager::VisibleStructures (Graphic3d_MapOfStructure& SG) const {

  SG.Assign(MyVisibleStructure);


}

void Graphic3d_StructureManager::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {

Standard_Boolean Flag = Standard_True;
Standard_Real Xm, Ym, Zm, XM, YM, ZM, RL, RF;

        RL = RealLast ();
        RF = RealFirst ();

        XMin = YMin = ZMin = RL;
        XMax = YMax = ZMax = RF;

        Graphic3d_MapIteratorOfMapOfStructure it(MyDisplayedStructure);
        for (; it.More(); it.Next()) {
          Handle(Graphic3d_Structure) SG = it.Key();
          if (! (SG->IsEmpty() || SG->IsInfinite ())) {
            SG->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
            if (Xm < XMin) XMin = Xm;
            if (Ym < YMin) YMin = Ym;
            if (Zm < ZMin) ZMin = Zm;
            if (XM > XMax) XMax = XM;
            if (YM > YMax) YMax = YM;
            if (ZM > ZMax) ZMax = ZM;
            Flag = Standard_False;
          }
        }

        // If all structures are empty or infinite
        if (Flag) {
          XMin = YMin = ZMin = RF;
          XMax = YMax = ZMax = RL;
        }
 
}
 
Standard_Integer Graphic3d_StructureManager::NewIdentification () {

Standard_Integer Id     = MyStructGenId.Next ();

#ifdef TRACE
        cout << "Graphic3d_StructureManager::NewIdentification " << Id << "\n";
        cout << flush;
#endif

        return Id;

}

Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {

//  Standard_Integer ind=0;
  Standard_Boolean notfound     = Standard_True;

  Handle(Graphic3d_Structure) StructNull;
 
  Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
  
  Handle(Graphic3d_Structure) SGfound;

  for (; it.More() && notfound; it.Next()) {
    Handle(Graphic3d_Structure) SG = it.Key();
    if ( SG->Identification () == AId) {
      notfound  = Standard_False;
      SGfound = SG;
    }
  }


  if (notfound)
    return (StructNull);
  else
    return (SGfound);

}

Standard_Integer Graphic3d_StructureManager::Identification () const {
 
        return (MyId);
 
}

Standard_Integer Graphic3d_StructureManager::Limit () {

        return (StructureManager_MAX);

}

Standard_Integer Graphic3d_StructureManager::CurrentId () {

        return (StructureManager_CurrentId);

}

Handle(Aspect_GraphicDevice) Graphic3d_StructureManager::GraphicDevice () const {

        return (MyGraphicDevice);

}