0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / AIS / AIS_Point.cxx
CommitLineData
b311480e 1// Created on: 1995-08-09
2// Created by: Arnaud BOUZY/Odile Olivier
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
87432b82 17#include <AIS_Point.hxx>
42cf5bc1 18
19#include <AIS_InteractiveContext.hxx>
7fd59977 20#include <Aspect_TypeOfLine.hxx>
42cf5bc1 21#include <BRepBuilderAPI_MakeVertex.hxx>
22#include <Geom_Point.hxx>
42cf5bc1 23#include <Graphic3d_ArrayOfPoints.hxx>
24#include <Graphic3d_AspectMarker3d.hxx>
25#include <Graphic3d_Group.hxx>
26#include <Graphic3d_Structure.hxx>
7fd59977 27#include <Prs3d_Drawer.hxx>
28#include <Prs3d_PointAspect.hxx>
42cf5bc1 29#include <Prs3d_Presentation.hxx>
7fd59977 30#include <Quantity_Color.hxx>
7fd59977 31#include <Select3D_SensitivePoint.hxx>
42cf5bc1 32#include <SelectMgr_EntityOwner.hxx>
33#include <Standard_Type.hxx>
7fd59977 34#include <StdPrs_Point.hxx>
42cf5bc1 35#include <TopoDS_Vertex.hxx>
7fd59977 36
92efcf78 37IMPLEMENT_STANDARD_RTTIEXT(AIS_Point,AIS_InteractiveObject)
38
7fd59977 39//=======================================================================
40//function : AIS_Point
41//purpose :
42//=======================================================================
43AIS_Point::AIS_Point(const Handle(Geom_Point)& aComponent):
44myComponent(aComponent),
45myHasTOM(Standard_False),
46myTOM(Aspect_TOM_PLUS)
47{
f838dac4 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);
db60634e 52 myHilightDrawer->SetZLayer (Graphic3d_ZLayerId_UNKNOWN);
f838dac4 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);
db60634e 57 myDynHilightDrawer->SetZLayer (Graphic3d_ZLayerId_Top);
7fd59977 58}
59
60//=======================================================================
61//function : Component
62//purpose :
63//=======================================================================
64
65Handle(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//=======================================================================
84void AIS_Point::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
85 const Handle(Prs3d_Presentation)& aPresentation,
86 const Standard_Integer aMode)
87{
7fd59977 88 aPresentation->SetInfiniteState(myInfiniteState);
89
90 if (aMode==0)
91 StdPrs_Point::Add(aPresentation,myComponent,myDrawer);
92 else if (aMode== -99)
93 {
7fd59977 94 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
f838dac4 95 TheGroup->SetPrimitivesAspect (myHilightDrawer->PointAspect()->Aspect());
a577aaab 96 Handle(Graphic3d_ArrayOfPoints) aPoint = new Graphic3d_ArrayOfPoints (1);
97 aPoint->AddVertex (myComponent->X(),myComponent->Y(),myComponent->Z());
98 TheGroup->AddPrimitiveArray (aPoint);
7fd59977 99 }
100
101}
102
103//=======================================================================
7fd59977 104//function : ComputeSelection
105//purpose :
106//=======================================================================
107void AIS_Point::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
108 const Standard_Integer /*aMode*/)
109{
110 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,10);
7fd59977 111 Handle(Select3D_SensitivePoint) sp = new Select3D_SensitivePoint(eown,
112 myComponent->Pnt());
113 aSelection->Add(sp);
114}
115
116//=======================================================================
117//function : SetColor
87432b82 118//purpose :
7fd59977 119//=======================================================================
f838dac4 120void AIS_Point::SetColor (const Quantity_Color& theCol)
7fd59977 121{
122 hasOwnColor=Standard_True;
f838dac4 123 myDrawer->SetColor (theCol);
7fd59977 124 UpdatePointValues();
125}
126
127//=======================================================================
128//function : UnsetColor
129//purpose :
130//=======================================================================
131void AIS_Point::UnsetColor()
132{
133 hasOwnColor=Standard_False;
134 UpdatePointValues();
135}
136
137
138//=======================================================================
139//function : Vertex
140//purpose :
141//=======================================================================
142TopoDS_Vertex AIS_Point::Vertex() const
143{
144 gp_Pnt P = myComponent->Pnt();
145 return BRepBuilderAPI_MakeVertex(P);
146}
147
7fd59977 148//=======================================================================
149//function : SetMarker
150//purpose :
151//=======================================================================
152
153void 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//=======================================================================
164void AIS_Point::UnsetMarker()
165{
166 myHasTOM = Standard_False;
167 UpdatePointValues();
168}
169
170//=======================================================================
171//function : AcceptDisplayMode
172//purpose :
173//=======================================================================
174
f838dac4 175 Standard_Boolean AIS_Point::AcceptDisplayMode (const Standard_Integer theMode) const
176{
177 return theMode == 0
178 || theMode == -99;
179}
7fd59977 180
181//=======================================================================
226fce20 182//function : replaceWithNewPointAspect
183//purpose :
184//=======================================================================
185void 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//=======================================================================
7fd59977 205//function : UpdatePointValues
206//purpose :
207//=======================================================================
208
209void AIS_Point::UpdatePointValues()
210{
226fce20 211 if (!hasOwnColor
212 && myOwnWidth == 0.0f
213 && !myHasTOM)
6262338c 214 {
226fce20 215 replaceWithNewPointAspect (Handle(Prs3d_PointAspect)());
7fd59977 216 return;
217 }
226fce20 218
b6472664 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();
7fd59977 227 }
b6472664 228
f838dac4 229 if(hasOwnColor) aCol = myDrawer->Color();
226fce20 230 if(myOwnWidth != 0.0f) aScale = myOwnWidth;
7fd59977 231 if(myHasTOM) aTOM = myTOM;
226fce20 232
233 if(myDrawer->HasOwnPointAspect())
234 {
7fd59977 235 Handle(Prs3d_PointAspect) PA = myDrawer->PointAspect();
7fd59977 236 PA->SetColor(aCol);
237 PA->SetTypeOfMarker(aTOM);
238 PA->SetScale(aScale);
226fce20 239 SynchronizeAspects();
7fd59977 240 }
241 else
226fce20 242 {
243 replaceWithNewPointAspect (new Prs3d_PointAspect (aTOM, aCol, aScale));
244 }
7fd59977 245}
246