0022898: IGES import fails in german environment
[occt.git] / src / QANewDBRepNaming / QANewDBRepNaming_FeatureCommands.cxx
CommitLineData
b311480e 1// Created on: 1999-12-23
2// Created by: Vladislav ROMASHKO
3// Copyright (c) 1999-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 <QANewDBRepNaming.ixx>
24
25#include <Draw.hxx>
26#include <Draw_Interpretor.hxx>
27#include <QANewDBRepNaming.hxx>
28#include <DBRep.hxx>
29
30#include <DDocStd.hxx>
31
32#include <DDF.hxx>
33
34#include <TDocStd_Document.hxx>
35#include <TDataXtd_Geometry.hxx>
36
37#include <TNaming_NamedShape.hxx>
38#include <TNaming_Tool.hxx>
39#include <TNaming_Builder.hxx>
40
41#include <TopTools_MapOfShape.hxx>
42#include <TopTools_MapIteratorOfMapOfShape.hxx>
43
44#include <TopoDS.hxx>
45#include <TopoDS_Shape.hxx>
46#include <TopoDS_Face.hxx>
47#include <TopoDS_Wire.hxx>
48#include <TopoDS_Edge.hxx>
49#include <TopoDS_Iterator.hxx>
50
51#include <TopExp.hxx>
52#include <TopExp_Explorer.hxx>
53
54#include <BRepAdaptor_Surface.hxx>
55#include <BRepAdaptor_Curve.hxx>
56
57#include <BRep_Tool.hxx>
58
59#include <BRepAlgoAPI_Fuse.hxx>
60#include <BRepAlgoAPI_Common.hxx>
61#include <BRepAlgoAPI_Cut.hxx>
62#include <BRepAlgoAPI_Section.hxx>
63
64#include <QANewModTopOpe_Limitation.hxx>
65#include <QANewModTopOpe_Intersection.hxx>
66
91a16bc7 67#include <Standard_Assert.hxx>
7fd59977 68
69#include <BRepBuilderAPI_MakeEdge.hxx>
70#include <BRepBuilderAPI_MakeFace.hxx>
71#include <BRepBuilderAPI_MakeWire.hxx>
72
73#include <BRepLib.hxx>
74
75#include <TColgp_Array1OfPnt.hxx>
76
77#include <GCE2d_MakeLine.hxx>
78
79#include <gp_Pnt.hxx>
80#include <gp_Ax1.hxx>
81#include <gp_Dir.hxx>
82#include <gp_Vec.hxx>
83
84#include <QANewBRepNaming_Fuse.hxx>
85#include <QANewBRepNaming_Cut.hxx>
86#include <QANewBRepNaming_Common.hxx>
87#include <QANewBRepNaming_Intersection.hxx>
88#include <QANewBRepNaming_Limitation.hxx>
89
90#include <BRepTools.hxx>
91#include <TDF_LabelMap.hxx>
92#include <QANewModTopOpe_Glue.hxx>
93#include <QANewBRepNaming_Gluing.hxx>
94
95//==============================================================
96//function : QANewDBRepNaming_NameBooleanOperationFeat
97//purpose : NameBooleanOperationFeat Doc Label Op = 1(Fuse), 2(Cut), 3(Common), 4(Inserction) 5(Limitation) DrawShape1 DrawShape2 [Forward = 0 || Reversed = 1 || BothSides = 2]
98//==============================================================
99
100static Standard_Integer QANewDBRepNaming_NameBooleanOperationFeat (Draw_Interpretor& di,
101 Standard_Integer nb,
102 const char ** arg)
103{
a7ae5c81 104 if (nb != 6 && nb != 7) {
7fd59977 105 di << "QANewDBRepNaming_NameBooleanOperationFeat : Error" << "\n";
106 return 1;
107 }
108
109 Handle(TDocStd_Document) D;
110 if (!DDocStd::GetDocument(arg[1],D)) return 1;
111 TDF_Label L;
112 if (!DDF::AddLabel(D->GetData(), arg[2], L)) return 1;
113
91322f44 114 const Standard_Integer Op = (Standard_Integer)Draw::Atoi(arg[3]);
7fd59977 115 const TopoDS_Shape& S1 = DBRep::Get(arg[4]);
116 const TopoDS_Shape& S2 = DBRep::Get(arg[5]);
117
118 Standard_Integer Orientation = 0;
91322f44 119 if (nb == 7) Orientation = Draw::Atoi(arg[6]);
7fd59977 120
121 switch (Op) {
122 case 1: {
123 di << "BRepAlgoAPI_Fuse" << "\n";
124 BRepAlgoAPI_Fuse mkFuse(S1, S2);
125
91a16bc7 126 Standard_ASSERT_RAISE(mkFuse.IsDone(), "Fuse failed");
7fd59977 127 QANewBRepNaming_Fuse nameBool(L);
128 nameBool.Load(mkFuse);
129 break;
130 }
131 case 2: {
132 di << "BRepAlgoAPI_Cut" << "\n";
133 BRepAlgoAPI_Cut mkCut(S1, S2);
134
91a16bc7 135 Standard_ASSERT_RAISE(mkCut.IsDone(), "Cut failed");
7fd59977 136 QANewBRepNaming_Cut nameBool(L);
137 nameBool.Load(mkCut);
138 break;
139 }
140 case 3: {
141 di << "BRepAlgoAPI_Common" << "\n";
142 BRepAlgoAPI_Common mkCommon(S1, S2);
143
91a16bc7 144 Standard_ASSERT_RAISE(mkCommon.IsDone(), "Common failed");
7fd59977 145 QANewBRepNaming_Common nameBool(L);
146 nameBool.Load(mkCommon);
147 break;
148 }
149 case 4: {
150 QANewModTopOpe_Intersection mkSection(S1, S2);
91a16bc7 151 Standard_ASSERT_RAISE(mkSection.IsDone(), "Section failed");
7fd59977 152 QANewBRepNaming_Intersection nameBool(L);
153 nameBool.Load(mkSection);
154 break;
155 }
156 case 5: {
157 QANewModTopOpe_Limitation mkLimit(S1, S2);
158 const QANewModTopOpe_ModeOfLimitation aMode = (QANewModTopOpe_ModeOfLimitation) Orientation;
159 mkLimit.SetMode(aMode);
160 mkLimit.Cut();
161// if (Orientation = 0) mkLimit.CutForward();
162// else if (Orientation = 1) mkLimit.CutReversed();
163// else if (Orientation = 2) mkLimit.CutBothSides();
91a16bc7 164 Standard_ASSERT_RAISE(mkLimit.IsDone(),"Limit failed");
7fd59977 165 QANewBRepNaming_Limitation nameBool(L);
166 nameBool.Load(mkLimit);
167 break;
168 }
169 default:
170 di<<"QANewDBRepNaming_NameBooleanOperation The type of operation must be 1 - fuse, 2 - cut or 3 - common"<<"\n";
171 }
172
173 return 0;
174}
175
176//==============================================================
177//function : QANewDBRepNaming_NameFuse
178//purpose : NameFuse Doc Label DrawShape1 DrawShape2
179//==============================================================
180
181static Standard_Integer QANewDBRepNaming_NameFuse (Draw_Interpretor& di,
182 Standard_Integer nb,
183 const char ** arg)
184{
185 if (nb != 5) {
186 di << "QANewDBRepNaming_NameFuse : Error" << "\n";
187 return 1;
188 }
189
190 Handle(TDocStd_Document) D;
191 if (!DDocStd::GetDocument(arg[1],D)) return 1;
192 TDF_Label L;
193 if (!DDF::AddLabel(D->GetData(), arg[2], L)) return 1;
194 const TopoDS_Shape& S1 = DBRep::Get(arg[3]);
195 const TopoDS_Shape& S2 = DBRep::Get(arg[4]);
196 QANewBRepNaming_Fuse nameBool(L);
197
198 di << "BRepAlgoAPI_Fuse" << "\n";
199 BRepAlgoAPI_Fuse mkFuse(S1, S2);
200
91a16bc7 201 Standard_ASSERT_RAISE(mkFuse.IsDone(), "Fuse failed");
7fd59977 202 nameBool.Load(mkFuse);
203 return 0;
204}
205
206//==============================================================
207//function : QANewDBRepNaming_NameCut
208//purpose : NameCut Doc Label DrawShape1 DrawShape2
209//==============================================================
210
211static Standard_Integer QANewDBRepNaming_NameCut (Draw_Interpretor& di,
212 Standard_Integer nb,
213 const char ** arg)
214{
215 if (nb != 5) {
216 di << "QANewDBRepNaming_NameCut : Error" << "\n";
217 return 1;
218 }
219
220 Handle(TDocStd_Document) D;
221 if (!DDocStd::GetDocument(arg[1],D)) return 1;
222 TDF_Label L;
223 if (!DDF::AddLabel(D->GetData(), arg[2], L)) return 1;
224 const TopoDS_Shape& S1 = DBRep::Get(arg[3]);
225 const TopoDS_Shape& S2 = DBRep::Get(arg[4]);
226// DBRep::Set("aShape", S1);
227 QANewBRepNaming_Cut nameBool(L);
228// DBRep::Set("S1", S1);
229// DBRep::Set("S2", S2);
230
231 di << "BRepAlgoAPI_Cut" << "\n";
232 BRepAlgoAPI_Cut mkCut(S1, S2);
233
234// DBRep::Set("CutRes", mkCut.Shape());
235// DBRep::Set("Shape1", mkCut.Shape1());
236// DBRep::Set("Shape2", mkCut.Shape2());
237// BRepTools::Write(mkCut.Shape1(), "/dn04/OS/SAMTECH/env/S1.brep");
91a16bc7 238 Standard_ASSERT_RAISE(mkCut.IsDone(), "Cut failed");
7fd59977 239 nameBool.Load(mkCut);
240// BRepTools::Write(mkCut.Shape1(), "/dn04/OS/SAMTECH/env/S2.brep");
241 return 0;
242}
243
244//==============================================================
245//function : QANewDBRepNaming_NameCommon
246//purpose : NameCommon Doc Label DrawShape1 DrawShape2
247//==============================================================
248
249static Standard_Integer QANewDBRepNaming_NameCommon (Draw_Interpretor& di,
250 Standard_Integer nb,
251 const char ** arg)
252{
253 if (nb != 5) {
254 di << "QANewDBRepNaming_NameCommon : Error" << "\n";
255 return 1;
256 }
257
258 Handle(TDocStd_Document) D;
259 if (!DDocStd::GetDocument(arg[1],D)) return 1;
260 TDF_Label L;
261 if (!DDF::AddLabel(D->GetData(), arg[2], L)) return 1;
262 const TopoDS_Shape& S1 = DBRep::Get(arg[3]);
263 const TopoDS_Shape& S2 = DBRep::Get(arg[4]);
264 QANewBRepNaming_Common nameBool(L);
265
266 di << "BRepAlgoAPI_Common" << "\n";
267 BRepAlgoAPI_Common mkCommon(S1, S2);
268
91a16bc7 269 Standard_ASSERT_RAISE(mkCommon.IsDone(), "Common failed");
7fd59977 270 nameBool.Load(mkCommon);
271 return 0;
272}
273
274//==============================================================
275//function : QANewDBRepNaming_NameIntersection
276//purpose : NameIntersection Doc Label DrawShape1 DrawShape2
277//==============================================================
278
279static Standard_Integer QANewDBRepNaming_NameIntersection (Draw_Interpretor& di,
280 Standard_Integer nb,
281 const char ** arg)
282{
283 if (nb != 5) {
284 di << "QANewDBRepNaming_NameIntersection : Error" << "\n";
285 return 1;
286 }
287
288 Handle(TDocStd_Document) D;
289 if (!DDocStd::GetDocument(arg[1],D)) return 1;
290 TDF_Label L;
291 if (!DDF::AddLabel(D->GetData(), arg[2], L)) return 1;
292 const TopoDS_Shape& S1 = DBRep::Get(arg[3]);
293 const TopoDS_Shape& S2 = DBRep::Get(arg[4]);
294 QANewBRepNaming_Intersection nameBool(L);
295 QANewModTopOpe_Intersection mkIntersection(S1, S2);
91a16bc7 296 Standard_ASSERT_RAISE(mkIntersection.IsDone(), "Section failed");
7fd59977 297 nameBool.Load(mkIntersection);
298 return 0;
299}
300
301//==============================================================
302//function : QANewDBRepNaming_NameLimit
303//purpose : NameLimit Doc Label DrawShape1 DrawShape2 [Orientation (Forward - 0, Reversed - 1 or BothSise - 2)]
304//==============================================================
305
306static Standard_Integer QANewDBRepNaming_NameLimit (Draw_Interpretor& di,
307 Standard_Integer nb,
308 const char ** arg)
309{
310 if (nb != 5 && nb != 6) {
311 di << "QANewDBRepNaming_NameLimit : Error" << "\n";
312 return 1;
313 }
314
315 Handle(TDocStd_Document) D;
316 if (!DDocStd::GetDocument(arg[1],D)) return 1;
317 TDF_Label L;
318 if (!DDF::AddLabel(D->GetData(), arg[2], L)) return 1;
319 const TopoDS_Shape& S1 = DBRep::Get(arg[3]);
320 const TopoDS_Shape& S2 = DBRep::Get(arg[4]);
321 Standard_Integer Orientation = 0;
322 if (nb == 6) {
91322f44 323 Orientation = Draw::Atoi(arg[5]);
7fd59977 324 }
325 QANewBRepNaming_Limitation nameBool(L);
326 const QANewModTopOpe_ModeOfLimitation aMode = (QANewModTopOpe_ModeOfLimitation) Orientation;
327 QANewModTopOpe_Limitation mkLimit(S1, S2, aMode);
328 mkLimit.Cut();
329 // if (Orientation == 0) mkLimit.CutForward();
330// else if (Orientation == 1) mkLimit.CutReversed();
331// else if (Orientation == 2) mkLimit.CutBothSides();
91a16bc7 332 Standard_ASSERT_RAISE(mkLimit.IsDone(), "Limit failed");
7fd59977 333 nameBool.Load(mkLimit);
334 return 0;
335}
336
337//==============================================================
338//function : QANewDBRepNaming_NameGlue
339//purpose : NameGlue Doc Label ObjectLabel ToolLabel [auxiliary valid labels]
340//==============================================================
341
342static Standard_Integer QANewDBRepNaming_NameGlue (Draw_Interpretor& di,
343 Standard_Integer nb,
344 const char ** arg)
345{
346 if (nb < 5) {
347 di << "QANewDBRepNaming_NameGlue : Error" << "\n";
348 return 1;
349 }
350
351 Handle(TDocStd_Document) D;
352 if (!DDocStd::GetDocument(arg[1],D)) return 1;
353 TDF_Label L,OL,TL;
354 if (!DDF::AddLabel(D->GetData(), arg[2], L)) return 1;
355 if (!DDF::AddLabel(D->GetData(), arg[3], OL)) return 1;
356 if (!DDF::AddLabel(D->GetData(), arg[4], TL)) return 1;
357 TDF_LabelMap aLog;
358 for(Standard_Integer i=5;i<nb;i++) {
359 TDF_Label aLabel;
360 if (!DDF::AddLabel(D->GetData(), arg[i], aLabel)) return 1;
361 aLog.Add(aLabel);
362 }
363 Handle(TNaming_NamedShape) anObjectNS,aToolNS;
364 if (!OL.FindAttribute(TNaming_NamedShape::GetID(),anObjectNS)) return 1;
365 if (!TL.FindAttribute(TNaming_NamedShape::GetID(),aToolNS)) return 1;
366
367 QANewModTopOpe_Glue aMKGlue(TNaming_Tool::CurrentShape(anObjectNS),TNaming_Tool::CurrentShape(aToolNS));
368 if (!aMKGlue.IsDone()) return 1;
369 aMKGlue.Build();
370 if (!aMKGlue.IsDone()) return 1;
371
372 QANewBRepNaming_Gluing aGlue(L);
373 aGlue.SetContext(TNaming_Tool::CurrentShape(anObjectNS),TNaming_Tool::CurrentShape(aToolNS));
374 aGlue.SetLog(aLog);
375 aGlue.Load(aMKGlue);
376 return 0;
377}
378
379//=======================================================================
380//function : FeatureCommands
381//purpose :
382//=======================================================================
383
384void QANewDBRepNaming::FeatureCommands (Draw_Interpretor& theCommands)
385{
386 static Standard_Boolean done = Standard_False;
387 if (done) return;
388 done = Standard_True;
389 const char* g = "Naming algorithm commands for features" ;
390
391
392 theCommands.Add ("NameBooleanOperationFeat",
393 "NameBooleanOperationFeat Doc Label Operation(1, 2, 3, 4 or 5) DrawShape1 DrawShape2 [Forward = 0 || Reversed = 1 || BothSides = 2] ",
394 __FILE__, QANewDBRepNaming_NameBooleanOperationFeat, g);
395
396 theCommands.Add ("NameFuse",
397 "NameFuse Doc Label DrawShape1 DrawShape2",
398 __FILE__, QANewDBRepNaming_NameFuse, g);
399
400 theCommands.Add ("NameCut",
401 "NameCut Doc Label DrawShape1 DrawShape2",
402 __FILE__, QANewDBRepNaming_NameCut, g);
403
404 theCommands.Add ("NameCommon",
405 "NameCommon Doc Label DrawShape1 DrawShape2",
406 __FILE__, QANewDBRepNaming_NameCommon, g);
407
408 theCommands.Add ("NameIntersection",
409 "NameIntersection Doc Label DrawShape1 DrawShape2",
410 __FILE__, QANewDBRepNaming_NameIntersection, g);
411
412 theCommands.Add ("NameLimit",
413 "NameLimit Doc Label DrawShape1 DrawShape2 [Orientation (Forward - 0, Reversed - 1 or BothSise - 2)]",
414 __FILE__, QANewDBRepNaming_NameLimit, g);
415
416 theCommands.Add ("NameGlue",
417 "NameGlue Doc Label ObjectLabel ToolLabel [auxiliary valid labels]",
418 __FILE__, QANewDBRepNaming_NameGlue, g);
419
420}