0022627: Change OCCT memory management defaults
[occt.git] / src / AIS / AIS_Point.cxx
1 // File:        AIS_Point.cxx
2 // Created:     Wed Aug  9 14:38:46 1995
3 // Author:      Arnaud BOUZY/Odile Olivier
4 //              <adn>
5
6 #define GER61351                //GG_171199     Enable to set an object RGB color
7 //                                                instead a restricted object NameOfColor.
8
9 #include <AIS_Point.ixx>
10 #include <Aspect_TypeOfLine.hxx>
11 #include <Prs3d_Drawer.hxx>
12 #include <Prs3d_PointAspect.hxx>
13 #include <Graphic3d_Structure.hxx>
14 #include <Graphic3d_Group.hxx>
15 #include <Quantity_Color.hxx>
16 #include <Graphic3d_Vertex.hxx>
17 #include <Graphic3d_AspectMarker3d.hxx>
18 #include <SelectMgr_EntityOwner.hxx>
19 #include <SelectBasics_EntityOwner.hxx>
20 #include <Select3D_SensitivePoint.hxx>
21 #include <StdPrs_Point.hxx>
22 #include <Geom_Point.hxx>
23 #include <BRepBuilderAPI_MakeVertex.hxx>
24 #include <AIS_Drawer.hxx>
25
26 #include <AIS_InteractiveContext.hxx>
27 //=======================================================================
28 //function : AIS_Point
29 //purpose  : 
30 //=======================================================================
31 AIS_Point::AIS_Point(const Handle(Geom_Point)& aComponent):
32 myComponent(aComponent),
33 myHasTOM(Standard_False),
34 myTOM(Aspect_TOM_PLUS)
35 {
36   myHilightMode=-99;
37 }
38
39 //=======================================================================
40 //function : Component
41 //purpose  : 
42 //=======================================================================
43
44 Handle(Geom_Point) AIS_Point::Component()
45 {
46   return myComponent;
47 }
48
49 //=======================================================================
50 //function : SetComponent
51 //purpose  : 
52 //=======================================================================
53
54  void AIS_Point::SetComponent(const Handle(Geom_Point)& aComponent)
55 {
56   myComponent = aComponent;
57 }
58
59 //=======================================================================
60 //function : Compute
61 //purpose  : 
62 //=======================================================================
63 void AIS_Point::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
64                         const Handle(Prs3d_Presentation)& aPresentation, 
65                         const Standard_Integer aMode)
66 {
67   aPresentation->Clear();
68
69   aPresentation->SetInfiniteState(myInfiniteState);
70
71   if (aMode==0)
72     StdPrs_Point::Add(aPresentation,myComponent,myDrawer);
73   else if (aMode== -99)
74     {
75       // Beeurk.. a revoir - rob-25/04/97
76       static Handle(Graphic3d_AspectMarker3d) PtA = 
77         new Graphic3d_AspectMarker3d ();
78       PtA->SetType(Aspect_TOM_PLUS);
79       PtA->SetScale(3.);
80       Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
81       TheGroup->SetPrimitivesAspect(PtA);
82       Graphic3d_Vertex Vtx(myComponent->X(),myComponent->Y(),myComponent->Z());
83       TheGroup->Marker(Vtx);
84     }
85     
86 }
87
88 //=======================================================================
89 //function : Compute
90 //purpose  : 
91 //=======================================================================
92
93 void AIS_Point::Compute(const Handle_Prs3d_Projector& aProjector,
94                         const Handle_Geom_Transformation& aTransformation,
95                         const Handle_Prs3d_Presentation& aPresentation)
96 {
97 // Standard_NotImplemented::Raise("AIS_Point::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
98  PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
99 }
100
101 //=======================================================================
102 //function : ComputeSelection
103 //purpose  : 
104 //=======================================================================
105 void AIS_Point::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
106                                  const Standard_Integer /*aMode*/)
107 {
108   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,10);
109 //  eown -> SelectBasics_EntityOwner::Set(5);
110   Handle(Select3D_SensitivePoint) sp = new Select3D_SensitivePoint(eown,
111                                                                    myComponent->Pnt());
112   aSelection->Add(sp);
113 }
114
115 //=======================================================================
116 //function : SetColor
117 //purpose  : 
118 //=======================================================================
119
120 void AIS_Point::SetColor(const Quantity_NameOfColor aCol)
121 #ifdef GER61351
122 {
123   SetColor(Quantity_Color(aCol));
124 }
125
126 void AIS_Point::SetColor(const Quantity_Color &aCol)
127 #endif
128 {
129   hasOwnColor=Standard_True;
130   myOwnColor=aCol;
131   UpdatePointValues();
132 }
133
134 //=======================================================================
135 //function : UnsetColor
136 //purpose  : 
137 //=======================================================================
138 void AIS_Point::UnsetColor()
139 {
140   hasOwnColor=Standard_False;
141   UpdatePointValues();
142 }
143
144
145 //=======================================================================
146 //function : Vertex
147 //purpose  : 
148 //=======================================================================
149 TopoDS_Vertex AIS_Point::Vertex() const
150 {
151   gp_Pnt P = myComponent->Pnt();
152   return BRepBuilderAPI_MakeVertex(P);
153 }
154
155 //=======================================================================
156 //function : Compute
157 //purpose  : to avoid warning
158 //=======================================================================
159 void AIS_Point::Compute(const Handle(PrsMgr_PresentationManager2d)&, 
160                            const Handle(Graphic2d_GraphicObject)&,
161                            const Standard_Integer)
162 {
163 }
164 //=======================================================================
165 //function : Compute
166 //purpose  : to avoid warning
167 //=======================================================================
168 void AIS_Point::Compute(const Handle(Prs3d_Projector)&, 
169                            const Handle(Prs3d_Presentation)&)
170 {
171 }
172
173 //=======================================================================
174 //function : SetMarker
175 //purpose  : 
176 //=======================================================================
177
178 void AIS_Point::SetMarker(const Aspect_TypeOfMarker aTOM)
179 {
180   myTOM = aTOM;
181   myHasTOM = Standard_True;
182   UpdatePointValues();
183 }
184
185 //=======================================================================
186 //function : UnsetMarker
187 //purpose  : 
188 //=======================================================================
189 void AIS_Point::UnsetMarker()
190 {
191   myHasTOM = Standard_False;
192   UpdatePointValues();
193 }
194
195 //=======================================================================
196 //function : AcceptDisplayMode
197 //purpose  : 
198 //=======================================================================
199
200  Standard_Boolean  AIS_Point::
201 AcceptDisplayMode(const Standard_Integer aMode) const
202 {return aMode == 0;}
203
204
205 //=======================================================================
206 //function : UpdatePointValues
207 //purpose  : 
208 //=======================================================================
209
210 void AIS_Point::UpdatePointValues()
211 {
212
213   if(!hasOwnColor && myOwnWidth==0.0 && !myHasTOM){
214     myDrawer->PointAspect().Nullify();
215     return;
216   }
217 #ifdef GER61351
218   Quantity_Color aCol;
219 #else
220   Quantity_NameOfColor aCol;
221 #endif 
222   Quantity_Color QCO;
223   Aspect_TypeOfMarker  aTOM;
224   Standard_Real        aScale;
225   
226   if(myDrawer->HasLink()){
227     myDrawer->Link()->PointAspect()->Aspect()->Values(QCO,aTOM,aScale);
228     aCol = QCO.Name();
229   }
230   else{
231     aCol = Quantity_NOC_YELLOW;
232     aTOM = Aspect_TOM_PLUS;
233     aScale = 1;
234   }
235   if(hasOwnColor) aCol = myOwnColor;
236   if(myOwnWidth!=0.0) aScale = myOwnWidth;
237   if(myHasTOM) aTOM = myTOM;
238   
239   
240   if(myDrawer->HasPointAspect()){
241     // CLE
242     // const Handle(Prs3d_PointAspect) PA =  myDrawer->PointAspect();
243     Handle(Prs3d_PointAspect) PA =  myDrawer->PointAspect();
244     // ENDCLE
245     PA->SetColor(aCol);
246     PA->SetTypeOfMarker(aTOM);
247     PA->SetScale(aScale);
248   }
249   else
250     myDrawer->SetPointAspect(new Prs3d_PointAspect(aTOM,aCol,aScale));
251 }
252