0031458: Visualization - refine classes across Prs3d and StdPrs packages
[occt.git] / src / AIS / AIS_Point.cxx
1 // Created on: 1995-08-09
2 // Created by: Arnaud BOUZY/Odile Olivier
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 <AIS_Point.hxx>
18
19 #include <AIS_InteractiveContext.hxx>
20 #include <Aspect_TypeOfLine.hxx>
21 #include <BRepBuilderAPI_MakeVertex.hxx>
22 #include <Geom_Point.hxx>
23 #include <Graphic3d_ArrayOfPoints.hxx>
24 #include <Graphic3d_AspectMarker3d.hxx>
25 #include <Graphic3d_Group.hxx>
26 #include <Graphic3d_Structure.hxx>
27 #include <Prs3d_Drawer.hxx>
28 #include <Prs3d_PointAspect.hxx>
29 #include <Prs3d_Presentation.hxx>
30 #include <Quantity_Color.hxx>
31 #include <Select3D_SensitivePoint.hxx>
32 #include <SelectMgr_EntityOwner.hxx>
33 #include <Standard_Type.hxx>
34 #include <StdPrs_Point.hxx>
35 #include <TopoDS_Vertex.hxx>
36
37 IMPLEMENT_STANDARD_RTTIEXT(AIS_Point,AIS_InteractiveObject)
38
39 //=======================================================================
40 //function : AIS_Point
41 //purpose  : 
42 //=======================================================================
43 AIS_Point::AIS_Point(const Handle(Geom_Point)& aComponent):
44 myComponent(aComponent),
45 myHasTOM(Standard_False),
46 myTOM(Aspect_TOM_PLUS)
47 {
48   myHilightDrawer = new Prs3d_Drawer();
49   myHilightDrawer->SetDisplayMode (-99);
50   myHilightDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_GRAY80, 3.0));
51   myHilightDrawer->SetColor (Quantity_NOC_GRAY80);
52   myHilightDrawer->SetZLayer (Graphic3d_ZLayerId_UNKNOWN);
53   myDynHilightDrawer = new Prs3d_Drawer();
54   myDynHilightDrawer->SetDisplayMode (-99);
55   myDynHilightDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_CYAN1, 3.0));
56   myDynHilightDrawer->SetColor (Quantity_NOC_CYAN1);
57   myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Top);
58 }
59
60 //=======================================================================
61 //function : Component
62 //purpose  : 
63 //=======================================================================
64
65 Handle(Geom_Point) AIS_Point::Component()
66 {
67   return myComponent;
68 }
69
70 //=======================================================================
71 //function : SetComponent
72 //purpose  : 
73 //=======================================================================
74
75  void AIS_Point::SetComponent(const Handle(Geom_Point)& aComponent)
76 {
77   myComponent = aComponent;
78 }
79
80 //=======================================================================
81 //function : Compute
82 //purpose  : 
83 //=======================================================================
84 void AIS_Point::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
85                         const Handle(Prs3d_Presentation)& aPresentation, 
86                         const Standard_Integer aMode)
87 {
88   aPresentation->SetInfiniteState(myInfiniteState);
89
90   if (aMode==0)
91     StdPrs_Point::Add(aPresentation,myComponent,myDrawer);
92   else if (aMode== -99)
93     {
94       Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
95       TheGroup->SetPrimitivesAspect (myHilightDrawer->PointAspect()->Aspect());
96       Handle(Graphic3d_ArrayOfPoints) aPoint = new Graphic3d_ArrayOfPoints (1);
97       aPoint->AddVertex (myComponent->X(),myComponent->Y(),myComponent->Z());
98       TheGroup->AddPrimitiveArray (aPoint);
99     }
100     
101 }
102
103 //=======================================================================
104 //function : ComputeSelection
105 //purpose  : 
106 //=======================================================================
107 void AIS_Point::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
108                                  const Standard_Integer /*aMode*/)
109 {
110   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,10);
111   Handle(Select3D_SensitivePoint) sp = new Select3D_SensitivePoint(eown,
112                                                                    myComponent->Pnt());
113   aSelection->Add(sp);
114 }
115
116 //=======================================================================
117 //function : SetColor
118 //purpose  :
119 //=======================================================================
120 void AIS_Point::SetColor (const Quantity_Color& theCol)
121 {
122   hasOwnColor=Standard_True;
123   myDrawer->SetColor (theCol);
124   UpdatePointValues();
125 }
126
127 //=======================================================================
128 //function : UnsetColor
129 //purpose  : 
130 //=======================================================================
131 void AIS_Point::UnsetColor()
132 {
133   hasOwnColor=Standard_False;
134   UpdatePointValues();
135 }
136
137
138 //=======================================================================
139 //function : Vertex
140 //purpose  : 
141 //=======================================================================
142 TopoDS_Vertex AIS_Point::Vertex() const
143 {
144   gp_Pnt P = myComponent->Pnt();
145   return BRepBuilderAPI_MakeVertex(P);
146 }
147
148 //=======================================================================
149 //function : SetMarker
150 //purpose  : 
151 //=======================================================================
152
153 void AIS_Point::SetMarker(const Aspect_TypeOfMarker aTOM)
154 {
155   myTOM = aTOM;
156   myHasTOM = Standard_True;
157   UpdatePointValues();
158 }
159
160 //=======================================================================
161 //function : UnsetMarker
162 //purpose  : 
163 //=======================================================================
164 void AIS_Point::UnsetMarker()
165 {
166   myHasTOM = Standard_False;
167   UpdatePointValues();
168 }
169
170 //=======================================================================
171 //function : AcceptDisplayMode
172 //purpose  : 
173 //=======================================================================
174
175  Standard_Boolean AIS_Point::AcceptDisplayMode (const Standard_Integer theMode) const
176 {
177   return theMode == 0
178       || theMode == -99;
179 }
180
181 //=======================================================================
182 //function : replaceWithNewPointAspect
183 //purpose  :
184 //=======================================================================
185 void AIS_Point::replaceWithNewPointAspect (const Handle(Prs3d_PointAspect)& theAspect)
186 {
187   if (!myDrawer->HasLink())
188   {
189     myDrawer->SetPointAspect (theAspect);
190     return;
191   }
192
193   const Handle(Graphic3d_AspectMarker3d) anAspectOld = myDrawer->PointAspect()->Aspect();
194   const Handle(Graphic3d_AspectMarker3d) anAspectNew = !theAspect.IsNull() ? theAspect->Aspect() : myDrawer->Link()->PointAspect()->Aspect();
195   if (anAspectNew != anAspectOld)
196   {
197     myDrawer->SetPointAspect (theAspect);
198     Graphic3d_MapOfAspectsToAspects aReplaceMap;
199     aReplaceMap.Bind (anAspectOld, anAspectNew);
200     replaceAspects (aReplaceMap);
201   }
202 }
203
204 //=======================================================================
205 //function : UpdatePointValues
206 //purpose  : 
207 //=======================================================================
208
209 void AIS_Point::UpdatePointValues()
210 {
211   if (!hasOwnColor
212    &&  myOwnWidth == 0.0f
213    && !myHasTOM)
214   {
215     replaceWithNewPointAspect (Handle(Prs3d_PointAspect)());
216     return;
217   }
218
219   Quantity_Color      aCol (Quantity_NOC_YELLOW);
220   Aspect_TypeOfMarker aTOM = Aspect_TOM_PLUS;
221   Standard_Real       aScale = 1.0;
222   if (myDrawer->HasLink())
223   {
224     aCol   = myDrawer->Link()->PointAspect()->Aspect()->Color();
225     aTOM   = myDrawer->Link()->PointAspect()->Aspect()->Type();
226     aScale = myDrawer->Link()->PointAspect()->Aspect()->Scale();
227   }
228
229   if(hasOwnColor) aCol = myDrawer->Color();
230   if(myOwnWidth != 0.0f) aScale = myOwnWidth;
231   if(myHasTOM) aTOM = myTOM;
232
233   if(myDrawer->HasOwnPointAspect())
234   {
235     Handle(Prs3d_PointAspect) PA =  myDrawer->PointAspect();
236     PA->SetColor(aCol);
237     PA->SetTypeOfMarker(aTOM);
238     PA->SetScale(aScale);
239     SynchronizeAspects();
240   }
241   else
242   {
243     replaceWithNewPointAspect (new Prs3d_PointAspect (aTOM, aCol, aScale));
244   }
245 }
246