1 // Created on: 1993-10-11
2 // Created by: Christophe MARION
3 // Copyright (c) 1993-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 // Modified by cma, Fri Nov 10 17:36:13 1995
19 #include <BRep_Builder.hxx>
20 #include <BRepLib_MakeEdge2d.hxx>
21 #include <HLRAlgo_EdgeIterator.hxx>
22 #include <HLRAlgo_EdgeStatus.hxx>
23 #include <HLRBRep_BiPnt2D.hxx>
24 #include <HLRBRep_ListIteratorOfListOfBPnt2D.hxx>
25 #include <HLRBRep_PolyAlgo.hxx>
26 #include <HLRBRep_PolyHLRToShape.hxx>
27 #include <TopExp_Explorer.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopTools_MapOfShape.hxx>
32 //=======================================================================
33 //function : HLRBRep_PolyHLRToShape
35 //=======================================================================
37 HLRBRep_PolyHLRToShape::HLRBRep_PolyHLRToShape ()
40 //=======================================================================
43 //=======================================================================
45 void HLRBRep_PolyHLRToShape::Update (const Handle(HLRBRep_PolyAlgo)& A)
48 myHideMode = Standard_True;
49 Standard_Real sta,end;
50 Standard_ShortReal tolsta,tolend;
51 HLRAlgo_EdgeIterator It;
55 Standard_Boolean reg1,regn,outl,intl;
56 const gp_Trsf& T = myAlgo->Projector().Transformation();
57 HLRAlgo_EdgeStatus status;
59 for (myAlgo->InitHide(); myAlgo->MoreHide(); myAlgo->NextHide()) {
60 HLRAlgo_BiPoint::PointsT& aPoints = myAlgo->Hide(status,S,reg1,regn,outl,intl);
61 gp_XYZ aSta = aPoints.Pnt1;
62 gp_XYZ aEnd = aPoints.Pnt2;
65 const gp_XY aSta2D(aSta.X(), aSta.Y());
66 const gp_XY aEnd2D(aEnd.X(), aEnd.Y());
67 const gp_XY aD = aEnd2D - aSta2D;
68 if (aD.Modulus() > 1.e-10) {
70 for (It.InitVisible(status);
73 It.Visible(sta,tolsta,end,tolend);
76 (aSta2D + sta * aD, aSta2D + end * aD,
77 S,reg1,regn,outl,intl));
80 for (It.InitHidden(status);
83 It.Hidden(sta,tolsta,end,tolend);
86 (aSta2D + sta * aD, aSta2D + end * aD,
87 S,reg1,regn,outl,intl));
93 //=======================================================================
94 //function : InternalCompound
96 //=======================================================================
99 HLRBRep_PolyHLRToShape::InternalCompound (const Standard_Integer typ,
100 const Standard_Boolean visible,
101 const TopoDS_Shape& S)
103 TopTools_MapOfShape Map;
106 for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next())
107 Map.Add(ex.Current());
108 for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next())
109 Map.Add(ex.Current());
111 Standard_Boolean todraw,reg1,regn,outl,intl;
112 Standard_Boolean added = Standard_False;
115 B.MakeCompound(TopoDS::Compound(Result));
118 HLRBRep_ListIteratorOfListOfBPnt2D It;
119 if (visible) It.Initialize(myBiPntVis);
120 else It.Initialize(myBiPntHid);
122 for (; It.More(); It.Next()) {
123 const HLRBRep_BiPnt2D& BP = It.Value();
128 if (typ == 1) todraw = intl;
129 else if (typ == 2) todraw = reg1 && !regn && !outl;
130 else if (typ == 3) todraw = regn && !outl;
131 else todraw = !(intl || (reg1 && !outl));
133 if (!S.IsNull()) todraw = Map.Contains(BP.Shape());
135 const gp_Pnt2d& FirstP2d = BP.P1();
136 const gp_Pnt2d& LastP2d = BP.P2();
137 if (FirstP2d.SquareDistance(LastP2d) > 1.e-20)
139 B.Add(Result,BRepLib_MakeEdge2d(BP.P1(),BP.P2()));
140 added = Standard_True;
146 const gp_Trsf& T = myAlgo->Projector().Transformation();
149 for (myAlgo->InitShow(); myAlgo->MoreShow(); myAlgo->NextShow()) {
150 HLRAlgo_BiPoint::PointsT& aPoints = myAlgo->Show(SBP,reg1,regn,outl,intl);
151 if (typ == 1) todraw = intl;
152 else if (typ == 2) todraw = reg1 && !regn && !outl;
153 else if (typ == 3) todraw = regn && !outl;
154 else todraw = !(intl || (reg1 && !outl));
156 if (!S.IsNull()) todraw = Map.Contains(SBP);
158 gp_XYZ aSta = aPoints.Pnt1, aEnd = aPoints.Pnt2;
161 const gp_XY aSta2D(aSta.X(), aSta.Y());
162 const gp_XY aEnd2D(aEnd.X(), aEnd.Y());
163 const gp_XY aD = aEnd2D - aSta2D;
164 if (aD.SquareModulus() > 1.e-20) {
165 B.Add(Result,BRepLib_MakeEdge2d(aSta2D, aEnd2D));
166 added = Standard_True;
171 if (!added) Result = TopoDS_Shape();