0024877: GCC 4.4.5 compiler warnings on Debian when OCCT is bult using CMake
[occt.git] / src / MeshVS / MeshVS_Mesh.cxx
CommitLineData
b311480e 1// Created on: 2003-09-09
2// Created by: Alexander SOLOVYOV
973c2be1 3// Copyright (c) 2003-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <MeshVS_Mesh.ixx>
17
18#include <AIS_InteractiveContext.hxx>
19
20#include <Prs3d_Root.hxx>
21#include <gp_Pnt.hxx>
22#include <TColgp_Array1OfPnt.hxx>
23
24#include <Select3D_SensitivePoint.hxx>
25#include <SelectMgr_Selection.hxx>
26
27#include <Aspect_MarkerStyle.hxx>
28#include <Aspect_LineStyle.hxx>
29#include <Aspect_InteriorStyle.hxx>
30
31#include <Prs3d_PointAspect.hxx>
32#include <Prs3d_LineAspect.hxx>
33#include <Prs3d_ShadingAspect.hxx>
34#include <Prs3d_Presentation.hxx>
35#include <PrsMgr_ModedPresentation.hxx>
36#include <PrsMgr_PresentationManager3d.hxx>
37
38#include <SelectBasics_SensitiveEntity.hxx>
39#include <SelectMgr_SequenceOfOwner.hxx>
40#include <Select3D_SensitiveGroup.hxx>
41#include <Select3D_SensitiveBox.hxx>
42
43#include <Graphic3d_MaterialAspect.hxx>
44#include <Graphic3d_AspectFillArea3d.hxx>
45#include <Graphic3d_NameOfMaterial.hxx>
46
47#include <TColStd_Array1OfReal.hxx>
48#include <TColStd_Array1OfInteger.hxx>
49#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
50#include <TColStd_ListIteratorOfListOfReal.hxx>
51#include <TColStd_SequenceOfInteger.hxx>
52#include <TColStd_ListIteratorOfListOfInteger.hxx>
53
54#include <Bnd_Box.hxx>
55
56#include <MeshVS_DataSource.hxx>
57#include <MeshVS_MeshEntityOwner.hxx>
58#include <MeshVS_MeshOwner.hxx>
59#include <MeshVS_SensitiveMesh.hxx>
60#include <MeshVS_DummySensitiveEntity.hxx>
61#include <MeshVS_SensitiveSegment.hxx>
62#include <MeshVS_SensitiveFace.hxx>
63#include <MeshVS_DrawerAttribute.hxx>
64#include <MeshVS_DataMapIteratorOfDataMapOfIntegerOwner.hxx>
65#include <MeshVS_SensitivePolyhedron.hxx>
66#include <MeshVS_SelectionModeFlags.hxx>
67#include <MeshVS_Buffer.hxx>
68
69#include <OSD_Timer.hxx>
70
71//================================================================
72// Function : Constructor MeshVS_Mesh
73// Purpose :
74//================================================================
75MeshVS_Mesh::MeshVS_Mesh (const Standard_Boolean theIsAllowOverlapped )
76{
77 myDataSource.Nullify();
78 myHilighter.Nullify();
79 myWholeMeshOwner.Nullify();
80 mySelectionMethod = MeshVS_MSM_NODES;
81
82 SetAutoHilight ( Standard_False );
83
84 SetDisplayMode( MeshVS_DMF_WireFrame ); // Mode as defaut
85 SetHilightMode( MeshVS_DMF_WireFrame ); // Wireframe as default hilight mode
86
87 SetColor ( Quantity_NOC_WHITE );
88 SetMaterial ( Graphic3d_NOM_PLASTIC );
89
90 myCurrentDrawer = new MeshVS_Drawer();
91 myCurrentDrawer->SetColor ( MeshVS_DA_InteriorColor, Quantity_NOC_BLUE4 );
92 myCurrentDrawer->SetInteger ( MeshVS_DA_InteriorStyle, Aspect_IS_SOLID );
93 myCurrentDrawer->SetInteger ( MeshVS_DA_MaxFaceNodes, 10 );
94 myCurrentDrawer->SetBoolean ( MeshVS_DA_IsAllowOverlapped, theIsAllowOverlapped );
95 myCurrentDrawer->SetBoolean ( MeshVS_DA_Reflection, Standard_True );
96 myCurrentDrawer->SetDouble ( MeshVS_DA_ShrinkCoeff, 0.8 );
97 myCurrentDrawer->SetBoolean ( MeshVS_DA_ComputeTime, Standard_False );
98 myCurrentDrawer->SetBoolean ( MeshVS_DA_ComputeSelectionTime, Standard_False );
99 myCurrentDrawer->SetBoolean ( MeshVS_DA_DisplayNodes, Standard_True );
100 myCurrentDrawer->SetDouble ( MeshVS_DA_EdgeWidth, 1.0 );
101 myCurrentDrawer->SetInteger ( MeshVS_DA_EdgeType, Aspect_TOL_SOLID );
102 myCurrentDrawer->SetInteger ( MeshVS_DA_MarkerType, Aspect_TOM_O );
103 myCurrentDrawer->SetColor ( MeshVS_DA_MarkerColor, Quantity_NOC_WHITE );
104 myCurrentDrawer->SetDouble ( MeshVS_DA_MarkerScale, 1.0 );
105 myCurrentDrawer->SetInteger ( MeshVS_DA_BeamType, Aspect_TOL_SOLID );
106 myCurrentDrawer->SetDouble ( MeshVS_DA_BeamWidth, 1.0 );
107 myCurrentDrawer->SetBoolean ( MeshVS_DA_SmoothShading, Standard_False );
108 myCurrentDrawer->SetBoolean ( MeshVS_DA_SupressBackFaces, Standard_False );
109
110 mySelectionDrawer = new MeshVS_Drawer();
111 mySelectionDrawer->Assign ( myCurrentDrawer );
112 mySelectionDrawer->SetInteger ( MeshVS_DA_MarkerType, Aspect_TOM_STAR );
113 mySelectionDrawer->SetColor ( MeshVS_DA_MarkerColor, Quantity_NOC_GRAY80 );
114 mySelectionDrawer->SetDouble ( MeshVS_DA_MarkerScale, 2.0 );
115
116 mySelectionDrawer->SetColor ( MeshVS_DA_BeamColor, Quantity_NOC_GRAY80 );
117 mySelectionDrawer->SetInteger ( MeshVS_DA_BeamType, Aspect_TOL_SOLID );
118 mySelectionDrawer->SetDouble ( MeshVS_DA_BeamWidth, 3.0 );
119
120 myHilightDrawer = new MeshVS_Drawer ();
121 myHilightDrawer->Assign ( myCurrentDrawer );
122 myHilightDrawer->SetDouble ( MeshVS_DA_ShrinkCoeff, 0.7 );
123 myHilightDrawer->SetInteger ( MeshVS_DA_InteriorStyle, Aspect_IS_SOLID );
124 myHilightDrawer->SetColor ( MeshVS_DA_InteriorColor, Quantity_NOC_YELLOW );
125 myHilightDrawer->SetColor ( MeshVS_DA_BackInteriorColor, Quantity_NOC_YELLOW );
126 myHilightDrawer->SetColor ( MeshVS_DA_EdgeColor, Quantity_NOC_GREEN );
127 myHilightDrawer->SetInteger ( MeshVS_DA_EdgeType, Aspect_TOL_SOLID );
128 myHilightDrawer->SetDouble ( MeshVS_DA_EdgeWidth, 1.0 );
129 myHilightDrawer->SetMaterial ( MeshVS_DA_FrontMaterial, Graphic3d_NOM_PLASTIC );
130 myHilightDrawer->SetMaterial ( MeshVS_DA_BackMaterial, Graphic3d_NOM_PLASTIC );
131
132 myHilightDrawer->SetColor ( MeshVS_DA_BeamColor, Quantity_NOC_GRAY80 );
133 myHilightDrawer->SetInteger ( MeshVS_DA_BeamType, Aspect_TOL_SOLID );
134 myHilightDrawer->SetDouble ( MeshVS_DA_BeamWidth, 3.0 );
135
136 myHilightDrawer->SetInteger ( MeshVS_DA_MarkerType, Aspect_TOM_STAR );
137 myHilightDrawer->SetColor ( MeshVS_DA_MarkerColor, Quantity_NOC_GRAY80 );
138 myHilightDrawer->SetDouble ( MeshVS_DA_MarkerScale, 2.0 );
139}
140
141void MeshVS_Mesh::Destroy()
142{
143}
144
145//================================================================
146// Function : Compute
147// Purpose :
148//================================================================
149void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
150 const Handle(Prs3d_Presentation)& thePresentation,
151 const Standard_Integer theMode )
152{
153 OSD_Timer gTimer;
154
155 Standard_Boolean ShowComputeTime = Standard_True;
156 myCurrentDrawer->GetBoolean( MeshVS_DA_ComputeTime, ShowComputeTime );
157
158 if ( ShowComputeTime )
159 {
160 gTimer.Reset();
161 gTimer.Start();
162 }
163
164 // Repair Ids in map if necessary
165 Handle( MeshVS_DataSource ) aDS = GetDataSource();
166 if ( aDS.IsNull() )
167 return;
168
169 const TColStd_PackedMapOfInteger& aNodes = aDS->GetAllNodes();
170 const TColStd_PackedMapOfInteger& aElems = aDS->GetAllElements();
171 Standard_Boolean HasNodes = !aNodes.IsEmpty(),
172 HasElements = !aElems.IsEmpty();
173
174 TColStd_PackedMapOfInteger aNodesToExclude, aElemsToExclude;
175
176 thePresentation->Clear();
177 Standard_Integer len = myBuilders.Length();
178 if ( theMode > 0 )
179 for ( Standard_Integer i=1; i<=len; i++ )
180 {
181 Handle (MeshVS_PrsBuilder) aCurrent = myBuilders.Value ( i );
182 if ( !aCurrent.IsNull() && aCurrent->TestFlags ( theMode ) )
183 {
184 aCurrent->SetPresentationManager( thePrsMgr );
185 if( HasNodes )
186 aCurrent->Build ( thePresentation, aNodes, aNodesToExclude, Standard_False, theMode );
187 if( HasElements )
188 aCurrent->Build ( thePresentation, aElems, aElemsToExclude, Standard_True, theMode );
189 }
190 }
191
192
193 if ( ShowComputeTime )
194 {
195 Standard_Real sec, cpu;
196 Standard_Integer min, hour;
197
198 gTimer.Show ( sec, min, hour, cpu );
199 cout << "DisplayMode : " << theMode << endl;
200 cout << "Compute : " << sec << " sec" << endl;
201 cout << "Compute CPU : " << cpu << " sec" << endl << endl;
202 gTimer.Stop();
203 }
204}
205
206//================================================================
207// Function : ComputeSelection
208// Purpose :
209//================================================================
210void MeshVS_Mesh::ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
211 const Standard_Integer theMode )
212{
213 OSD_Timer gTimer;
214
215 Standard_Boolean ShowComputeSelectionTime = Standard_True;
216 myCurrentDrawer->GetBoolean( MeshVS_DA_ComputeSelectionTime, ShowComputeSelectionTime );
217
218 if ( ShowComputeSelectionTime )
219 {
220 gTimer.Reset();
221 gTimer.Start();
222 }
223
224 Standard_Integer aMaxFaceNodes;
225 Handle( MeshVS_DataSource ) aSource = GetDataSource();
226
227 if ( aSource.IsNull() || myCurrentDrawer.IsNull() || !myCurrentDrawer->GetInteger
228 ( MeshVS_DA_MaxFaceNodes, aMaxFaceNodes ) || aMaxFaceNodes<=0 )
229 return;
230
231 MeshVS_Buffer aCoordsBuf (3*aMaxFaceNodes*sizeof(Standard_Real));
232 TColStd_Array1OfReal aCoords (aCoordsBuf, 1, 3*aMaxFaceNodes);
233 Standard_Integer NbNodes;
234
235 MeshVS_EntityType aType;
236 Standard_Address anAddr;
237 TColStd_MapIteratorOfPackedMapOfInteger anIter;
238 Standard_Real x, y, z;
239
240 Standard_Integer aMode = HasDisplayMode() ? DisplayMode() : DefaultDisplayMode();
241 if ( myHilighter.IsNull() || ( aMode & MeshVS_DMF_OCCMask ) == 0 )
242 return;
243 const TColStd_PackedMapOfInteger& anAllNodesMap = aSource->GetAllNodes();
244 const TColStd_PackedMapOfInteger& anAllElementsMap= aSource->GetAllElements();
245//agv Standard_Integer i;
246
247 // skt: advanced mesh selection
248 if( aSource->IsAdvancedSelectionEnabled() ) {
249 Handle(MeshVS_MeshOwner) anOwner;
250 // Get the owner if it is already created
251 MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt( GetOwnerMaps( Standard_False ) );
252 for( ; anIt.More(); anIt.Next() )
253 {
254 anOwner = Handle(MeshVS_MeshOwner)::DownCast( anIt.Value() );
255 // clear selected entities
256 if( !anOwner.IsNull() )
257 break;
258 }
259 if( anOwner.IsNull() )
260 // Create one owner for the whole mesh and for all selection modes
261 anOwner = new MeshVS_MeshOwner( this, aSource, 5 );
262 // Save the owner. It will be available via GetOwnerMaps method
263 if( !myMeshOwners.IsBound( 1 ) )
264 myMeshOwners.Bind( 1, anOwner );
265 // Create one sensitive entity. It should detect mesh entities correspondingly
266 // to selection mode
267 Handle(MeshVS_SensitiveMesh) aSensMesh = new MeshVS_SensitiveMesh( anOwner, theMode );
268 theSelection->Add ( aSensMesh );
269 }
270 else {
271 switch ( theMode )
272 {
273 case MeshVS_SMF_Node: // Nodes
274
275 myNodeOwners.Clear();
276
277 for ( anIter.Initialize( anAllNodesMap ); anIter.More(); anIter.Next() )
278 {
279 Standard_Integer aKey = anIter.Key();
280 if ( !myDataSource->GetGeom ( aKey, Standard_False, aCoords, NbNodes, aType ) )
281 continue;
282
283 anAddr = myDataSource->GetAddr ( aKey, Standard_False );
284
285 Handle (MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner
286 ( this, aKey, anAddr, aType, 5 );
287
288 myNodeOwners.Bind ( aKey, anOwner );
289
290 if ( IsSelectableNode( aKey ) )
291 {
292 x = aCoords(1);
293 y = aCoords(2);
294 z = aCoords(3);
295 Handle (Select3D_SensitivePoint) aPoint = new Select3D_SensitivePoint
296 ( anOwner, gp_Pnt (x, y, z) );
297 theSelection->Add ( aPoint );
298 }
299 else
300 theSelection->Add ( new MeshVS_DummySensitiveEntity ( anOwner ) );
301 }
302 break;
303
304 case MeshVS_SMF_Mesh:
305
306 if( myWholeMeshOwner.IsNull() )
307 myWholeMeshOwner = new SelectMgr_EntityOwner( this );
308
309 switch( mySelectionMethod )
310 {
311 case MeshVS_MSM_BOX:
312 {
eb1ebea4 313 Bnd_Box box;
7fd59977 314 TColStd_MapIteratorOfPackedMapOfInteger anIterN( anAllNodesMap );
7fd59977 315 for( ; anIterN.More(); anIterN.Next() )
eb1ebea4 316 {
eafb234b 317 if( myDataSource->GetGeom( anIterN.Key(), Standard_False, aCoords, NbNodes, aType ) ) {
eb1ebea4 318 box.Add (gp_Pnt (aCoords(1), aCoords(2), aCoords(3)));
eafb234b 319 }
eb1ebea4 320 }
321 if (!box.IsVoid())
322 theSelection->Add (new Select3D_SensitiveBox (myWholeMeshOwner, box));
7fd59977 323 }
324 break;
325
326 case MeshVS_MSM_NODES:
327 {
328 TColStd_MapIteratorOfPackedMapOfInteger anIterN( anAllNodesMap );
329 for( ; anIterN.More(); anIterN.Next() )
330 if( myDataSource->GetGeom( anIterN.Key(), Standard_False, aCoords, NbNodes, aType ) &&
331 !IsHiddenNode( anIterN.Key() ) )
332 theSelection->Add( new Select3D_SensitivePoint( myWholeMeshOwner, gp_Pnt ( aCoords(1), aCoords(2), aCoords(3) ) ) );
333 }
334 break;
335
336 case MeshVS_MSM_PRECISE:
337 {
338 Handle( Select3D_SensitiveEntity ) anEnt;
339 TColStd_MapIteratorOfPackedMapOfInteger anIterMV( anAllElementsMap );
340
341 TColStd_PackedMapOfInteger aSharedNodes;
342 for( ; anIterMV.More(); anIterMV.Next() )
343 {
344 Standard_Integer aKey = anIterMV.Key();
345
346 if( IsSelectableElem( aKey ) &&
347 myDataSource->GetGeomType( aKey, Standard_True, aType ) &&
348 aType==MeshVS_ET_Face )
349 {
350 myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType );
351 if( NbNodes==0 )
352 continue;
353
354 MeshVS_Buffer aNodesBuf (NbNodes*sizeof(Standard_Integer));
355 TColStd_Array1OfInteger aElemNodes(aNodesBuf, 1, NbNodes);
356 if ( !myDataSource->GetNodesByElement ( aKey, aElemNodes, NbNodes ) )
357 continue;
358
359 TColgp_Array1OfPnt Points( 1, NbNodes );
360 for ( Standard_Integer i=1; i<=NbNodes; i++ )
361 {
362 Points (i) = gp_Pnt ( aCoords (3*i-2), aCoords (3*i-1), aCoords (3*i) );
363 aSharedNodes.Add( aElemNodes( i ) );
364 }
365
366 anEnt = new Select3D_SensitiveFace( myWholeMeshOwner, Points );
367 theSelection->Add( anEnt );
368 }
369 }
370 for( anIterMV.Initialize( anAllElementsMap ); anIterMV.More(); anIterMV.Next() )
371 {
372 Standard_Integer aKey = anIterMV.Key();
373
374 if( IsSelectableElem( aKey ) &&
375 myDataSource->GetGeomType( aKey, Standard_True, aType ) &&
376 aType==MeshVS_ET_Link )
377 {
378 myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType );
379 if( NbNodes==0 )
380 continue;
381
382 MeshVS_Buffer aNodesBuf (NbNodes*sizeof(Standard_Integer));
383 TColStd_Array1OfInteger aElemNodes(aNodesBuf, 1, NbNodes);
384 if ( !myDataSource->GetNodesByElement ( aKey, aElemNodes, NbNodes ) )
385 continue;
386
387 TColgp_Array1OfPnt Points( 1, NbNodes );
388 Standard_Boolean all_shared = Standard_True;
389 for ( Standard_Integer i=1; i<=NbNodes; i++ )
390 {
391 Points (i) = gp_Pnt ( aCoords (3*i-2), aCoords (3*i-1), aCoords (3*i) );
392 all_shared = all_shared && aSharedNodes.Contains( aElemNodes( i ) );
393 aSharedNodes.Add( aElemNodes( i ) );
394 }
395
396 if( !all_shared )
397 {
398 anEnt = new Select3D_SensitiveSegment( myWholeMeshOwner, Points.Value( 1 ), Points.Value( 2 ) );
399 theSelection->Add( anEnt );
400 }
401 }
402 }
403 for( anIterMV.Initialize( anAllNodesMap ); anIterMV.More(); anIterMV.Next() )
404 {
405 Standard_Integer aKey = anIterMV.Key();
406 if( IsSelectableElem( aKey ) &&
407 myDataSource->GetGeom ( aKey, Standard_False, aCoords, NbNodes, aType ) &&
408 !aSharedNodes.Contains( aKey ) )
409 {
410 anEnt = new Select3D_SensitivePoint( myWholeMeshOwner, gp_Pnt ( aCoords(1), aCoords(2), aCoords(3) ) ) ;
411 theSelection->Add( anEnt );
412 }
413 }
414 }
415 break;
416 }
417 break;
418
419 case MeshVS_SMF_Group:
420 {
421 myGroupOwners.Clear();
422
423 TColStd_PackedMapOfInteger anAllGroupsMap;
424 aSource->GetAllGroups( anAllGroupsMap );
425
426 Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo;
427
428 for ( anIter.Initialize( anAllGroupsMap ); anIter.More(); anIter.Next() )
429 {
430 Standard_Integer aKeyGroup = anIter.Key();
431
432 MeshVS_EntityType aGroupType;
433 TColStd_PackedMapOfInteger aGroupMap;
434 if ( !myDataSource->GetGroup( aKeyGroup, aGroupType, aGroupMap ) )
435 continue;
436
437 anAddr = myDataSource->GetGroupAddr ( aKeyGroup );
438 Standard_Integer aPrior = 0;
439
440 if( aGroupType == MeshVS_ET_Volume )
441 aPrior = 1;
442 if ( aGroupType == MeshVS_ET_Face )
443 aPrior = 2;
444 else if ( aGroupType == MeshVS_ET_Link )
445 aPrior = 3;
446 else if ( aGroupType == MeshVS_ET_0D )
447 aPrior = 4;
448 else if ( aGroupType == MeshVS_ET_Node )
449 aPrior = 5;
450
451 Handle (MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner
452 ( this, aKeyGroup, anAddr, aGroupType, aPrior, Standard_True );
453
454 myGroupOwners.Bind( aKeyGroup, anOwner );
455
456 Standard_Boolean added = Standard_False;
457 for ( TColStd_MapIteratorOfPackedMapOfInteger anIterMG (aGroupMap);
458 anIterMG.More(); anIterMG.Next() )
459 {
460 Standard_Integer aKey = anIterMG.Key();
461 if ( aGroupType == MeshVS_ET_Node ) {
462 if( myDataSource->GetGeom( aKey, Standard_False, aCoords, NbNodes, aType ) &&
463 IsSelectableNode/*!IsHiddenNode*/( aKey ) ) {
464 theSelection->Add( new Select3D_SensitivePoint( anOwner, gp_Pnt ( aCoords(1), aCoords(2), aCoords(3) ) ) );
465 added = Standard_True;
466 }
467 }
468 else if ( myDataSource->GetGeomType ( aKey, Standard_True, aType ) &&
469 IsSelectableElem/*!IsHiddenElem*/( aKey ) ) {
470 myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType );
471
472 TColgp_Array1OfPnt anArr( 1, NbNodes );
473 for ( Standard_Integer i=1; i<=NbNodes; i++ )
474 {
475 x = aCoords(3*i-2);
476 y = aCoords(3*i-1);
477 z = aCoords(3*i);
478 anArr.SetValue ( i, gp_Pnt ( x, y, z ) );
479 }
480
481 if ( aType == MeshVS_ET_Face && NbNodes > 0 ) // Faces: 2D-elements
482 {
483 Handle (MeshVS_SensitiveFace) aFace =
484 new MeshVS_SensitiveFace( anOwner, anArr );
485 theSelection->Add ( aFace );
486 added = Standard_True;
487 }
488 else if ( aType == MeshVS_ET_Link && NbNodes > 0 ) // Links: 1D-elements
489 {
490 Handle (MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment
491 ( anOwner, anArr(1), anArr(2) );
492 theSelection->Add ( aSeg );
493 added = Standard_True;
494 }
495 else if( aType == MeshVS_ET_Volume && aSource->Get3DGeom( aKey, NbNodes, aTopo ) )
496 {
497 Handle( MeshVS_SensitivePolyhedron ) aPolyhedron =
498 new MeshVS_SensitivePolyhedron( anOwner, anArr, aTopo );
499 theSelection->Add( aPolyhedron );
500 added = Standard_True;
501 }
502 else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!!
503 {
504 Handle (SelectBasics_SensitiveEntity) anEnt =
505 myHilighter->CustomSensitiveEntity ( anOwner, aKey );
506 if (!anEnt.IsNull()) {
507 theSelection->Add ( anEnt );
508 added = Standard_True;
509 }
510 }
511 }
512 }
513 if ( !added )
514 theSelection->Add ( new MeshVS_DummySensitiveEntity ( anOwner ) );
515 }
516 }
517 break;
518
519 default: // all residuary modes
520 {
521 Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo;
522
523 myElementOwners.Clear();
524
525 MeshVS_DataMapOfIntegerOwner* CurMap = &my0DOwners;
526 if ( theMode == MeshVS_ET_Link )
527 CurMap = &myLinkOwners;
528 else if ( theMode == MeshVS_ET_Face )
529 CurMap = &myFaceOwners;
530 else if ( theMode == MeshVS_ET_Volume )
531 CurMap = &myVolumeOwners;
532
533 CurMap->Clear();
534
535 for (TColStd_MapIteratorOfPackedMapOfInteger anIterMV (anAllElementsMap);
536 anIterMV.More(); anIterMV.Next() )
537 {
538 Standard_Integer aKey = anIterMV.Key();
539
540 if ( myDataSource->GetGeomType ( aKey, Standard_True, aType ) && theMode == aType )
541 {
542 myDataSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType );
543 anAddr = myDataSource->GetAddr ( aKey, Standard_True );
544
545 Standard_Integer aPrior = 0;
546
547 if( aType == MeshVS_ET_Volume )
548 aPrior = 1;
549 if ( aType == MeshVS_ET_Face )
550 aPrior = 2;
551 else if ( aType == MeshVS_ET_Link )
552 aPrior = 3;
553 else if ( aType == MeshVS_ET_0D )
554 aPrior = 4;
555
556 Handle (MeshVS_MeshEntityOwner) anOwner = new MeshVS_MeshEntityOwner
557 ( this, aKey, anAddr, aType, aPrior );
558
559 CurMap->Bind ( aKey, anOwner );
560
561 if ( IsSelectableElem( aKey ) ) //The element is selectable
562 {
563 TColgp_Array1OfPnt anArr( 1, NbNodes );
564 for ( Standard_Integer i=1; i<=NbNodes; i++ )
565 {
566 x = aCoords(3*i-2);
567 y = aCoords(3*i-1);
568 z = aCoords(3*i);
569 anArr.SetValue ( i, gp_Pnt ( x, y, z ) );
570 }
571
572 if ( aType == MeshVS_ET_Face && NbNodes > 0 ) // Faces: 2D-elements
573 {
574 Handle (MeshVS_SensitiveFace) aFace =
575 new MeshVS_SensitiveFace( anOwner, anArr );
576 theSelection->Add ( aFace );
577 }
578 else if ( aType == MeshVS_ET_Link && NbNodes > 0 ) // Links: 1D-elements
579 {
580 Handle (MeshVS_SensitiveSegment) aSeg = new MeshVS_SensitiveSegment
581 ( anOwner, anArr(1), anArr(2) );
582 theSelection->Add ( aSeg );
583 }
584 else if( aType == MeshVS_ET_Volume && aSource->Get3DGeom( aKey, NbNodes, aTopo ) )
585 {
586 Handle( MeshVS_SensitivePolyhedron ) aPolyhedron =
587 new MeshVS_SensitivePolyhedron( anOwner, anArr, aTopo );
588 theSelection->Add( aPolyhedron );
589 }
590 else //if ( aType == MeshVS_ET_0D ) // Custom : not only 0D-elements !!!
591 {
592 Handle (SelectBasics_SensitiveEntity) anEnt =
593 myHilighter->CustomSensitiveEntity ( anOwner, aKey );
594 if (!anEnt.IsNull())
595 theSelection->Add ( anEnt );
596 }
597 }
598 else
599 theSelection->Add ( new MeshVS_DummySensitiveEntity ( anOwner ) );
600 }
601 }
602 }
603 break;
604 }
605 }
606
607 if ( ShowComputeSelectionTime )
608 {
609 Standard_Real sec, cpu;
610 Standard_Integer min, hour;
611
612 gTimer.Show ( sec, min, hour, cpu );
613 cout << "SelectionMode : " << theMode << endl;
614 cout << "Compute selection: " << sec << " sec" << endl;
615 cout << "Compute selection CPU : " << cpu << " sec" << endl << endl;
616 gTimer.Stop();
617 }
618}
619
620//================================================================
621// Function : GetBuildersCount
622// Purpose :
623//================================================================
624Standard_Integer MeshVS_Mesh::GetBuildersCount () const
625{
626 return myBuilders.Length();
627}
628
629//================================================================
630// Function : GetFreeId
631// Purpose :
632//================================================================
633Standard_Integer MeshVS_Mesh::GetFreeId () const
634{
635 TColStd_PackedMapOfInteger Ids;
636 Standard_Integer i, len = myBuilders.Length(), curId;
637
638 for ( i=1; i<=len; i++ )
639 Ids.Add( myBuilders.Value(i)->GetId () );
640
641 curId = 0;
642 while ( Ids.Contains( curId ) )
643 curId++;
644
645 return curId;
646}
647
648//================================================================
649// Function : GetBuilder
650// Purpose :
651//================================================================
652Handle (MeshVS_PrsBuilder) MeshVS_Mesh::GetBuilder ( const Standard_Integer Index ) const
653{
654 if ( Index>=1 && Index<=myBuilders.Length() )
655 return myBuilders.Value( Index );
656 else
657 return 0;
658}
659
660//================================================================
661// Function : GetBuilderById
662// Purpose :
663//================================================================
664Handle (MeshVS_PrsBuilder) MeshVS_Mesh::GetBuilderById ( const Standard_Integer Id ) const
665{
666 Handle (MeshVS_PrsBuilder) Result;
667
668 Standard_Integer i, len = myBuilders.Length();
669 for ( i=1; i<=len; i++ )
670 if ( myBuilders.Value(i)->GetId () == Id )
671 {
672 Result = myBuilders.Value(i);
673 break;
674 }
675 return Result;
676}
677
678//================================================================
679// Function : AddBuilder
680// Purpose :
681//================================================================
682void MeshVS_Mesh::AddBuilder ( const Handle (MeshVS_PrsBuilder)& theBuilder,
683 const Standard_Boolean TreatAsHilighter )
684{
685 if ( theBuilder.IsNull() )
686 return;
687
688 Standard_Integer i, n = myBuilders.Length();
689 for ( i = 1; i<=n; i++ )
690 if ( myBuilders(i)->GetPriority() < theBuilder->GetPriority() )
691 break;
692
693 if ( i>n )
694 myBuilders.Append ( theBuilder );
695 else
696 myBuilders.InsertBefore ( i, theBuilder );
697
698 if( TreatAsHilighter )
699 myHilighter = theBuilder;
700}
701
702//================================================================
703// Function : RemoveBuilder
704// Purpose :
705//================================================================
706void MeshVS_Mesh::RemoveBuilder ( const Standard_Integer theIndex )
707{
708 Handle( MeshVS_PrsBuilder ) aBuild = GetBuilder( theIndex );
709 if ( !aBuild.IsNull() )
710 {
711 if ( aBuild == myHilighter )
712 myHilighter.Nullify();
713 myBuilders.Remove ( theIndex );
714 }
715}
716
717//================================================================
718// Function : RemoveBuilderById
719// Purpose :
720//================================================================
721void MeshVS_Mesh::RemoveBuilderById ( const Standard_Integer Id )
722{
723 Standard_Integer i, n = myBuilders.Length();
724 for ( i=1; i<=n; i++ )
725 {
726 Handle( MeshVS_PrsBuilder ) aCur = myBuilders(i);
727 if ( !aCur.IsNull() && aCur->GetId()==Id )
728 break;
729 }
730 if ( i>=1 && i<=n )
731 {
732 if ( GetBuilder( i )==myHilighter )
733 myHilighter.Nullify();
734 RemoveBuilder ( i );
735 }
736}
737
738//================================================================
739// Function : SetHiddenElems
740// Purpose :
741//================================================================
742void MeshVS_Mesh::SetHiddenElems ( const Handle(TColStd_HPackedMapOfInteger)& theMap )
743{
744 myHiddenElements = theMap;
745
746 // Note: update of list of selectable nodes -- this is not optimal!
747 Standard_Boolean AutoSelUpdate = Standard_False;
748 if ( !GetDrawer().IsNull() && GetDrawer()->GetBoolean( MeshVS_DA_SelectableAuto, AutoSelUpdate ) &&
749 AutoSelUpdate )
750 UpdateSelectableNodes();
751}
752
753//================================================================
754// Function : SetHiddenNodes
755// Purpose :
756//================================================================
757void MeshVS_Mesh::SetHiddenNodes ( const Handle(TColStd_HPackedMapOfInteger)& theMap )
758{
759 myHiddenNodes = theMap;
760
761 // Note: update of list of selectable nodes -- this is not optimal!
762 Standard_Boolean AutoSelUpdate = Standard_False;
763 if ( !GetDrawer().IsNull() && GetDrawer()->GetBoolean( MeshVS_DA_SelectableAuto, AutoSelUpdate ) &&
764 AutoSelUpdate )
765 UpdateSelectableNodes();
766}
767
768//================================================================
769// Function : GetHiddenElems
770// Purpose :
771//================================================================
772const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetHiddenElems () const
773{
774 return myHiddenElements;
775}
776
777//================================================================
778// Function : GetHiddenNodes
779// Purpose :
780//================================================================
781const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetHiddenNodes () const
782{
783 return myHiddenNodes;
784}
785
786//================================================================
787// Function : AddToMap
788// Purpose :
789//================================================================
790void AddToMap ( MeshVS_DataMapOfIntegerOwner& Result, const MeshVS_DataMapOfIntegerOwner& Addition )
791{
792 MeshVS_DataMapIteratorOfDataMapOfIntegerOwner anIt ( Addition );
793 for ( ; anIt.More(); anIt.Next() )
794 if ( Result.IsBound ( anIt.Key() ) )
795 Result.ChangeFind ( anIt.Key() ) = anIt.Value();
796 else
797 Result.Bind( anIt.Key(), anIt.Value() );
798}
799
800//================================================================
801// Function : GetOwnerMaps
802// Purpose :
803//================================================================
804const MeshVS_DataMapOfIntegerOwner& MeshVS_Mesh::GetOwnerMaps ( const Standard_Boolean IsElements )
805{
806 Handle(MeshVS_DataSource) aDS = GetDataSource();
807 if( !aDS.IsNull() && aDS->IsAdvancedSelectionEnabled() )
808 return myMeshOwners;
809 if ( IsElements )
810 {
811 if ( myElementOwners.IsEmpty() )
812 {
813 AddToMap ( myElementOwners, my0DOwners );
814 AddToMap ( myElementOwners, myLinkOwners );
815 AddToMap ( myElementOwners, myFaceOwners );
816 AddToMap ( myElementOwners, myVolumeOwners );
817 }
818 return myElementOwners;
819 }
820 else
821 return myNodeOwners;
822}
823
824//================================================================
825// Function : IsHiddenElem
826// Purpose :
827//================================================================
828Standard_Boolean MeshVS_Mesh::IsHiddenElem ( const Standard_Integer theID ) const
829{
830 return ! myHiddenElements.IsNull() && myHiddenElements->Map().Contains( theID );
831}
832
833//================================================================
834// Function : IsHiddenNode
835// Purpose :
836//================================================================
837Standard_Boolean MeshVS_Mesh::IsHiddenNode ( const Standard_Integer theID ) const
838{
839 // note that by default all nodes are hidden
840 return myHiddenNodes.IsNull() || myHiddenNodes->Map().Contains( theID );
841}
842
843//================================================================
844// Function : GetDrawer
845// Purpose :
846//================================================================
847Handle( MeshVS_Drawer ) MeshVS_Mesh::GetDrawer() const
848{
849 return myCurrentDrawer;
850}
851
852//================================================================
853// Function : SetDrawer
854// Purpose :
855//================================================================
856void MeshVS_Mesh::SetDrawer(const Handle(MeshVS_Drawer)& aDrawer)
857{
858 myCurrentDrawer = aDrawer;
859}
860
861//================================================================
862// Function : GetDataSource
863// Purpose :
864//================================================================
865Handle(MeshVS_DataSource) MeshVS_Mesh::GetDataSource() const
866{
867 return myDataSource;
868}
869
870//================================================================
871// Function : SetDataSource
872// Purpose :
873//================================================================
874void MeshVS_Mesh::SetDataSource( const Handle(MeshVS_DataSource)& theDataSource )
875{
876 myDataSource = theDataSource;
877}
878
879//================================================================
880// Function : HilightSelected
881// Purpose :
882//================================================================
883void MeshVS_Mesh::HilightSelected ( const Handle(PrsMgr_PresentationManager3d)& thePM,
884 const SelectMgr_SequenceOfOwner& theOwners )
885{
886 if ( myHilighter.IsNull() )
887 return;
888
889// if ( mySelectionPrs.IsNull() )
890// mySelectionPrs = new Prs3d_Presentation ( thePM->StructureManager() );
891
892 //new functionality
893
894 Handle( Prs3d_Presentation ) aSelectionPrs;
895
896 aSelectionPrs = GetSelectPresentation( thePM );
897
898 if( HasPresentation() )
899 aSelectionPrs->SetTransformPersistence( Presentation()->TransformPersistenceMode(), Presentation()->TransformPersistencePoint() );
900 //----------------
901
902 // It is very important to call this parent method, because it check whether
903 // mySelectionPrs is created and if not, create it.
904
905#ifdef _DEBUG
906 OSD_Timer gTimer;
907 gTimer.Reset();
908 gTimer.Start();
909#endif
910
911 Standard_Integer len = theOwners.Length(), i;
912
913 Handle (MeshVS_MeshEntityOwner) anOwner;
914 TColStd_PackedMapOfInteger aSelNodes, aSelElements;
915
916 for( i=1; i<=len; i++ )
917 {
918 anOwner = Handle (MeshVS_MeshEntityOwner)::DownCast ( theOwners.Value ( i ) );
919 if ( !anOwner.IsNull() )
920 {
921 // nkv: add support of mesh groups
922 if ( anOwner->IsGroup() ) {
923 MeshVS_EntityType aGroupType;
924 TColStd_PackedMapOfInteger aGroupMap;
925 if ( GetDataSource()->GetGroup( anOwner->ID(), aGroupType, aGroupMap ) ) {
926 if ( aGroupType == MeshVS_ET_Node ) {
927 for( TColStd_MapIteratorOfPackedMapOfInteger anIt(aGroupMap); anIt.More(); anIt.Next() )
928 if( IsSelectableNode/*!IsHiddenNode*/( anIt.Key() ) )
929 aSelNodes.Add( anIt.Key() );
930 }
931 else {
932 for( TColStd_MapIteratorOfPackedMapOfInteger anIt(aGroupMap); anIt.More(); anIt.Next() )
933 if( IsSelectableElem/*!IsHiddenElem*/( anIt.Key() ) )
934 aSelElements.Add( anIt.Key() );
935 }
936 }
937 }
938 else {
939 if( anOwner->Type() == MeshVS_ET_Node )
940 aSelNodes.Add( anOwner->ID() );
941 else
942 aSelElements.Add( anOwner->ID() );
943 }
944 }
945 else if( GetDataSource()->IsAdvancedSelectionEnabled() )
946 {
947 Handle(MeshVS_MeshOwner) aMeshOwner = Handle(MeshVS_MeshOwner)::DownCast ( theOwners.Value ( i ) );
948 if( !aMeshOwner.IsNull() )
949 {
950 Handle(TColStd_HPackedMapOfInteger) aNodes = aMeshOwner->GetSelectedNodes();
951 Handle(TColStd_HPackedMapOfInteger) aElems = aMeshOwner->GetSelectedElements();
952 if( !aNodes.IsNull() )
953 aSelNodes.Assign( aNodes->Map() );
954 if( !aElems.IsNull() )
955 aSelElements.Assign( aElems->Map() );
956 }
957 }
958//agv else if( theOwners.Value ( i )==myWholeMeshOwner )
959 else if (IsWholeMeshOwner (theOwners.Value ( i )))
960 {
961 TColStd_MapIteratorOfPackedMapOfInteger anIt(GetDataSource()->GetAllNodes());
962 for( ; anIt.More(); anIt.Next() )
963 if( !IsHiddenNode( anIt.Key() ) )
964 aSelNodes.Add( anIt.Key() );
965
966 anIt = TColStd_MapIteratorOfPackedMapOfInteger( GetDataSource()->GetAllElements() );
967 for( ; anIt.More(); anIt.Next() )
968 if( !IsHiddenElem( anIt.Key() ) )
969 aSelElements.Add( anIt.Key() );
970
971 break;
972 }
973 }
974
975 Standard_Boolean IsNeedToRedisplay = Standard_False;
976
977 aSelectionPrs->Clear();
978
979 myHilighter->SetDrawer ( mySelectionDrawer );
980
981 if( aSelNodes.Extent()>0 )
982 {
983 TColStd_PackedMapOfInteger tmp;
984 myHilighter->Build ( aSelectionPrs, aSelNodes, tmp, Standard_False, MeshVS_DMF_SelectionPrs );
985 }
986 if( aSelElements.Extent()>0 )
987 {
988 TColStd_PackedMapOfInteger tmp;
989 myHilighter->Build( aSelectionPrs, aSelElements, tmp, Standard_True, MeshVS_DMF_SelectionPrs );
990 }
991
992 myHilighter->SetDrawer ( 0 );
993
994 IsNeedToRedisplay = Standard_True;
995
996 if ( IsNeedToRedisplay )
997 {
998 aSelectionPrs->SetDisplayPriority(9);
999 aSelectionPrs->Display();
1000 }
1001
1002#ifdef _DEBUG
1003 Standard_Real sec, cpu;
1004 Standard_Integer min, hour;
1005
1006 gTimer.Show ( sec, min, hour, cpu );
1007 cout << "HilightSelected : " << endl;
1008 cout << aSelNodes.Extent() << " nodes " << endl;
1009 cout << aSelElements.Extent() << " elements " << endl;
1010 cout << "Time : " << sec << " sec" << endl;
1011 cout << "CPU time : " << cpu << " sec" << endl << endl;
1012 gTimer.Stop();
1013#endif
1014}
1015
1016//================================================================
1017// Function : HilightOwnerWithColor
1018// Purpose :
1019//================================================================
1020void MeshVS_Mesh::HilightOwnerWithColor ( const Handle(PrsMgr_PresentationManager3d)& PM,
1021 const Quantity_NameOfColor Color,
1022 const Handle(SelectMgr_EntityOwner)& Owner)
1023{
1024 if ( myHilighter.IsNull() )
1025 return;
1026
1027 SelectMgr_SequenceOfOwner theOwners;
1028 //new functionality
1029
1030 //if ( myHilightPrs.IsNull() )
1031 // myHilightPrs = new Prs3d_Presentation ( PM->StructureManager() );
1032
1033 Handle( Prs3d_Presentation ) aHilightPrs;
1034 aHilightPrs = GetHilightPresentation( PM );
1035
1036 aHilightPrs->Clear();
1037
1038 //new functionality
1039 if( HasPresentation() )
1040 aHilightPrs->SetTransformPersistence( Presentation()->TransformPersistenceMode(), Presentation()->TransformPersistencePoint() );
1041 //----------------
1042
1043 if( Owner.IsNull() ) return;
1044
1045 const Standard_Boolean isMeshEntityOwner = Owner->IsKind ( STANDARD_TYPE ( MeshVS_MeshEntityOwner ) );
1046 const Standard_Boolean isWholeMeshOwner =
1047//agv !Owner.IsNull() && Owner==myWholeMeshOwner;
1048 IsWholeMeshOwner (Owner);
1049
1050 Standard_Integer aDispMode = MeshVS_DMF_Shading;
1051 if ( HasDisplayMode() && ( DisplayMode() & MeshVS_DMF_OCCMask ) > MeshVS_DMF_WireFrame )
1052 aDispMode = ( DisplayMode() & MeshVS_DMF_OCCMask );
1053 //It because we draw hilighted owners only in shading or shrink (not in wireframe)
1054
1055 myHilightDrawer->SetColor( MeshVS_DA_InteriorColor, Color );
1056 myHilightDrawer->SetColor( MeshVS_DA_BackInteriorColor, Color );
1057 myHilightDrawer->SetColor( MeshVS_DA_EdgeColor, Color );
1058 myHilightDrawer->SetColor( MeshVS_DA_BeamColor, Color );
1059 myHilightDrawer->SetColor( MeshVS_DA_MarkerColor, Color );
1060 myHilighter->SetDrawer( myHilightDrawer );
1061
1062 if( isMeshEntityOwner )
1063 {
1064 Handle ( MeshVS_MeshEntityOwner ) theAISOwner = Handle ( MeshVS_MeshEntityOwner )::DownCast ( Owner );
1065 MeshVS_EntityType aType = theAISOwner->Type();
1066 Standard_Integer anID = theAISOwner->ID();
1067
1068 if ( theAISOwner->IsGroup() ) {
1069 MeshVS_EntityType aGroupType;
1070 TColStd_PackedMapOfInteger aGroupMap;
1071 if ( myDataSource->GetGroup( anID, aGroupType, aGroupMap ) ) {
1072 TColStd_PackedMapOfInteger tmp;
1073 myHilighter->Build( aHilightPrs, aGroupMap, tmp, aType!=MeshVS_ET_Node,
1074 aDispMode | MeshVS_DMF_HilightPrs );
1075 }
1076 }
1077 else {
1078 TColStd_PackedMapOfInteger anOne, tmp;
1079 anOne.Add (anID);
1080 myHilighter->Build( aHilightPrs, anOne, tmp, aType!=MeshVS_ET_Node,
1081 aDispMode | MeshVS_DMF_HilightPrs );
1082 }
1083 }
1084 else if( isWholeMeshOwner )
1085 {
1086 if( ! GetDataSource().IsNull() )
1087 {
1088 TColStd_PackedMapOfInteger tmp;
1089 myHilighter->Build( aHilightPrs, GetDataSource()->GetAllElements(), tmp,
1090 Standard_True, MeshVS_DMF_WireFrame );
1091 }
1092 }
1093 else
1094 {
1095 Handle(MeshVS_MeshOwner) aMeshOwner = Handle(MeshVS_MeshOwner)::DownCast ( Owner );
1096 if( !aMeshOwner.IsNull() )
1097 {
1098 Handle(TColStd_HPackedMapOfInteger) aNodes = aMeshOwner->GetDetectedNodes();
1099 Handle(TColStd_HPackedMapOfInteger) aElems = aMeshOwner->GetDetectedElements();
1100 // hilight detected entities
1101 if( !aNodes.IsNull() )
1102 {
1103 TColStd_PackedMapOfInteger tmp;
1104 myHilighter->Build( aHilightPrs, aNodes->Map(), tmp, Standard_False,
1105 aDispMode | MeshVS_DMF_HilightPrs );
1106 }
1107 if( !aElems.IsNull() )
1108 {
1109 TColStd_PackedMapOfInteger tmp;
1110 myHilighter->Build( aHilightPrs, aElems->Map(), tmp, Standard_True,
1111 aDispMode | MeshVS_DMF_HilightPrs );
1112 }
1113 }
1114 }
1115
679ecdee 1116 if (PM->IsImmediateModeOn())
1117 {
1118 PM->AddToImmediateList (aHilightPrs);
1119 }
7fd59977 1120 myHilighter->SetDrawer ( 0 );
1121}
1122
1123//=======================================================================
1124//function : ClearSelected
1125//purpose :
1126//=======================================================================
1127void MeshVS_Mesh::ClearSelected ()
1128{
1129 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL );
1130 if( !aSelectionPrs.IsNull() )
1131 aSelectionPrs->Clear();
1132}
1133
1134//=======================================================================
1135//function : FindBuilder
1136//purpose :
1137//=======================================================================
1138Handle (MeshVS_PrsBuilder) MeshVS_Mesh::FindBuilder ( const Standard_CString theTypeName ) const
1139{
1140 Standard_Integer len = myBuilders.Length();
1141 Handle(MeshVS_PrsBuilder) aBuilder;
1142 Standard_Boolean IsExist = Standard_False;
1143
1144 for ( Standard_Integer i=1; i<=len && !IsExist; i++)
1145 if ( myBuilders.Value (i)->IsKind ( theTypeName ) )
1146 {
1147 aBuilder = myBuilders.Value (i);
1148 IsExist = Standard_True;
1149 }
1150
1151 return aBuilder;
1152}
1153
1154//=======================================================================
1155//function : SetHilighter
1156//purpose :
1157//=======================================================================
1158void MeshVS_Mesh::SetHilighter ( const Handle( MeshVS_PrsBuilder )& Builder )
1159{
1160 myHilighter = Builder;
1161}
1162
1163//=======================================================================
1164//function : SetHilighter
1165//purpose :
1166//=======================================================================
1167Standard_Boolean MeshVS_Mesh::SetHilighter ( const Standard_Integer Index )
1168{
1169 Handle( MeshVS_PrsBuilder ) aBuild = GetBuilder( Index );
1170 Standard_Boolean aRes = ( !aBuild.IsNull() );
1171 if ( aRes )
1172 myHilighter = aBuild;
1173 return aRes;
1174}
1175
1176//=======================================================================
1177//function : SetHilighter
1178//purpose :
1179//=======================================================================
1180Standard_Boolean MeshVS_Mesh::SetHilighterById ( const Standard_Integer Id )
1181{
1182 Handle( MeshVS_PrsBuilder ) aBuild = GetBuilderById( Id );
1183 Standard_Boolean aRes = ( !aBuild.IsNull() );
1184 if ( aRes )
1185 myHilighter = aBuild;
1186 return aRes;
1187}
1188
1189//=======================================================================
1190//function : GetHilighter
1191//purpose :
1192//=======================================================================
1193Handle( MeshVS_PrsBuilder ) MeshVS_Mesh::GetHilighter () const
1194{
1195 return myHilighter;
1196}
1197
1198//=======================================================================
1199//function : IsSelectableElem
1200//purpose :
1201//=======================================================================
1202Standard_Boolean MeshVS_Mesh::IsSelectableElem ( const Standard_Integer ID ) const
1203{
1204 return ! IsHiddenElem ( ID );
1205}
1206
1207//=======================================================================
1208//function : IsSelectableNode
1209//purpose :
1210//=======================================================================
1211Standard_Boolean MeshVS_Mesh::IsSelectableNode ( const Standard_Integer ID ) const
1212{
1213 return mySelectableNodes.IsNull() ? ! IsHiddenNode ( ID ) :
1214 mySelectableNodes->Map().Contains( ID );
1215}
1216
1217//=======================================================================
1218//function : GetSelectableNodes
1219//purpose :
1220//=======================================================================
1221const Handle(TColStd_HPackedMapOfInteger)& MeshVS_Mesh::GetSelectableNodes () const
1222{
1223 return mySelectableNodes;
1224}
1225
1226//=======================================================================
1227//function : SetSelectableNodes
1228//purpose :
1229//=======================================================================
1230void MeshVS_Mesh::SetSelectableNodes ( const Handle(TColStd_HPackedMapOfInteger)& Ids )
1231{
1232 mySelectableNodes = Ids;
1233}
1234
1235//=======================================================================
1236//function : UpdateSelectableNodes
1237//purpose :
1238//=======================================================================
1239void MeshVS_Mesh::UpdateSelectableNodes()
1240{
1241 mySelectableNodes = new TColStd_HPackedMapOfInteger;
1242
1243 Standard_Integer aMaxFaceNodes;
1244 Handle( MeshVS_DataSource ) aSource = GetDataSource();
1245 if ( aSource.IsNull() || myCurrentDrawer.IsNull() || !myCurrentDrawer->GetInteger
1246 ( MeshVS_DA_MaxFaceNodes, aMaxFaceNodes ) || aMaxFaceNodes<=0 )
1247 return;
1248
1249 // all non-hidden nodes are selectable;
1250 // by default (i.e. if myHiddenNodes.IsNull()) all nodes are hidden
1251 if ( ! myHiddenNodes.IsNull() )
1252 {
1253 mySelectableNodes->ChangeMap().Subtraction (aSource->GetAllNodes(),
1254 myHiddenNodes->Map());
1255 }
1256
1257 // add all nodes belonging to non-hidden elements
1258 TColStd_MapIteratorOfPackedMapOfInteger anIter( aSource->GetAllElements() );
1259 for ( ; anIter.More(); anIter.Next() )
1260 {
1261 Standard_Integer aKey = anIter.Key();
1262 if ( IsHiddenElem (aKey) )
1263 continue;
1264
1265 MeshVS_Buffer aNodesBuf (aMaxFaceNodes*sizeof(Standard_Integer));
1266 TColStd_Array1OfInteger aNodes (aNodesBuf, 1, aMaxFaceNodes);
1267 Standard_Integer NbNodes;
1268 if ( !aSource->GetNodesByElement ( aKey, aNodes, NbNodes ) )
1269 continue;
1270 for ( Standard_Integer i=1; i<=NbNodes; i++ )
1271 mySelectableNodes->ChangeMap().Add ( aNodes(i) );
1272 }
1273}
1274
1275//=======================================================================
1276//function : GetMeshSelMethod
1277//purpose :
1278//=======================================================================
1279MeshVS_MeshSelectionMethod MeshVS_Mesh::GetMeshSelMethod() const
1280{
1281 return mySelectionMethod;
1282}
1283
1284//=======================================================================
1285//function : SetMeshSelMethod
1286//purpose :
1287//=======================================================================
1288void MeshVS_Mesh::SetMeshSelMethod( const MeshVS_MeshSelectionMethod M )
1289{
1290 mySelectionMethod = M;
1291}
1292
1293//=======================================================================
1294//function : IsWholeMeshOwner
1295//purpose :
1296//=======================================================================
1297
1298Standard_Boolean MeshVS_Mesh::IsWholeMeshOwner
1299 (const Handle(SelectMgr_EntityOwner)& theOwn) const
1300{
1301 return theOwn.IsNull() ? Standard_False : (theOwn == myWholeMeshOwner);
1302}