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
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.
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.
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.
23 #include <QANewDBRepNaming.ixx>
26 #include <Draw_Interpretor.hxx>
27 #include <QANewDBRepNaming.hxx>
30 #include <DDocStd.hxx>
34 #include <TDocStd_Document.hxx>
35 #include <TDataXtd_Geometry.hxx>
37 #include <TNaming_NamedShape.hxx>
38 #include <TNaming_Tool.hxx>
39 #include <TNaming_Builder.hxx>
41 #include <TopTools_MapOfShape.hxx>
42 #include <TopTools_MapIteratorOfMapOfShape.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>
52 #include <TopExp_Explorer.hxx>
54 #include <BRepAdaptor_Surface.hxx>
55 #include <BRepAdaptor_Curve.hxx>
57 #include <BRep_Tool.hxx>
59 #include <BRepAlgoAPI_Fuse.hxx>
60 #include <BRepAlgoAPI_Common.hxx>
61 #include <BRepAlgoAPI_Cut.hxx>
62 #include <BRepAlgoAPI_Section.hxx>
64 #include <QANewModTopOpe_Limitation.hxx>
65 #include <QANewModTopOpe_Intersection.hxx>
67 #include <Standard_Assert.hxx>
69 #include <BRepBuilderAPI_MakeEdge.hxx>
70 #include <BRepBuilderAPI_MakeFace.hxx>
71 #include <BRepBuilderAPI_MakeWire.hxx>
73 #include <BRepLib.hxx>
75 #include <TColgp_Array1OfPnt.hxx>
77 #include <GCE2d_MakeLine.hxx>
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>
90 #include <BRepTools.hxx>
91 #include <TDF_LabelMap.hxx>
92 #include <QANewModTopOpe_Glue.hxx>
93 #include <QANewBRepNaming_Gluing.hxx>
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 //==============================================================
100 static Standard_Integer QANewDBRepNaming_NameBooleanOperationFeat (Draw_Interpretor& di,
104 if (nb != 6 && nb != 7) {
105 di << "QANewDBRepNaming_NameBooleanOperationFeat : Error" << "\n";
109 Handle(TDocStd_Document) D;
110 if (!DDocStd::GetDocument(arg[1],D)) return 1;
112 if (!DDF::AddLabel(D->GetData(), arg[2], L)) return 1;
114 const Standard_Integer Op = (Standard_Integer)atoi(arg[3]);
115 const TopoDS_Shape& S1 = DBRep::Get(arg[4]);
116 const TopoDS_Shape& S2 = DBRep::Get(arg[5]);
118 Standard_Integer Orientation = 0;
119 if (nb == 7) Orientation = atoi(arg[6]);
123 di << "BRepAlgoAPI_Fuse" << "\n";
124 BRepAlgoAPI_Fuse mkFuse(S1, S2);
126 Standard_ASSERT_RAISE(mkFuse.IsDone(), "Fuse failed");
127 QANewBRepNaming_Fuse nameBool(L);
128 nameBool.Load(mkFuse);
132 di << "BRepAlgoAPI_Cut" << "\n";
133 BRepAlgoAPI_Cut mkCut(S1, S2);
135 Standard_ASSERT_RAISE(mkCut.IsDone(), "Cut failed");
136 QANewBRepNaming_Cut nameBool(L);
137 nameBool.Load(mkCut);
141 di << "BRepAlgoAPI_Common" << "\n";
142 BRepAlgoAPI_Common mkCommon(S1, S2);
144 Standard_ASSERT_RAISE(mkCommon.IsDone(), "Common failed");
145 QANewBRepNaming_Common nameBool(L);
146 nameBool.Load(mkCommon);
150 QANewModTopOpe_Intersection mkSection(S1, S2);
151 Standard_ASSERT_RAISE(mkSection.IsDone(), "Section failed");
152 QANewBRepNaming_Intersection nameBool(L);
153 nameBool.Load(mkSection);
157 QANewModTopOpe_Limitation mkLimit(S1, S2);
158 const QANewModTopOpe_ModeOfLimitation aMode = (QANewModTopOpe_ModeOfLimitation) Orientation;
159 mkLimit.SetMode(aMode);
161 // if (Orientation = 0) mkLimit.CutForward();
162 // else if (Orientation = 1) mkLimit.CutReversed();
163 // else if (Orientation = 2) mkLimit.CutBothSides();
164 Standard_ASSERT_RAISE(mkLimit.IsDone(),"Limit failed");
165 QANewBRepNaming_Limitation nameBool(L);
166 nameBool.Load(mkLimit);
170 di<<"QANewDBRepNaming_NameBooleanOperation The type of operation must be 1 - fuse, 2 - cut or 3 - common"<<"\n";
176 //==============================================================
177 //function : QANewDBRepNaming_NameFuse
178 //purpose : NameFuse Doc Label DrawShape1 DrawShape2
179 //==============================================================
181 static Standard_Integer QANewDBRepNaming_NameFuse (Draw_Interpretor& di,
186 di << "QANewDBRepNaming_NameFuse : Error" << "\n";
190 Handle(TDocStd_Document) D;
191 if (!DDocStd::GetDocument(arg[1],D)) return 1;
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);
198 di << "BRepAlgoAPI_Fuse" << "\n";
199 BRepAlgoAPI_Fuse mkFuse(S1, S2);
201 Standard_ASSERT_RAISE(mkFuse.IsDone(), "Fuse failed");
202 nameBool.Load(mkFuse);
206 //==============================================================
207 //function : QANewDBRepNaming_NameCut
208 //purpose : NameCut Doc Label DrawShape1 DrawShape2
209 //==============================================================
211 static Standard_Integer QANewDBRepNaming_NameCut (Draw_Interpretor& di,
216 di << "QANewDBRepNaming_NameCut : Error" << "\n";
220 Handle(TDocStd_Document) D;
221 if (!DDocStd::GetDocument(arg[1],D)) return 1;
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);
231 di << "BRepAlgoAPI_Cut" << "\n";
232 BRepAlgoAPI_Cut mkCut(S1, S2);
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");
238 Standard_ASSERT_RAISE(mkCut.IsDone(), "Cut failed");
239 nameBool.Load(mkCut);
240 // BRepTools::Write(mkCut.Shape1(), "/dn04/OS/SAMTECH/env/S2.brep");
244 //==============================================================
245 //function : QANewDBRepNaming_NameCommon
246 //purpose : NameCommon Doc Label DrawShape1 DrawShape2
247 //==============================================================
249 static Standard_Integer QANewDBRepNaming_NameCommon (Draw_Interpretor& di,
254 di << "QANewDBRepNaming_NameCommon : Error" << "\n";
258 Handle(TDocStd_Document) D;
259 if (!DDocStd::GetDocument(arg[1],D)) return 1;
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);
266 di << "BRepAlgoAPI_Common" << "\n";
267 BRepAlgoAPI_Common mkCommon(S1, S2);
269 Standard_ASSERT_RAISE(mkCommon.IsDone(), "Common failed");
270 nameBool.Load(mkCommon);
274 //==============================================================
275 //function : QANewDBRepNaming_NameIntersection
276 //purpose : NameIntersection Doc Label DrawShape1 DrawShape2
277 //==============================================================
279 static Standard_Integer QANewDBRepNaming_NameIntersection (Draw_Interpretor& di,
284 di << "QANewDBRepNaming_NameIntersection : Error" << "\n";
288 Handle(TDocStd_Document) D;
289 if (!DDocStd::GetDocument(arg[1],D)) return 1;
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);
296 Standard_ASSERT_RAISE(mkIntersection.IsDone(), "Section failed");
297 nameBool.Load(mkIntersection);
301 //==============================================================
302 //function : QANewDBRepNaming_NameLimit
303 //purpose : NameLimit Doc Label DrawShape1 DrawShape2 [Orientation (Forward - 0, Reversed - 1 or BothSise - 2)]
304 //==============================================================
306 static Standard_Integer QANewDBRepNaming_NameLimit (Draw_Interpretor& di,
310 if (nb != 5 && nb != 6) {
311 di << "QANewDBRepNaming_NameLimit : Error" << "\n";
315 Handle(TDocStd_Document) D;
316 if (!DDocStd::GetDocument(arg[1],D)) return 1;
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;
323 Orientation = atoi(arg[5]);
325 QANewBRepNaming_Limitation nameBool(L);
326 const QANewModTopOpe_ModeOfLimitation aMode = (QANewModTopOpe_ModeOfLimitation) Orientation;
327 QANewModTopOpe_Limitation mkLimit(S1, S2, aMode);
329 // if (Orientation == 0) mkLimit.CutForward();
330 // else if (Orientation == 1) mkLimit.CutReversed();
331 // else if (Orientation == 2) mkLimit.CutBothSides();
332 Standard_ASSERT_RAISE(mkLimit.IsDone(), "Limit failed");
333 nameBool.Load(mkLimit);
337 //==============================================================
338 //function : QANewDBRepNaming_NameGlue
339 //purpose : NameGlue Doc Label ObjectLabel ToolLabel [auxiliary valid labels]
340 //==============================================================
342 static Standard_Integer QANewDBRepNaming_NameGlue (Draw_Interpretor& di,
347 di << "QANewDBRepNaming_NameGlue : Error" << "\n";
351 Handle(TDocStd_Document) D;
352 if (!DDocStd::GetDocument(arg[1],D)) return 1;
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;
358 for(Standard_Integer i=5;i<nb;i++) {
360 if (!DDF::AddLabel(D->GetData(), arg[i], aLabel)) return 1;
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;
367 QANewModTopOpe_Glue aMKGlue(TNaming_Tool::CurrentShape(anObjectNS),TNaming_Tool::CurrentShape(aToolNS));
368 if (!aMKGlue.IsDone()) return 1;
370 if (!aMKGlue.IsDone()) return 1;
372 QANewBRepNaming_Gluing aGlue(L);
373 aGlue.SetContext(TNaming_Tool::CurrentShape(anObjectNS),TNaming_Tool::CurrentShape(aToolNS));
379 //=======================================================================
380 //function : FeatureCommands
382 //=======================================================================
384 void QANewDBRepNaming::FeatureCommands (Draw_Interpretor& theCommands)
386 static Standard_Boolean done = Standard_False;
388 done = Standard_True;
389 const char* g = "Naming algorithm commands for features" ;
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);
396 theCommands.Add ("NameFuse",
397 "NameFuse Doc Label DrawShape1 DrawShape2",
398 __FILE__, QANewDBRepNaming_NameFuse, g);
400 theCommands.Add ("NameCut",
401 "NameCut Doc Label DrawShape1 DrawShape2",
402 __FILE__, QANewDBRepNaming_NameCut, g);
404 theCommands.Add ("NameCommon",
405 "NameCommon Doc Label DrawShape1 DrawShape2",
406 __FILE__, QANewDBRepNaming_NameCommon, g);
408 theCommands.Add ("NameIntersection",
409 "NameIntersection Doc Label DrawShape1 DrawShape2",
410 __FILE__, QANewDBRepNaming_NameIntersection, g);
412 theCommands.Add ("NameLimit",
413 "NameLimit Doc Label DrawShape1 DrawShape2 [Orientation (Forward - 0, Reversed - 1 or BothSise - 2)]",
414 __FILE__, QANewDBRepNaming_NameLimit, g);
416 theCommands.Add ("NameGlue",
417 "NameGlue Doc Label ObjectLabel ToolLabel [auxiliary valid labels]",
418 __FILE__, QANewDBRepNaming_NameGlue, g);