0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / SelectMgr / SelectMgr_Selection.cxx
1 // Created on: 1995-02-16
2 // Created by: Mister rmi
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <SelectMgr_Selection.hxx>
18
19 #include <SelectMgr_EntityOwner.hxx>
20 #include <Standard_NullObject.hxx>
21
22 IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_Selection,Standard_Transient)
23
24 //==================================================
25 // Function: SelectMgr_Selection
26 // Purpose :
27 //==================================================
28 SelectMgr_Selection::SelectMgr_Selection (const Standard_Integer theModeIdx)
29 : myMode (theModeIdx),
30   mySelectionState (SelectMgr_SOS_Unknown),
31   myBVHUpdateStatus (SelectMgr_TBU_None),
32   mySensFactor (2),
33   myIsCustomSens (Standard_False)
34 {}
35
36 SelectMgr_Selection::~SelectMgr_Selection()
37 {
38   Destroy();
39 }
40
41 //==================================================
42 // Function: Destroy
43 // Purpose :
44 //==================================================
45 void SelectMgr_Selection::Destroy()
46 {
47   for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
48   {
49     Handle(SelectMgr_SensitiveEntity)& anEntity = anEntityIter.ChangeValue();
50     anEntity->BaseSensitive()->Set (NULL);
51   }
52   mySensFactor = 2;
53 }
54
55 //==================================================
56 // Function: ADD
57 // Purpose :
58 //==================================================
59 void SelectMgr_Selection::Add (const Handle(Select3D_SensitiveEntity)& theSensitive)
60 {
61   // if input is null: in debug mode raise exception
62   Standard_NullObject_Raise_if (theSensitive.IsNull(), "Null sensitive entity is added to the selection");
63   if (theSensitive.IsNull())
64   {
65     // in release mode do not add
66     return;
67   }
68
69   Handle(SelectMgr_SensitiveEntity) anEntity = new SelectMgr_SensitiveEntity (theSensitive);
70   myEntities.Append (anEntity);
71   if (mySelectionState == SelectMgr_SOS_Activated
72   && !anEntity->IsActiveForSelection())
73   {
74     anEntity->SetActiveForSelection();
75   }
76
77   if (myIsCustomSens)
78   {
79     anEntity->BaseSensitive()->SetSensitivityFactor (mySensFactor);
80   }
81   else
82   {
83     mySensFactor = Max (mySensFactor, anEntity->BaseSensitive()->SensitivityFactor());
84   }
85 }       
86
87 //==================================================
88 // Function: Clear
89 // Purpose :
90 //==================================================
91 void SelectMgr_Selection::Clear()
92 {
93   for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
94   {
95     Handle(SelectMgr_SensitiveEntity)& anEntity = anEntityIter.ChangeValue();
96     anEntity->Clear();
97   }
98
99   myEntities.Clear();
100 }
101
102 //==================================================
103 // function: SetSensitivity
104 // purpose : Changes sensitivity of the selection and all its entities to the given value.
105 //           IMPORTANT: This method does not update any outer selection structures, so for
106 //           proper updates use SelectMgr_SelectionManager::SetSelectionSensitivity method.
107 //==================================================
108 void SelectMgr_Selection::SetSensitivity (const Standard_Integer theNewSens)
109 {
110   mySensFactor = theNewSens;
111   myIsCustomSens = Standard_True;
112   for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
113   {
114     Handle(SelectMgr_SensitiveEntity)& anEntity = anEntityIter.ChangeValue();
115     anEntity->BaseSensitive()->SetSensitivityFactor (theNewSens);
116   }
117 }
118
119 // =======================================================================
120 // function : DumpJson
121 // purpose  :
122 // =======================================================================
123 void SelectMgr_Selection::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
124 {
125   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
126
127   NCollection_Map<Handle(SelectMgr_EntityOwner)> anOwners;
128   for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anIterator (myEntities); anIterator.More(); anIterator.Next())
129   {
130     const Handle(SelectMgr_SensitiveEntity)& anEntity = anIterator.Value();
131     if (anEntity.IsNull() || anEntity->BaseSensitive().IsNull())
132     {
133       continue;
134     }
135     const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->BaseSensitive()->OwnerId();
136     if (anOwners.Add (anOwner))
137     {
138       OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anOwner.get())
139     }
140   }
141
142   for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anIterator (myEntities); anIterator.More(); anIterator.Next())
143   {
144     const Handle(SelectMgr_SensitiveEntity)& anEntity = anIterator.Value();
145     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anEntity.get())
146   }
147
148   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMode)
149   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, mySelectionState)
150   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, mySensFactor)
151   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUpdateStatus)
152   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBVHUpdateStatus)
153   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsCustomSens)
154 }