0022898: IGES import fails in german environment
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <BRepTest.hxx>
24#include <DBRep.hxx>
25#include <DrawTrSurf.hxx>
26#include <Draw_Appli.hxx>
27#include <Draw_Interpretor.hxx>
28
29#include <BRepOffsetAPI_DraftAngle.hxx>
30#include <BRepOffsetAPI_MakeDraft.hxx>
31#include <TopoDS.hxx>
32#include <TopoDS_Face.hxx>
33#include <gp_Pln.hxx>
34#include <gp_Dir.hxx>
35
36static void Print(Draw_Interpretor& di,
37 const Draft_ErrorStatus St)
38{
39 di << " Error Status : ";
40 switch (St) {
41 case Draft_NoError:
42 di << "No error";
43 break;
44
45 case Draft_FaceRecomputation:
46 di << "Impossible face recomputation";
47 break;
48
49 case Draft_EdgeRecomputation:
50 di << "Impossible edge recomputation";
51 break;
52
53 case Draft_VertexRecomputation:
54 di << "Impossible vertex recomputation";
55 break;
56
57 }
58}
59
60static Standard_Integer DEP(Draw_Interpretor& theCommands,
61 Standard_Integer narg, const char** a)
62{
63 if ((narg<14)||(narg%8 != 6)) return 1;
64 TopoDS_Shape V = DBRep::Get(a[2]);
65 BRepOffsetAPI_DraftAngle drft(V);
66
91322f44 67 gp_Dir Dirextract(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
7fd59977 68
69 TopoDS_Face F;
70 Standard_Real Angle;
71 gp_Pnt Pax;
72 gp_Dir Dax;
73 for (Standard_Integer ii = 0; ii < (narg-6)/8; ii++){
74 TopoDS_Shape aLocalShape(DBRep::Get(a[8*ii+6],TopAbs_FACE));
75 F = TopoDS::Face(aLocalShape);
76// F = TopoDS::Face(DBRep::Get(a[8*ii+6],TopAbs_FACE));
91322f44 77 Angle = Draw::Atof(a[8*ii+7])*M_PI/180.;
78 Pax.SetCoord(Draw::Atof(a[8*ii+8]),Draw::Atof(a[8*ii+9]),Draw::Atof(a[8*ii+10]));
79 Dax.SetCoord(Draw::Atof(a[8*ii+11]),Draw::Atof(a[8*ii+12]),Draw::Atof(a[8*ii+13]));
7fd59977 80 drft.Add(F,Dirextract,Angle,gp_Pln(Pax,Dax));
81 if (!drft.AddDone()) {
82 break;
83 }
84 }
85
86 if (!drft.AddDone()) {
87 DBRep::Set("bugdep",drft.ProblematicShape());
88 theCommands << "Bad shape in variable bugdep ";
89 Print(theCommands,drft.Status());
90 return 1;
91 }
92 drft.Build();
93 if (drft.IsDone()) {
94 DBRep::Set(a[1],drft);
95 return 0;
96 }
97 DBRep::Set("bugdep",drft.ProblematicShape());
98 theCommands << "Problem encountered during the reconstruction : ";
99 theCommands << "bad shape in variable bugdep; ";
100 Print(theCommands,drft.Status());
101 return 1;
102}
103
104
105static Standard_Integer NDEP(Draw_Interpretor& theCommands,
106 Standard_Integer narg, const char** a)
107{
108 if ((narg<15)||((narg)%9 != 6)) return 1;
109 TopoDS_Shape V = DBRep::Get(a[2]);
110 if ( V.IsNull()) {
111 //cout << a[2] << " is not a Shape" << endl;
112 theCommands << a[2] << " is not a Shape" << "\n";
113 return 1;
114 }
115
116 BRepOffsetAPI_DraftAngle drft(V);
117
91322f44 118 gp_Dir Dirextract(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
7fd59977 119
120 TopoDS_Face F;
121 Standard_Real Angle;
122 gp_Pnt Pax;
123 gp_Dir Dax;
124 Standard_Boolean Flag;
125 for (Standard_Integer ii = 0; ii < (narg-6)/9; ii++){
126 TopoDS_Shape aLocalFace(DBRep::Get(a[9*ii+6],TopAbs_FACE));
127 F = TopoDS::Face(aLocalFace);
128// F = TopoDS::Face(DBRep::Get(a[9*ii+6],TopAbs_FACE));
129
130 if ( F.IsNull()) {
131 //cout << a[9*ii+6] << " is not a face" << endl;
132 theCommands << a[9*ii+6] << " is not a face" << "\n";
133 return 1;
134 }
135
136//#ifdef DEB
91322f44 137// Flag = Draw::Atof(a[9*ii+7]); // BUG?? Real -> Boolean ???
7fd59977 138//#else
91322f44 139 Flag = (Standard_Boolean ) Draw::Atof(a[9*ii+7]);
7fd59977 140//#endif
91322f44 141 Angle = Draw::Atof(a[9*ii+8])*M_PI/180.;
142 Pax.SetCoord(Draw::Atof(a[9*ii+9]),Draw::Atof(a[9*ii+10]),Draw::Atof(a[9*ii+11]));
143 Dax.SetCoord(Draw::Atof(a[9*ii+12]),Draw::Atof(a[9*ii+13]),Draw::Atof(a[9*ii+14]));
7fd59977 144 drft.Add(F,Dirextract,Angle,gp_Pln(Pax,Dax), Flag);
145 if (!drft.AddDone()) {
146 break;
147 }
148 }
149
150 if (!drft.AddDone()) {
151 DBRep::Set("bugdep",drft.ProblematicShape());
152 theCommands << "Bad shape in variable bugdep ";
153 Print(theCommands,drft.Status());
154 return 1;
155 }
156 drft.Build();
157 if (drft.IsDone()) {
158 DBRep::Set(a[1],drft);
159 return 0;
160 }
161 DBRep::Set("bugdep",drft.ProblematicShape());
162 theCommands << "Problem encountered during the reconstruction : ";
163 theCommands << "bad shape in variable bugdep; ";
164 Print(theCommands,drft.Status());
165 return 1;
166}
167
168static Standard_Integer draft (Draw_Interpretor& di,
169 Standard_Integer n, const char** a)
170{
171 Standard_Integer Inside = -1;
172 Standard_Boolean Internal = Standard_False;
173 if (n < 8) return 1;
174
175 Standard_Real x, y ,z, teta;
176 TopoDS_Shape SInit = DBRep::Get(a[2]);//shape d'arret
177
91322f44 178 x = Draw::Atof(a[3]);
179 y = Draw::Atof(a[4]); // direction de depouille
180 z = Draw::Atof(a[5]);
181 teta = Draw::Atof(a[6]); //angle de depouille (teta)
7fd59977 182
183 gp_Dir D(x,y,z);
184
185
186
187 BRepOffsetAPI_MakeDraft MkDraft(SInit, D, teta);
188
189 if (n>8) {
190 Standard_Integer cur = 8;
191 if (!strcmp(a[cur],"-IN")) {
192 Inside = 1;
193 cur++;
194 }
195 else if (!strcmp(a[cur],"-OUT")) {
196 Inside = 0;
197 cur++;
198 }
199
200 if (cur<n) {
201 if (!strcmp(a[cur],"-Ri")) {
202 MkDraft.SetOptions(BRepBuilderAPI_RightCorner);
203 cur++;
204 }
205 else if (!strcmp(a[cur],"-Ro")) {
206 MkDraft.SetOptions(BRepBuilderAPI_RoundCorner);
207 cur++;
208 }
209 }
210 if (cur<n) {
211 if (!strcmp(a[cur],"-Internal")) {
212 Internal = Standard_True;
213 cur++;
214 }
215 }
216 }
217
218 if (Internal) {
219 MkDraft.SetDraft(Internal);
220 di << "Internal Draft : " << "\n";
221 //cout << "Internal Draft : " << endl;
222 }
223 else
224 di << "External Draft : " << "\n";
225 //cout << "External Draft : " << endl;
226
227 TopoDS_Shape Stop = DBRep::Get(a[7]);//shape d'arret
228 if (!Stop.IsNull()) {
229 Standard_Boolean KeepOutside = Standard_True;
230 if (Inside==0) KeepOutside = Standard_False;
231 MkDraft.Perform(Stop, KeepOutside);
232 }
233 else {
234 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[7]);
235 if (! Surf.IsNull()) { // surface d'arret
236 Standard_Boolean KeepInside = Standard_True;
237 if (Inside==1) KeepInside = Standard_False;
238 MkDraft.Perform(Surf, KeepInside);
239 }
240 else { // by Lenght
91322f44 241 Standard_Real L = Draw::Atof(a[7]);
7fd59977 242 if (L > 1.e-7) {
243 MkDraft.Perform(L);
244 }
245 else return 1;
246 }
247 }
248
249 DBRep::Set(a[1], MkDraft.Shape());
250 DBRep::Set("DraftShell", MkDraft.Shell());
251
252 return 0;
253}
254
255
256//=======================================================================
257//function : DraftAngleCommands
258//purpose :
259//=======================================================================
260
261void BRepTest::DraftAngleCommands(Draw_Interpretor& theCommands)
262{
263 static Standard_Boolean done = Standard_False;
264 if (done) return;
265 done = Standard_True;
266
267 DBRep::BasicCommands(theCommands);
268
269 const char* g = "Draft angle modification commands";
270
271 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);
272
273 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);
274
275 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]",
276 __FILE__,draft,g);
277}