summaryrefslogtreecommitdiff
path: root/src/HLRBRep/HLRBRep_PolyHLRToShape.cxx
blob: f831f765a815c3e952446f982f991fa31994553f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// File:	HLRBRep_PolyHLRToShape.cxx
// Created:	Mon Oct 11 16:55:56 1993
// Author:	Christophe MARION
//		<cma@nonox>
// Modified by cma, Fri Nov 10 17:36:13 1995

#include <HLRBRep_PolyHLRToShape.ixx>
#include <BRep_Builder.hxx>
#include <BRepLib_MakeEdge2d.hxx>
#include <TopoDS.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_MapOfShape.hxx>
#include <HLRBRep_BiPnt2D.hxx>
#include <HLRBRep_ListIteratorOfListOfBPnt2D.hxx>
#include <HLRAlgo_EdgeStatus.hxx>
#include <HLRAlgo_EdgeIterator.hxx>

#define PntX1 ((Standard_Real*)Coordinates)[0]
#define PntY1 ((Standard_Real*)Coordinates)[1]
#define PntZ1 ((Standard_Real*)Coordinates)[2]
#define PntX2 ((Standard_Real*)Coordinates)[3]
#define PntY2 ((Standard_Real*)Coordinates)[4]
#define PntZ2 ((Standard_Real*)Coordinates)[5]

//=======================================================================
//function : HLRBRep_PolyHLRToShape
//purpose  : 
//=======================================================================

HLRBRep_PolyHLRToShape::HLRBRep_PolyHLRToShape ()
{}

//=======================================================================
//function : Update
//purpose  : 
//=======================================================================

void HLRBRep_PolyHLRToShape::Update (const Handle(HLRBRep_PolyAlgo)& A)
{
  myAlgo = A;
  myHideMode = Standard_True;
  Standard_Real sta,end,XSta,YSta,ZSta,XEnd,YEnd,ZEnd,dx,dy;
  Standard_ShortReal tolsta,tolend;
  HLRAlgo_EdgeIterator It;
  myBiPntVis.Clear();
  myBiPntHid.Clear();
  TopoDS_Shape S;
  Standard_Boolean reg1,regn,outl,intl;
  const gp_Trsf& T = myAlgo->Projector().Transformation();
  HLRAlgo_EdgeStatus status;
  Standard_Address Coordinates;

  for (myAlgo->InitHide(); myAlgo->MoreHide(); myAlgo->NextHide()) {
    myAlgo->Hide(Coordinates,status,S,reg1,regn,outl,intl);
    XSta = PntX1;
    YSta = PntY1;
    ZSta = PntZ1;
    XEnd = PntX2;
    YEnd = PntY2;
    ZEnd = PntZ2;
    T.Transforms(XSta,YSta,ZSta);
    T.Transforms(XEnd,YEnd,ZEnd);
    dx = XEnd - XSta;
    dy = YEnd - YSta;
    if (sqrt(dx * dx + dy * dy) > 1.e-10) {
    
      for (It.InitVisible(status);
	   It.MoreVisible();
	   It.NextVisible()) {
	It.Visible(sta,tolsta,end,tolend);
	myBiPntVis.Append
	  (HLRBRep_BiPnt2D
	   (XSta + sta * dx,YSta + sta * dy,
	    XSta + end * dx,YSta + end * dy,
	    S,reg1,regn,outl,intl));
      }
      
      for (It.InitHidden(status);
	   It.MoreHidden();
	   It.NextHidden()) {
	It.Hidden(sta,tolsta,end,tolend);
	myBiPntHid.Append
	  (HLRBRep_BiPnt2D
	   (XSta + sta * dx,YSta + sta * dy,
	    XSta + end * dx,YSta + end * dy,
	    S,reg1,regn,outl,intl));
      }
    }
  }
}

//=======================================================================
//function : InternalCompound
//purpose  : 
//=======================================================================

TopoDS_Shape 
HLRBRep_PolyHLRToShape::InternalCompound (const Standard_Integer typ,
					  const Standard_Boolean visible,
					  const TopoDS_Shape& S)
{
  TopTools_MapOfShape Map;
  if (!S.IsNull()) {
    TopExp_Explorer ex;
    for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next())
      Map.Add(ex.Current());
    for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next())
      Map.Add(ex.Current());
  }
  Standard_Boolean todraw,reg1,regn,outl,intl;
  Standard_Boolean added = Standard_False;
  TopoDS_Shape Result;
  BRep_Builder B;
  B.MakeCompound(TopoDS::Compound(Result));

  if (myHideMode) {
    HLRBRep_ListIteratorOfListOfBPnt2D It;
    if (visible) It.Initialize(myBiPntVis);
    else         It.Initialize(myBiPntHid);
    
    for (; It.More(); It.Next()) {
      const HLRBRep_BiPnt2D& BP = It.Value();
      reg1 = BP.Rg1Line();
      regn = BP.RgNLine();
      outl = BP.OutLine();
      intl = BP.IntLine();
      if      (typ == 1) todraw =  intl;
      else if (typ == 2) todraw =  reg1 && !regn && !outl;
      else if (typ == 3) todraw =  regn && !outl;
      else               todraw = !(intl || (reg1 && !outl));
      if (todraw)
	if (!S.IsNull()) todraw = Map.Contains(BP.Shape());
      if (todraw) {
	B.Add(Result,BRepLib_MakeEdge2d(BP.P1(),BP.P2()));
	added = Standard_True;
      }
    }
  }
  else {
    const gp_Trsf& T = myAlgo->Projector().Transformation();
    TopoDS_Shape SBP;
    Standard_Real XSta,YSta,ZSta,XEnd,YEnd,ZEnd,dx,dy;
    Standard_Address Coordinates;

    for (myAlgo->InitShow(); myAlgo->MoreShow(); myAlgo->NextShow()) {
      myAlgo->Show(Coordinates,SBP,reg1,regn,outl,intl);
      if      (typ == 1) todraw =  intl;
      else if (typ == 2) todraw =  reg1 && !regn && !outl;
      else if (typ == 3) todraw =  regn && !outl;
      else               todraw = !(intl || (reg1 && !outl));
      if (todraw)
	if (!S.IsNull()) todraw = Map.Contains(SBP);
      if (todraw) {
	XSta = PntX1;
	YSta = PntY1;
	ZSta = PntZ1;
	XEnd = PntX2;
	YEnd = PntY2;
	ZEnd = PntZ2;
	T.Transforms(XSta,YSta,ZSta);
	T.Transforms(XEnd,YEnd,ZEnd);
	dx = XEnd - XSta;
	dy = YEnd - YSta;
	if (sqrt(dx * dx + dy * dy) > 1.e-10) {
	  B.Add(Result,BRepLib_MakeEdge2d(gp_Pnt2d(XSta,YSta),
					  gp_Pnt2d(XEnd,YEnd)));
	  added = Standard_True;
	}
      }
    }
  }
  if (!added) Result = TopoDS_Shape();
  return Result;
}