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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <AIS_Point.hxx>
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>
37 IMPLEMENT_STANDARD_RTTIEXT(AIS_Point,AIS_InteractiveObject)
39 //=======================================================================
40 //function : AIS_Point
42 //=======================================================================
43 AIS_Point::AIS_Point(const Handle(Geom_Point)& aComponent):
44 myComponent(aComponent),
45 myHasTOM(Standard_False),
46 myTOM(Aspect_TOM_PLUS)
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);
60 //=======================================================================
61 //function : Component
63 //=======================================================================
65 Handle(Geom_Point) AIS_Point::Component()
70 //=======================================================================
71 //function : SetComponent
73 //=======================================================================
75 void AIS_Point::SetComponent(const Handle(Geom_Point)& aComponent)
77 myComponent = aComponent;
80 //=======================================================================
83 //=======================================================================
84 void AIS_Point::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
85 const Handle(Prs3d_Presentation)& aPresentation,
86 const Standard_Integer aMode)
88 aPresentation->SetInfiniteState(myInfiniteState);
91 StdPrs_Point::Add(aPresentation,myComponent,myDrawer);
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);
103 //=======================================================================
104 //function : ComputeSelection
106 //=======================================================================
107 void AIS_Point::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
108 const Standard_Integer /*aMode*/)
110 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,10);
111 Handle(Select3D_SensitivePoint) sp = new Select3D_SensitivePoint(eown,
116 //=======================================================================
117 //function : SetColor
119 //=======================================================================
120 void AIS_Point::SetColor (const Quantity_Color& theCol)
122 hasOwnColor=Standard_True;
123 myDrawer->SetColor (theCol);
127 //=======================================================================
128 //function : UnsetColor
130 //=======================================================================
131 void AIS_Point::UnsetColor()
133 hasOwnColor=Standard_False;
138 //=======================================================================
141 //=======================================================================
142 TopoDS_Vertex AIS_Point::Vertex() const
144 gp_Pnt P = myComponent->Pnt();
145 return BRepBuilderAPI_MakeVertex(P);
148 //=======================================================================
149 //function : SetMarker
151 //=======================================================================
153 void AIS_Point::SetMarker(const Aspect_TypeOfMarker aTOM)
156 myHasTOM = Standard_True;
160 //=======================================================================
161 //function : UnsetMarker
163 //=======================================================================
164 void AIS_Point::UnsetMarker()
166 myHasTOM = Standard_False;
170 //=======================================================================
171 //function : AcceptDisplayMode
173 //=======================================================================
175 Standard_Boolean AIS_Point::AcceptDisplayMode (const Standard_Integer theMode) const
181 //=======================================================================
182 //function : replaceWithNewPointAspect
184 //=======================================================================
185 void AIS_Point::replaceWithNewPointAspect (const Handle(Prs3d_PointAspect)& theAspect)
187 if (!myDrawer->HasLink())
189 myDrawer->SetPointAspect (theAspect);
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)
197 myDrawer->SetPointAspect (theAspect);
198 Graphic3d_MapOfAspectsToAspects aReplaceMap;
199 aReplaceMap.Bind (anAspectOld, anAspectNew);
200 replaceAspects (aReplaceMap);
204 //=======================================================================
205 //function : UpdatePointValues
207 //=======================================================================
209 void AIS_Point::UpdatePointValues()
212 && myOwnWidth == 0.0f
215 replaceWithNewPointAspect (Handle(Prs3d_PointAspect)());
219 Quantity_Color aCol (Quantity_NOC_YELLOW);
220 Aspect_TypeOfMarker aTOM = Aspect_TOM_PLUS;
221 Standard_Real aScale = 1.0;
222 if (myDrawer->HasLink())
224 aCol = myDrawer->Link()->PointAspect()->Aspect()->Color();
225 aTOM = myDrawer->Link()->PointAspect()->Aspect()->Type();
226 aScale = myDrawer->Link()->PointAspect()->Aspect()->Scale();
229 if(hasOwnColor) aCol = myDrawer->Color();
230 if(myOwnWidth != 0.0f) aScale = myOwnWidth;
231 if(myHasTOM) aTOM = myTOM;
233 if(myDrawer->HasOwnPointAspect())
235 Handle(Prs3d_PointAspect) PA = myDrawer->PointAspect();
237 PA->SetTypeOfMarker(aTOM);
238 PA->SetScale(aScale);
239 SynchronizeAspects();
243 replaceWithNewPointAspect (new Prs3d_PointAspect (aTOM, aCol, aScale));