summaryrefslogtreecommitdiff
path: root/src/BRepTest/BRepTest_DraftAngleCommands.cxx
blob: 4ec2a217c233314563234b1148a2fc9fd31e4f0a (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// File:	BRepTest_DraftAngleCommands.cxx
// Created:	Wed Feb 22 15:46:48 1995
// Author:	Jacques GOUSSARD
//		<jag@topsn2>


#include <BRepTest.hxx>
#include <DBRep.hxx>
#include <DrawTrSurf.hxx>
#include <Draw_Appli.hxx>
#include <Draw_Interpretor.hxx>

#include <BRepOffsetAPI_DraftAngle.hxx>
#include <BRepOffsetAPI_MakeDraft.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <gp_Pln.hxx>
#include <gp_Dir.hxx>

static void Print(Draw_Interpretor& di,
		  const Draft_ErrorStatus St)
{
  di << "  Error Status : ";
  switch (St) {
  case Draft_NoError:
    di << "No error";
    break;

  case Draft_FaceRecomputation:
    di << "Impossible face recomputation";
    break;

  case Draft_EdgeRecomputation:
    di << "Impossible edge recomputation";
    break;

  case Draft_VertexRecomputation:
    di << "Impossible vertex recomputation";
    break;

  }
}

static Standard_Integer DEP(Draw_Interpretor& theCommands,
                            Standard_Integer narg, const char** a)
{
  if ((narg<14)||(narg%8 != 6)) return 1;
  TopoDS_Shape V = DBRep::Get(a[2]);
  BRepOffsetAPI_DraftAngle drft(V);

  gp_Dir Dirextract(atof(a[3]),atof(a[4]),atof(a[5]));

  TopoDS_Face F;
  Standard_Real Angle;
  gp_Pnt Pax;
  gp_Dir Dax;
  for (Standard_Integer ii = 0; ii < (narg-6)/8; ii++){
    TopoDS_Shape aLocalShape(DBRep::Get(a[8*ii+6],TopAbs_FACE));
    F = TopoDS::Face(aLocalShape);
//    F = TopoDS::Face(DBRep::Get(a[8*ii+6],TopAbs_FACE));
    Angle = atof(a[8*ii+7])*PI/180.;
    Pax.SetCoord(atof(a[8*ii+8]),atof(a[8*ii+9]),atof(a[8*ii+10]));
    Dax.SetCoord(atof(a[8*ii+11]),atof(a[8*ii+12]),atof(a[8*ii+13]));
    drft.Add(F,Dirextract,Angle,gp_Pln(Pax,Dax));
    if (!drft.AddDone()) {
      break;
    }
  }

  if (!drft.AddDone()) {
    DBRep::Set("bugdep",drft.ProblematicShape());
    theCommands << "Bad shape in variable bugdep ";
    Print(theCommands,drft.Status());
    return 1;
  }
  drft.Build();
  if (drft.IsDone()) {
    DBRep::Set(a[1],drft);
    return 0;
  }
  DBRep::Set("bugdep",drft.ProblematicShape());
  theCommands << "Problem encountered during the reconstruction : ";
  theCommands << "bad shape in variable bugdep; ";
  Print(theCommands,drft.Status());
  return 1;
}


static Standard_Integer NDEP(Draw_Interpretor& theCommands,
                            Standard_Integer narg, const char** a)
{
  if ((narg<15)||((narg)%9 != 6)) return 1;
  TopoDS_Shape V = DBRep::Get(a[2]);
  if ( V.IsNull()) {
    //cout << a[2] << " is not a Shape" << endl;
    theCommands << a[2] << " is not a Shape" << "\n";
    return 1;
  }

  BRepOffsetAPI_DraftAngle drft(V);

  gp_Dir Dirextract(atof(a[3]),atof(a[4]),atof(a[5]));

  TopoDS_Face F;
  Standard_Real Angle;
  gp_Pnt Pax;
  gp_Dir Dax;
  Standard_Boolean Flag;
  for (Standard_Integer ii = 0; ii < (narg-6)/9; ii++){
    TopoDS_Shape aLocalFace(DBRep::Get(a[9*ii+6],TopAbs_FACE));
    F = TopoDS::Face(aLocalFace);
//    F = TopoDS::Face(DBRep::Get(a[9*ii+6],TopAbs_FACE));

    if ( F.IsNull()) {
      //cout << a[9*ii+6] << " is not a face" << endl;
      theCommands << a[9*ii+6] << " is not a face" << "\n";
      return 1;
    }

//#ifdef DEB
//    Flag = atof(a[9*ii+7]); // BUG?? Real -> Boolean ???
//#else
    Flag = (Standard_Boolean ) atof(a[9*ii+7]);
//#endif
    Angle = atof(a[9*ii+8])*PI/180.;
    Pax.SetCoord(atof(a[9*ii+9]),atof(a[9*ii+10]),atof(a[9*ii+11]));
    Dax.SetCoord(atof(a[9*ii+12]),atof(a[9*ii+13]),atof(a[9*ii+14]));
    drft.Add(F,Dirextract,Angle,gp_Pln(Pax,Dax), Flag);
    if (!drft.AddDone()) {
      break;
    }
  }

  if (!drft.AddDone()) {
    DBRep::Set("bugdep",drft.ProblematicShape());
    theCommands << "Bad shape in variable bugdep ";
    Print(theCommands,drft.Status());
    return 1;
  }
  drft.Build();
  if (drft.IsDone()) {
    DBRep::Set(a[1],drft);
    return 0;
  }
  DBRep::Set("bugdep",drft.ProblematicShape());
  theCommands << "Problem encountered during the reconstruction : ";
  theCommands << "bad shape in variable bugdep; ";
  Print(theCommands,drft.Status());
  return 1;
}

static Standard_Integer draft (Draw_Interpretor& di,
				   Standard_Integer n, const char** a)
{
  Standard_Integer Inside = -1;
  Standard_Boolean Internal = Standard_False;
  if (n < 8) return 1;

  Standard_Real x, y ,z, teta;
  TopoDS_Shape SInit = DBRep::Get(a[2]);//shape d'arret
  
  x = atof(a[3]);   
  y = atof(a[4]);  // direction de depouille
  z = atof(a[5]);  
  teta = atof(a[6]); //angle de depouille (teta)

  gp_Dir D(x,y,z);
 


  BRepOffsetAPI_MakeDraft MkDraft(SInit, D, teta);

  if (n>8) {
    Standard_Integer cur = 8;
    if (!strcmp(a[cur],"-IN")) {
     Inside = 1;
     cur++;
    }
    else if (!strcmp(a[cur],"-OUT")) {
      Inside = 0;
     cur++; 
    }

    if (cur<n) {
      if (!strcmp(a[cur],"-Ri")) {
	MkDraft.SetOptions(BRepBuilderAPI_RightCorner);
	cur++;
      }
      else if (!strcmp(a[cur],"-Ro")) {
	MkDraft.SetOptions(BRepBuilderAPI_RoundCorner);
	cur++;
      }      
    }
    if (cur<n) {
      if (!strcmp(a[cur],"-Internal")) {
	Internal = Standard_True;
	cur++;
      }
    }
  }  

  if (Internal) {
    MkDraft.SetDraft(Internal);
    di << "Internal Draft : " << "\n";
    //cout << "Internal Draft : " << endl;
  }
  else
    di << "External Draft : " << "\n";
    //cout << "External Draft : " << endl;

  TopoDS_Shape Stop = DBRep::Get(a[7]);//shape d'arret 
  if (!Stop.IsNull()) {
    Standard_Boolean KeepOutside = Standard_True;
    if (Inside==0)  KeepOutside = Standard_False;
    MkDraft.Perform(Stop,  KeepOutside);
  }
  else {
    Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[7]); 
    if (! Surf.IsNull()) { // surface d'arret
      Standard_Boolean KeepInside = Standard_True;
      if (Inside==1)  KeepInside = Standard_False;
      MkDraft.Perform(Surf, KeepInside);
    }
    else {  // by Lenght
      Standard_Real L = atof(a[7]);
      if (L > 1.e-7) {
	 MkDraft.Perform(L);
      }
      else  return 1;
    }
  }
 
  DBRep::Set(a[1], MkDraft.Shape());
  DBRep::Set("DraftShell", MkDraft.Shell());

  return 0;
}


//=======================================================================
//function : DraftAngleCommands
//purpose  : 
//=======================================================================

void  BRepTest::DraftAngleCommands(Draw_Interpretor& theCommands)
{
  static Standard_Boolean done = Standard_False;
  if (done) return;
  done = Standard_True;

  DBRep::BasicCommands(theCommands);

  const char* g = "Draft angle modification commands";
   
  theCommands.Add("depouille", " Inclines faces of a shape, dep result shape dirx diry dirz face angle x y x dx dy dz [face angle...]",__FILE__,DEP,g);

  theCommands.Add("ndepouille", " Inclines faces of a shape, dep result shape dirx diry dirz face 0/1 angle x y x dx dy dz [face 0/1 angle...]",__FILE__,NDEP,g);

 theCommands.Add("draft"," Compute a draft surface along a shape, \n draft result shape dirx diry dirz  angle shape/surf/length [-IN/-OUT] [Ri/Ro] [-Internal]",
		 __FILE__,draft,g);
}