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