0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / PrsDim / PrsDim_ConcentricRelation.cxx
CommitLineData
b311480e 1// Created on: 1996-12-05
2// Created by: Flore Lantheaume/Odile Olivier
3// Copyright (c) 1996-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
787ff240 17#include <PrsDim_ConcentricRelation.hxx>
7fd59977 18
787ff240 19#include <PrsDim.hxx>
7fd59977 20#include <BRepAdaptor_Curve.hxx>
42cf5bc1 21#include <DsgPrs_ConcentricPresentation.hxx>
7fd59977 22#include <Geom_Circle.hxx>
42cf5bc1 23#include <Geom_Plane.hxx>
42cf5bc1 24#include <GeomAbs_CurveType.hxx>
7fd59977 25#include <gp_Ax1.hxx>
42cf5bc1 26#include <gp_Ax2.hxx>
27#include <gp_Dir.hxx>
7fd59977 28#include <gp_Pln.hxx>
42cf5bc1 29#include <gp_Pnt.hxx>
30#include <gp_Vec.hxx>
31#include <Prs3d_Presentation.hxx>
42cf5bc1 32#include <Select3D_SensitiveCircle.hxx>
33#include <Select3D_SensitiveSegment.hxx>
34#include <SelectMgr_EntityOwner.hxx>
35#include <SelectMgr_Selection.hxx>
36#include <Standard_NotImplemented.hxx>
42cf5bc1 37#include <TopoDS.hxx>
38#include <TopoDS_Shape.hxx>
7fd59977 39#include <TopoDS_Vertex.hxx>
7fd59977 40
787ff240 41IMPLEMENT_STANDARD_RTTIEXT(PrsDim_ConcentricRelation, PrsDim_Relation)
92efcf78 42
7fd59977 43//=======================================================================
44//function : Constructor
45//purpose :
46//=======================================================================
787ff240 47PrsDim_ConcentricRelation::PrsDim_ConcentricRelation(
7fd59977 48 const TopoDS_Shape& aFShape,
49 const TopoDS_Shape& aSShape,
50 const Handle(Geom_Plane)& aPlane)
51{
52 myFShape = aFShape;
53 mySShape = aSShape;
54 myPlane = aPlane;
55 myDir = aPlane->Pln().Axis().Direction();
56}
57
58//=======================================================================
59//function : Compute
60//purpose :
61//=======================================================================
787ff240 62void PrsDim_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
7fd59977 63 const Handle(Prs3d_Presentation)& aPresentation,
64 const Standard_Integer)
65{
7fd59977 66 TopAbs_ShapeEnum type2(mySShape.ShapeType());
67 aPresentation->SetInfiniteState(Standard_True);
68 switch (myFShape.ShapeType()) {
69 case TopAbs_EDGE:
70 {
71 if (type2 == TopAbs_EDGE) ComputeTwoEdgesConcentric(aPresentation);
72 else if (type2 == TopAbs_VERTEX) ComputeEdgeVertexConcentric(aPresentation);
73 }
74 break;
75
76 case TopAbs_VERTEX:
77 {
78 if (type2 == TopAbs_VERTEX) ComputeTwoVerticesConcentric(aPresentation);
79 else if (type2 == TopAbs_EDGE) ComputeEdgeVertexConcentric(aPresentation);
80 }
81 break;
82 default: {return;}
83 }
84}
85
7fd59977 86//=======================================================================
87//function : ComputeTwoEdgesConcentric
88//purpose :
89//=======================================================================
787ff240 90void PrsDim_ConcentricRelation::ComputeEdgeVertexConcentric(const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 91{
92 TopoDS_Edge E;
93 TopoDS_Vertex V;
94 if (myFShape.ShapeType() == TopAbs_EDGE) {
95 E = TopoDS::Edge(myFShape);
96 V = TopoDS::Vertex(mySShape);
97 }
98 else {
53aa7b32
P
99 E = TopoDS::Edge(mySShape);
100 V = TopoDS::Vertex(myFShape);
7fd59977 101 }
102 gp_Pnt p1,p2;
103 Handle(Geom_Curve) C;
104 Handle(Geom_Curve) extCurv;
105 Standard_Boolean isInfinite;
106 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
787ff240 107 if (!PrsDim::ComputeGeometry(E,C,p1,p2,extCurv,isInfinite,isOnPlanEdge,myPlane)) return;
7fd59977 108 gp_Pnt P;
787ff240 109 PrsDim::ComputeGeometry(V,P, myPlane, isOnPlanVertex);
7fd59977 110
c5f3a425 111 Handle(Geom_Circle) CIRCLE (Handle(Geom_Circle)::DownCast (C));
7fd59977 112 myCenter = CIRCLE->Location();
113 myRad = Min(CIRCLE->Radius()/5.,15.);
114 gp_Dir vec(p1.XYZ() - myCenter.XYZ() );
115 gp_Vec vectrans(vec);
116 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
117 DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
787ff240 118 if (!isOnPlanEdge) PrsDim::ComputeProjEdgePresentation(aPresentation,myDrawer,E,CIRCLE,p1,p2);
119 if (!isOnPlanVertex) PrsDim::ComputeProjVertexPresentation(aPresentation,myDrawer,V,P);
7fd59977 120}
121
122//=======================================================================
123//function : ComputeTwoEdgesConcentric
124//purpose :
125//=======================================================================
787ff240 126void PrsDim_ConcentricRelation::ComputeTwoVerticesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 127{
128 TopoDS_Vertex V1,V2;
129 V1 = TopoDS::Vertex(myFShape);
130 V2 = TopoDS::Vertex(myFShape);
131 Standard_Boolean isOnPlanVertex1(Standard_True),isOnPlanVertex2(Standard_True);
132 gp_Pnt P1,P2;
787ff240 133 PrsDim::ComputeGeometry(V1,P1, myPlane,isOnPlanVertex1);
134 PrsDim::ComputeGeometry(V2,P2, myPlane,isOnPlanVertex2);
7fd59977 135 myCenter = P1;
136 myRad = 15.;
137 gp_Dir vec(myPlane->Pln().Position().XDirection());
138 gp_Vec vectrans(vec);
139 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
140 DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
787ff240 141 if (!isOnPlanVertex1) PrsDim::ComputeProjVertexPresentation(aPresentation,myDrawer,V1,P1);
142 if (!isOnPlanVertex2) PrsDim::ComputeProjVertexPresentation(aPresentation,myDrawer,V2,P2);
7fd59977 143}
144
145//=======================================================================
146//function : ComputeTwoEdgesConcentric
147//purpose :
148//=======================================================================
787ff240 149void PrsDim_ConcentricRelation::ComputeTwoEdgesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 150{
151 BRepAdaptor_Curve curv1(TopoDS::Edge(myFShape));
152 BRepAdaptor_Curve curv2(TopoDS::Edge(mySShape));
153
154 gp_Pnt ptat11,ptat12,ptat21,ptat22;
155 Handle(Geom_Curve) geom1,geom2;
156 Standard_Boolean isInfinite1,isInfinite2;
157 Handle(Geom_Curve) extCurv;
787ff240 158 if (!PrsDim::ComputeGeometry(TopoDS::Edge(myFShape), TopoDS::Edge(mySShape),
7fd59977 159 myExtShape,
787ff240 160 geom1, geom2,
161 ptat11, ptat12,
162 ptat21, ptat22,
7fd59977 163 extCurv,
164 isInfinite1,isInfinite2,
165 myPlane)) {
166 return;
167 }
168
c5f3a425 169 Handle(Geom_Circle) gcirc1 (Handle(Geom_Circle)::DownCast (geom1));
170 Handle(Geom_Circle) gcirc2 (Handle(Geom_Circle)::DownCast (geom2));
7fd59977 171
172 myCenter = gcirc1->Location();
173
81bba717 174 // choose the radius equal to 1/5 of the smallest radius of
175 // 2 circles. Limit is imposed ( 0.02 by chance)
896faa72 176 Standard_Real aRad1 = gcirc1->Radius();
177 Standard_Real aRad2 = gcirc2->Radius();
178 myRad = (aRad1 > aRad2 ) ? aRad2 : aRad1;
7fd59977 179 myRad /= 5;
180 if (myRad > 15.) myRad =15.;
181
182
81bba717 183 //Calculate a point of circle of radius myRad
7fd59977 184 gp_Dir vec(ptat11.XYZ() - myCenter.XYZ() );
185 gp_Vec vectrans(vec);
186 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
187
188 DsgPrs_ConcentricPresentation::Add(aPresentation,
189 myDrawer,
190 myCenter,
191 myRad,
192 myDir,
193 myPnt);
194 if ( (myExtShape != 0) && !extCurv.IsNull()) {
195 gp_Pnt pf, pl;
196 if ( myExtShape == 1 ) {
197 if (!isInfinite1) {
198 pf = ptat11;
199 pl = ptat12;
200 }
201 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),gcirc1,pf,pl);
202 }
203 else {
204 if (!isInfinite2) {
205 pf = ptat21;
206 pl = ptat22;
207 }
208 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),gcirc2,pf,pl);
209 }
210 }
211}
212
7fd59977 213//=======================================================================
214//function : ComputeSelection
215//purpose :
216//=======================================================================
217
787ff240 218void PrsDim_ConcentricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
7fd59977 219 const Standard_Integer)
220{
221 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
222
81bba717 223 //Creation of 2 sensitive circles
224 // the greater
7fd59977 225 gp_Ax2 ax(myCenter, myDir);
7f24b768 226 gp_Circ aCirc (ax, myRad);
227 Handle(Select3D_SensitiveCircle) sensit = new Select3D_SensitiveCircle (own, aCirc);
7fd59977 228 aSelection->Add(sensit);
81bba717 229 // the smaller
7f24b768 230 aCirc.SetRadius(myRad/2);
231 sensit = new Select3D_SensitiveCircle (own, aCirc);
7fd59977 232 aSelection->Add(sensit);
233
81bba717 234 //Creation of 2 segments sensitive for the cross
7fd59977 235 Handle(Select3D_SensitiveSegment) seg;
236 gp_Pnt otherPnt = myPnt.Mirrored(myCenter);
237 seg = new Select3D_SensitiveSegment(own,
238 otherPnt,
239 myPnt);
240 aSelection->Add(seg);
241
242 gp_Ax1 RotateAxis(myCenter, myDir);
c6541a0c
D
243 gp_Pnt FPnt = myCenter.Rotated(RotateAxis, M_PI/2);
244 gp_Pnt SPnt = myCenter.Rotated(RotateAxis, -M_PI/2);
7fd59977 245 seg = new Select3D_SensitiveSegment(own,
246 FPnt,
247 SPnt);
248 aSelection->Add(seg);
249
250}
251