summaryrefslogtreecommitdiff
path: root/src/NIS/NIS_InteractiveObject.cxx
blob: aec249098b202bbd0c8c1242d4548a45ed3c08f4 (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
// File:      NIS_InteractiveObject.cxx
// Created:   07.07.07 11:24
// Author:    Alexander GRIGORIEV
// Copyright: Open Cascade 2007


#include <NIS_InteractiveObject.hxx>
#include <NIS_InteractiveContext.hxx>
#include <Standard_NullValue.hxx>

IMPLEMENT_STANDARD_HANDLE  (NIS_InteractiveObject, Standard_Transient)
IMPLEMENT_STANDARD_RTTIEXT (NIS_InteractiveObject, Standard_Transient)

//=======================================================================
//function : ~NIS_InteractiveObject()
//purpose  : Destructor
//=======================================================================

NIS_InteractiveObject::~NIS_InteractiveObject (  )
{
  if (myID != 0 && myDrawer.IsNull() == Standard_False)
    myDrawer->removeObject( this, Standard_False);
}

//=======================================================================
//function : SetDrawer
//purpose  : 
//=======================================================================

const Handle_NIS_Drawer& NIS_InteractiveObject::SetDrawer
                                        (const Handle(NIS_Drawer)& theDrawer,
                                         const Standard_Boolean    setUpdated)
{
  NIS_InteractiveContext * aCtx = theDrawer->GetContext();
  if (myDrawer.IsNull() == Standard_False) {
    if (aCtx == 0L)
    {
      aCtx = myDrawer->GetContext();
      theDrawer->myCtx = aCtx;
    }
    else
    {
      Standard_NullValue_Raise_if
        (myDrawer->GetContext() != 0L && aCtx != myDrawer->GetContext(),
         "NIS_InteractiveObject::SetDrawer: different drawer context");
    }
  }

  Standard_NullValue_Raise_if
    (aCtx == 0L, "NIS_InteractiveObject::SetDrawer: NULL drawer context");
  // Add (if necessary) the new drawer to the Context
  if (theDrawer->myIniId == 0)
    theDrawer->myIniId = myID;
  const Handle(NIS_Drawer)& aDrawer = aCtx->myDrawers.Added (theDrawer);
  if (myDrawer != aDrawer)
  {
    // Move the Object from the old drawer to the new one.
    if (myDrawer.IsNull() == Standard_False)
      myDrawer->removeObject(this, Standard_True);
    myDrawer = aDrawer;

    myDrawer->addObject(this, aCtx->myIsShareDrawList, Standard_True);
  }
  if (setUpdated)
    myDrawer->SetUpdated (NIS_Drawer::Draw_Normal,
                          NIS_Drawer::Draw_Top,
                          NIS_Drawer::Draw_Transparent,
                          NIS_Drawer::Draw_Hilighted);
  return aDrawer;
}

//=======================================================================
//function : SetTransparency
//purpose  : 
//=======================================================================

void NIS_InteractiveObject::SetTransparency (const Standard_Real theValue)
{
  Standard_Integer aValue =
    static_cast<Standard_Integer> (theValue * MaxTransparency);
  if (aValue != static_cast<Standard_Integer>(myTransparency))
  {
    if (aValue <= 0)
      myTransparency = 0;
    else if (aValue >= 1000)
      myTransparency = 1000u;
    else
      myTransparency = static_cast<unsigned int> (aValue);

    if (myDrawer.IsNull() == Standard_False && myID != 0) {
      const Handle(NIS_Drawer) aDrawer = DefaultDrawer(0L);
      aDrawer->Assign (GetDrawer());
      aDrawer->myTransparency = Transparency();
      SetDrawer (aDrawer, Standard_False);

      NIS_InteractiveContext * aCtx = myDrawer->GetContext();
      Standard_NullValue_Raise_if
        (aCtx == 0L, "NIS_InteractiveObject::SetTransparency: "
                     "NULL drawer context");
      if (IsTransparent()) {
        if (myDrawType == NIS_Drawer::Draw_Normal) {
          aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Add(myID);
          aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Remove(myID);
          myDrawType = NIS_Drawer::Draw_Transparent;
        }
        myDrawer->SetUpdated (NIS_Drawer::Draw_Normal);
      } else {
        if (myDrawType == NIS_Drawer::Draw_Transparent) {
          aCtx->myMapObjects[NIS_Drawer::Draw_Normal].Add(myID);
          aCtx->myMapObjects[NIS_Drawer::Draw_Transparent].Remove(myID);
          myDrawType = NIS_Drawer::Draw_Normal;
        }
        myDrawer->SetUpdated (NIS_Drawer::Draw_Transparent);
      }
      setDrawerUpdate();
    }
  }
}

//=======================================================================
//function : GetBox
//purpose  : 
//=======================================================================

const Bnd_B3f& NIS_InteractiveObject::GetBox ()
{
  if (myIsUpdateBox)
  {
    myIsUpdateBox = Standard_False;
    computeBox();
  }
  return myBox;
}

//=======================================================================
//function : Clone
//purpose  : 
//=======================================================================

void NIS_InteractiveObject::Clone (const Handle_NCollection_BaseAllocator&,
                                   Handle_NIS_InteractiveObject& theDest) const
{
  if (theDest.IsNull() == Standard_False)
  {
    theDest->myID = 0;
    theDest->myDrawer = myDrawer;
    theDest->myDrawType = myDrawType;
    theDest->myBaseType = myBaseType;
    theDest->myIsHidden = myIsHidden;
    theDest->myIsDynHilighted = myIsDynHilighted;
    theDest->myIsUpdateBox = myIsUpdateBox;
    theDest->myTransparency = myTransparency;
    if (myIsUpdateBox == Standard_False)
      theDest->myBox = myBox;
    theDest->myAttributePtr = myAttributePtr;
  }
}

//=======================================================================
//function : CloneWithID
//purpose  : 
//=======================================================================

void NIS_InteractiveObject::CloneWithID
                        (const Handle_NCollection_BaseAllocator& theAlloc,
                         Handle_NIS_InteractiveObject&           theDest)
{
  Clone(theAlloc, theDest);
  theDest->myID = myID;
  myDrawer.Nullify();
}

//=======================================================================
//function : Intersect
//purpose  : 
//=======================================================================

Standard_Boolean NIS_InteractiveObject::Intersect (const Bnd_B3f&,
                                                   const gp_Trsf&,
                                                   const Standard_Boolean) const
{
  return Standard_True;
}

//=======================================================================
//function : Intersect
//purpose  : 
//=======================================================================

Standard_Boolean NIS_InteractiveObject::Intersect
                     (const NCollection_List<gp_XY> &thePolygon,
                      const gp_Trsf                 &theTrf,
                      const Standard_Boolean         isFull) const
{
  return Standard_True;
}

//=======================================================================
//function : IsSelectable
//purpose  : Query if the Object is selectable.
//=======================================================================

Standard_Boolean NIS_InteractiveObject::IsSelectable () const
{
  Standard_Boolean aResult(Standard_False);
  if (myDrawer.IsNull() == Standard_False)
    aResult = myDrawer->GetContext()->IsSelectable (myID);
  return aResult;
}

//=======================================================================
//function : SetSelectable
//purpose  : Set or change the selectable state of the Object.
//=======================================================================

void NIS_InteractiveObject::SetSelectable (const Standard_Boolean isSel) const
{
  if (myDrawer.IsNull() == Standard_False) {
    NIS_InteractiveContext * aCtx = myDrawer->GetContext();
    if (isSel)
      aCtx->myMapNonSelectableObjects.Remove (myID);
    else {
      aCtx->myMapNonSelectableObjects.Add (myID);
      if (myDrawType == NIS_Drawer::Draw_Hilighted)
      {
        aCtx->myMapObjects[NIS_Drawer::Draw_Hilighted].Remove(myID);
        aCtx->deselectObj (this, myID);
      }
    }
  }
}