Warnings on vc14 were eliminated
[occt.git] / src / BRepTest / BRepTest_DraftAngleCommands.cxx
CommitLineData
b311480e 1// Created on: 1995-02-22
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1995-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
17#include <BRepTest.hxx>
18#include <DBRep.hxx>
19#include <DrawTrSurf.hxx>
20#include <Draw_Appli.hxx>
21#include <Draw_Interpretor.hxx>
22
23#include <BRepOffsetAPI_DraftAngle.hxx>
24#include <BRepOffsetAPI_MakeDraft.hxx>
25#include <TopoDS.hxx>
26#include <TopoDS_Face.hxx>
27#include <gp_Pln.hxx>
28#include <gp_Dir.hxx>
29
30static void Print(Draw_Interpretor& di,
31 const Draft_ErrorStatus St)
32{
33 di << " Error Status : ";
34 switch (St) {
35 case Draft_NoError:
36 di << "No error";
37 break;
38
39 case Draft_FaceRecomputation:
40 di << "Impossible face recomputation";
41 break;
42
43 case Draft_EdgeRecomputation:
44 di << "Impossible edge recomputation";
45 break;
46
47 case Draft_VertexRecomputation:
48 di << "Impossible vertex recomputation";
49 break;
50
51 }
52}
53
54static Standard_Integer DEP(Draw_Interpretor& theCommands,
55 Standard_Integer narg, const char** a)
56{
57 if ((narg<14)||(narg%8 != 6)) return 1;
58 TopoDS_Shape V = DBRep::Get(a[2]);
59 BRepOffsetAPI_DraftAngle drft(V);
60
91322f44 61 gp_Dir Dirextract(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
7fd59977 62
63 TopoDS_Face F;
64 Standard_Real Angle;
65 gp_Pnt Pax;
66 gp_Dir Dax;
67 for (Standard_Integer ii = 0; ii < (narg-6)/8; ii++){
68 TopoDS_Shape aLocalShape(DBRep::Get(a[8*ii+6],TopAbs_FACE));
69 F = TopoDS::Face(aLocalShape);
70// F = TopoDS::Face(DBRep::Get(a[8*ii+6],TopAbs_FACE));
91322f44 71 Angle = Draw::Atof(a[8*ii+7])*M_PI/180.;
72 Pax.SetCoord(Draw::Atof(a[8*ii+8]),Draw::Atof(a[8*ii+9]),Draw::Atof(a[8*ii+10]));
73 Dax.SetCoord(Draw::Atof(a[8*ii+11]),Draw::Atof(a[8*ii+12]),Draw::Atof(a[8*ii+13]));
7fd59977 74 drft.Add(F,Dirextract,Angle,gp_Pln(Pax,Dax));
75 if (!drft.AddDone()) {
76 break;
77 }
78 }
79
80 if (!drft.AddDone()) {
81 DBRep::Set("bugdep",drft.ProblematicShape());
82 theCommands << "Bad shape in variable bugdep ";
83 Print(theCommands,drft.Status());
84 return 1;
85 }
86 drft.Build();
87 if (drft.IsDone()) {
88 DBRep::Set(a[1],drft);
89 return 0;
90 }
91 DBRep::Set("bugdep",drft.ProblematicShape());
92 theCommands << "Problem encountered during the reconstruction : ";
93 theCommands << "bad shape in variable bugdep; ";
94 Print(theCommands,drft.Status());
95 return 1;
96}
97
98
99static Standard_Integer NDEP(Draw_Interpretor& theCommands,
100 Standard_Integer narg, const char** a)
101{
102 if ((narg<15)||((narg)%9 != 6)) return 1;
103 TopoDS_Shape V = DBRep::Get(a[2]);
104 if ( V.IsNull()) {
105 //cout << a[2] << " is not a Shape" << endl;
586db386 106 theCommands << a[2] << " is not a Shape\n";
7fd59977 107 return 1;
108 }
109
110 BRepOffsetAPI_DraftAngle drft(V);
111
91322f44 112 gp_Dir Dirextract(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
7fd59977 113
114 TopoDS_Face F;
115 Standard_Real Angle;
116 gp_Pnt Pax;
117 gp_Dir Dax;
118 Standard_Boolean Flag;
119 for (Standard_Integer ii = 0; ii < (narg-6)/9; ii++){
120 TopoDS_Shape aLocalFace(DBRep::Get(a[9*ii+6],TopAbs_FACE));
121 F = TopoDS::Face(aLocalFace);
122// F = TopoDS::Face(DBRep::Get(a[9*ii+6],TopAbs_FACE));
123
124 if ( F.IsNull()) {
125 //cout << a[9*ii+6] << " is not a face" << endl;
586db386 126 theCommands << a[9*ii+6] << " is not a face\n";
7fd59977 127 return 1;
128 }
129
dde68833 130 Flag = Draw::Atoi(a[9*ii+7]) != 0;
91322f44 131 Angle = Draw::Atof(a[9*ii+8])*M_PI/180.;
132 Pax.SetCoord(Draw::Atof(a[9*ii+9]),Draw::Atof(a[9*ii+10]),Draw::Atof(a[9*ii+11]));
133 Dax.SetCoord(Draw::Atof(a[9*ii+12]),Draw::Atof(a[9*ii+13]),Draw::Atof(a[9*ii+14]));
7fd59977 134 drft.Add(F,Dirextract,Angle,gp_Pln(Pax,Dax), Flag);
135 if (!drft.AddDone()) {
136 break;
137 }
138 }
139
140 if (!drft.AddDone()) {
141 DBRep::Set("bugdep",drft.ProblematicShape());
142 theCommands << "Bad shape in variable bugdep ";
143 Print(theCommands,drft.Status());
144 return 1;
145 }
146 drft.Build();
147 if (drft.IsDone()) {
148 DBRep::Set(a[1],drft);
149 return 0;
150 }
151 DBRep::Set("bugdep",drft.ProblematicShape());
152 theCommands << "Problem encountered during the reconstruction : ";
153 theCommands << "bad shape in variable bugdep; ";
154 Print(theCommands,drft.Status());
155 return 1;
156}
157
158static Standard_Integer draft (Draw_Interpretor& di,
159 Standard_Integer n, const char** a)
160{
161 Standard_Integer Inside = -1;
162 Standard_Boolean Internal = Standard_False;
163 if (n < 8) return 1;
164
165 Standard_Real x, y ,z, teta;
166 TopoDS_Shape SInit = DBRep::Get(a[2]);//shape d'arret
167
91322f44 168 x = Draw::Atof(a[3]);
169 y = Draw::Atof(a[4]); // direction de depouille
170 z = Draw::Atof(a[5]);
171 teta = Draw::Atof(a[6]); //angle de depouille (teta)
7fd59977 172
173 gp_Dir D(x,y,z);
174
175
176
177 BRepOffsetAPI_MakeDraft MkDraft(SInit, D, teta);
178
179 if (n>8) {
180 Standard_Integer cur = 8;
181 if (!strcmp(a[cur],"-IN")) {
182 Inside = 1;
183 cur++;
184 }
185 else if (!strcmp(a[cur],"-OUT")) {
186 Inside = 0;
187 cur++;
188 }
189
190 if (cur<n) {
191 if (!strcmp(a[cur],"-Ri")) {
192 MkDraft.SetOptions(BRepBuilderAPI_RightCorner);
193 cur++;
194 }
195 else if (!strcmp(a[cur],"-Ro")) {
196 MkDraft.SetOptions(BRepBuilderAPI_RoundCorner);
197 cur++;
198 }
199 }
200 if (cur<n) {
201 if (!strcmp(a[cur],"-Internal")) {
202 Internal = Standard_True;
203 cur++;
204 }
205 }
206 }
207
208 if (Internal) {
209 MkDraft.SetDraft(Internal);
586db386 210 di << "Internal Draft : \n";
7fd59977 211 //cout << "Internal Draft : " << endl;
212 }
213 else
586db386 214 di << "External Draft : \n";
7fd59977 215 //cout << "External Draft : " << endl;
216
217 TopoDS_Shape Stop = DBRep::Get(a[7]);//shape d'arret
218 if (!Stop.IsNull()) {
219 Standard_Boolean KeepOutside = Standard_True;
220 if (Inside==0) KeepOutside = Standard_False;
221 MkDraft.Perform(Stop, KeepOutside);
222 }
223 else {
224 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[7]);
225 if (! Surf.IsNull()) { // surface d'arret
226 Standard_Boolean KeepInside = Standard_True;
227 if (Inside==1) KeepInside = Standard_False;
228 MkDraft.Perform(Surf, KeepInside);
229 }
230 else { // by Lenght
91322f44 231 Standard_Real L = Draw::Atof(a[7]);
7fd59977 232 if (L > 1.e-7) {
233 MkDraft.Perform(L);
234 }
235 else return 1;
236 }
237 }
238
239 DBRep::Set(a[1], MkDraft.Shape());
240 DBRep::Set("DraftShell", MkDraft.Shell());
241
242 return 0;
243}
244
245
246//=======================================================================
247//function : DraftAngleCommands
248//purpose :
249//=======================================================================
250
251void BRepTest::DraftAngleCommands(Draw_Interpretor& theCommands)
252{
253 static Standard_Boolean done = Standard_False;
254 if (done) return;
255 done = Standard_True;
256
257 DBRep::BasicCommands(theCommands);
258
259 const char* g = "Draft angle modification commands";
260
261 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);
262
263 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);
264
265 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]",
266 __FILE__,draft,g);
267}