0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / AIS / AIS_Relation.cxx
CommitLineData
b311480e 1// Created on: 1996-12-05
2// Created by: Odile Olivier
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
b8ddfc2f 22//GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
7fd59977 23
24#define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
25// if any in all dimensions.
26
27#include <AIS.hxx>
7fd59977 28#include <Graphic3d_Group.hxx>
29
30#include <AIS_Relation.ixx>
31
32#include <AIS_Drawer.hxx>
33#include <AIS_GraphicTool.hxx>
34#include <BRepBuilderAPI_MakeEdge.hxx>
35#include <BRep_Tool.hxx>
36#include <Geom_Circle.hxx>
37#include <Geom_Line.hxx>
38#include <Geom_CartesianPoint.hxx>
39
40#include <Prs3d_LineAspect.hxx>
a6eb515f 41#include <Prs3d_DimensionAspect.hxx>
7fd59977 42#include <Prs3d_PointAspect.hxx>
7fd59977 43#include <Prs3d_TextAspect.hxx>
44
45#include <StdPrs_WFDeflectionShape.hxx>
46#include <StdPrs_Point.hxx>
47
48#include <TopoDS.hxx>
49#include <TopoDS_Edge.hxx>
50#include <gp_Circ.hxx>
51#include <gp_Lin.hxx>
52#include <gp_Pnt.hxx>
53#include <ElCLib.hxx>
54#include <TopExp.hxx>
55
56
57#include <Precision.hxx>
58#include <BRepBuilderAPI_MakeVertex.hxx>
59
60//=======================================================================
61//function : AIS_Relation
62//purpose :
63//=======================================================================
64AIS_Relation::AIS_Relation(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
65:AIS_InteractiveObject(aTypeOfPresentation3d),
66 myVal(1.),
67 myPosition(0.,0.,0.),
68#ifdef BUC60915
69 myArrowSize( myVal / 10. ),
70#endif
71 myAutomaticPosition(Standard_True),
72 myExtShape(0),
73 myFirstOffset(0.),mySecondOffset(0.),
74 myIsSetBndBox( Standard_False )
75#ifdef BUC60915
76 ,myArrowSizeIsDefined( Standard_False)
77#endif
78{
79}
80
81
82
83//=======================================================================
84//function : ComputeProjEdgePresentation
85//purpose :
86//=======================================================================
87
88void AIS_Relation::ComputeProjEdgePresentation(const Handle(Prs3d_Presentation)& aPrs,
89 const TopoDS_Edge& anEdge,
90 const Handle(Geom_Curve)& ProjCurv,
91 const gp_Pnt& FirstP,
92 const gp_Pnt& LastP,
93 const Quantity_NameOfColor aColor,
94 const Standard_Real width,
95 const Aspect_TypeOfLine aProjTOL,
96 const Aspect_TypeOfLine aCallTOL) const
97{
98 if (!myDrawer->HasWireAspect()){
99 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aProjTOL,2.));}
100 else {
101 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
102 li->SetColor(aColor);
103 li->SetTypeOfLine(aProjTOL);
104 li->SetWidth(width);
105 }
106
107 Standard_Real pf, pl;
108 TopLoc_Location loc;
109 Handle(Geom_Curve) curve;
110 Standard_Boolean isInfinite;
111 curve = BRep_Tool::Curve(anEdge,loc,pf,pl);
112 isInfinite = (Precision::IsInfinite(pf) || Precision::IsInfinite(pl));
113
114 TopoDS_Edge E;
115
116 // Calcul de la presentation de l'edge
117 if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
118 const Handle(Geom_Line) & gl = (Handle(Geom_Line)&) ProjCurv;
119 if ( !isInfinite) {
120 pf = ElCLib::Parameter(gl->Lin(),FirstP);
121 pl = ElCLib::Parameter(gl->Lin(),LastP);
122 BRepBuilderAPI_MakeEdge MakEd(gl->Lin(), pf, pl);
123 E = MakEd.Edge();
124 }
125 else {
126 BRepBuilderAPI_MakeEdge MakEd(gl->Lin());
127 E = MakEd.Edge();
128 }
129 }
130 else if (ProjCurv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
131 const Handle(Geom_Circle) & gc = (Handle(Geom_Circle)&) ProjCurv;
132 pf = ElCLib::Parameter(gc->Circ(),FirstP);
133 pl = ElCLib::Parameter(gc->Circ(),LastP);
134 BRepBuilderAPI_MakeEdge MakEd(gc->Circ(),pf, pl);
135 E = MakEd.Edge();
136 }
137 StdPrs_WFDeflectionShape::Add(aPrs, E, myDrawer);
138
139 //Calcul de la presentation des lignes de raccord
140 myDrawer->WireAspect()->SetTypeOfLine(aCallTOL);
141 if (!isInfinite) {
142 gp_Pnt ppf, ppl;
143 ppf = BRep_Tool::Pnt( TopExp::FirstVertex(TopoDS::Edge(anEdge)));
144 ppl = BRep_Tool::Pnt( TopExp::LastVertex(TopoDS::Edge(anEdge)));
145 if (FirstP.Distance( ppf ) > gp::Resolution())
146 {
147 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
148 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
149 }
150 else
151 {
152 BRepBuilderAPI_MakeVertex MakVert1( FirstP );
153 StdPrs_WFDeflectionShape::Add(aPrs, MakVert1.Vertex(), myDrawer);
154 }
155 if (LastP.Distance( ppl ) > gp::Resolution())
156 {
157 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
158 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
159 }
160 else
161 {
162 BRepBuilderAPI_MakeVertex MakVert2( LastP );
163 StdPrs_WFDeflectionShape::Add(aPrs, MakVert2.Vertex(), myDrawer);
164 }
165/*
166 BRepBuilderAPI_MakeEdge MakEd1(FirstP, ppf);
167 StdPrs_WFDeflectionShape::Add(aPrs, MakEd1.Edge(), myDrawer);
168 BRepBuilderAPI_MakeEdge MakEd2(LastP, ppl);
169 StdPrs_WFDeflectionShape::Add(aPrs, MakEd2.Edge(), myDrawer);
170*/
171 }
172}
173
174
175//=======================================================================
176//function : ComputeProjVertexPresentation
177//purpose :
178//=======================================================================
179
180void AIS_Relation::ComputeProjVertexPresentation(const Handle(Prs3d_Presentation)& aPrs,
181 const TopoDS_Vertex& aVertex,
182 const gp_Pnt& ProjPoint,
183 const Quantity_NameOfColor aColor,
184 const Standard_Real width,
185 const Aspect_TypeOfMarker aProjTOM,
186 const Aspect_TypeOfLine aCallTOL) const
187{
188 if (!myDrawer->HasPointAspect()){
189 myDrawer->SetPointAspect(new Prs3d_PointAspect(aProjTOM, aColor,1));}
190 else {
191 const Handle(Prs3d_PointAspect)& pa = myDrawer->PointAspect();
192 pa->SetColor(aColor);
193 pa->SetTypeOfMarker(aProjTOM);
194 }
195
196 // calcul du projete
197 StdPrs_Point::Add(aPrs, new Geom_CartesianPoint(ProjPoint), myDrawer);
198
199 if (!myDrawer->HasWireAspect()){
200 myDrawer->SetWireAspect(new Prs3d_LineAspect(aColor,aCallTOL,2.));}
201 else {
202 const Handle(Prs3d_LineAspect)& li = myDrawer->WireAspect();
203 li->SetColor(aColor);
204 li->SetTypeOfLine(aCallTOL);
205 li->SetWidth(width);
206 }
207
208 // Si les points ne sont pas confondus...
209 if (!ProjPoint.IsEqual (BRep_Tool::Pnt(aVertex),Precision::Confusion())) {
210 // calcul des lignes de rappel
211 BRepBuilderAPI_MakeEdge MakEd(ProjPoint,BRep_Tool::Pnt(aVertex));
212 StdPrs_WFDeflectionShape::Add(aPrs, MakEd.Edge(), myDrawer);
213 }
214}
215
216//=======================================================================
217//function : SetColor
218//purpose :
219//=======================================================================
220
221void AIS_Relation::SetColor(const Quantity_NameOfColor aCol)
7fd59977 222{
223 SetColor(Quantity_Color(aCol));
224}
225
226void AIS_Relation::SetColor(const Quantity_Color &aCol)
7fd59977 227{
228 if(hasOwnColor && myOwnColor==aCol) return;
229
230 if (!myDrawer->HasTextAspect()) myDrawer->SetTextAspect(new Prs3d_TextAspect());
231 hasOwnColor=Standard_True;
232 myOwnColor=aCol;
233 myDrawer->TextAspect()->SetColor(aCol);
234
235 Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
236 if (!myDrawer->HasLineAspect()) {
237 myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
238 }
a6eb515f 239 if (!myDrawer->HasDimensionAspect()) {
240 myDrawer->SetDimensionAspect(new Prs3d_DimensionAspect);
7fd59977 241 }
a6eb515f 242
7fd59977 243 myDrawer->LineAspect()->SetColor(aCol);
a6eb515f 244 const Handle(Prs3d_DimensionAspect)& DIMENSION = myDrawer->DimensionAspect();
7fd59977 245 const Handle(Prs3d_LineAspect)& LINE = myDrawer->LineAspect();
246 const Handle(Prs3d_TextAspect)& TEXT = myDrawer->TextAspect();
247
a6eb515f 248 DIMENSION->SetLineAspect(LINE);
249 DIMENSION->SetTextAspect(TEXT);
7fd59977 250}
251
252//=======================================================================
253//function : UnsetColor
254//purpose :
255//=======================================================================
256void AIS_Relation::UnsetColor()
257{
258 if (!hasOwnColor) return;
259 hasOwnColor = Standard_False;
260 const Handle(Prs3d_LineAspect)& LA = myDrawer->LineAspect();
7fd59977 261 Quantity_Color CC;
262 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
263 LA->SetColor(CC);
a6eb515f 264 myDrawer->DimensionAspect()->SetLineAspect(LA);
7fd59977 265 myDrawer->SetTextAspect(myDrawer->Link()->TextAspect());
266}
267
268//=======================================================================
269//function : AcceptDisplayMode
270//purpose :
271//=======================================================================
272
273 Standard_Boolean AIS_Relation::
274AcceptDisplayMode(const Standard_Integer aMode) const
275{return aMode == 0;}
276
277
278//=======================================================================
279//function : SetFirstShape
280//purpose :
281//=======================================================================
282
283void AIS_Relation::SetFirstShape(const TopoDS_Shape& aFShape)
284{
285 myFShape = aFShape;
286}
287
288
289//=======================================================================
290//function : SetSecondShape
291//purpose :
292//=======================================================================
293
294void AIS_Relation::SetSecondShape(const TopoDS_Shape& aSShape)
295{
296 mySShape = aSShape;
297}
298
299//=======================================================================
300//function : KindOfDimension
301//purpose :
302//=======================================================================
303AIS_KindOfDimension AIS_Relation::KindOfDimension() const
304{return AIS_KOD_NONE;}
305
306//=======================================================================
307//function : IsMovable
308//purpose :
309//=======================================================================
310Standard_Boolean AIS_Relation::IsMovable() const
311{return Standard_False;}
312
313