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