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