0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / DNaming / DNaming_ModelingCommands.cxx
CommitLineData
b311480e 1// Created on: 2010-01-15
2// Created by: Sergey ZARITCHNY
973c2be1 3// Copyright (c) 2010-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
91322f44 16#include <Draw.hxx>
7fd59977 17#include <Draw_Interpretor.hxx>
18#include <Standard_ErrorHandler.hxx>
19#include <DNaming.hxx>
20#include <DBRep.hxx>
21
22#include <BRepTools.hxx>
23#include <BRep_Builder.hxx>
24#include <gp_Trsf.hxx>
25#include <TopAbs.hxx>
26#include <TopoDS.hxx>
27#include <TopoDS_Shape.hxx>
28#include <TopoDS_Iterator.hxx>
29#include <TopExp_Explorer.hxx>
30#include <TopTools_MapOfShape.hxx>
31#include <TopTools_MapIteratorOfMapOfShape.hxx>
32#include <TopTools_MapOfOrientedShape.hxx>
33#include <TopTools_DataMapOfOrientedShapeShape.hxx>
34#include <TopTools_ListOfShape.hxx>
35#include <TopTools_ListIteratorOfListOfShape.hxx>
36#include <TCollection_AsciiString.hxx>
37#include <Standard_GUID.hxx>
38
39#include <DDF.hxx>
40#include <DDocStd.hxx>
41#include <TDF_TagSource.hxx>
42#include <TDF_Tool.hxx>
43#include <TDF_Reference.hxx>
44#include <TDF_ChildIterator.hxx>
45#include <TDF_ChildIDIterator.hxx>
46#include <TDF_MapIteratorOfLabelMap.hxx>
47#include <TDataStd_Real.hxx>
48#include <TDataStd_Integer.hxx>
49#include <TDataStd_TreeNode.hxx>
50#include <TDataStd_Name.hxx>
51#include <TDataStd_UAttribute.hxx>
52#include <TFunction_Function.hxx>
53#include <TFunction_Logbook.hxx>
54#include <TFunction_Driver.hxx>
55#include <TFunction_DriverTable.hxx>
56#include <TNaming_NamedShape.hxx>
57#include <TNaming_Selector.hxx>
58#include <TNaming_Builder.hxx>
59#include <TNaming_Naming.hxx>
60#include <TNaming_Name.hxx>
61#include <TDocStd_Document.hxx>
62
63#include <DNaming_BoxDriver.hxx>
64#include <DNaming_CylinderDriver.hxx>
65#include <DNaming_SelectionDriver.hxx>
66#include <DNaming_BooleanOperationDriver.hxx>
67#include <DNaming_FilletDriver.hxx>
68#include <DNaming_TransformationDriver.hxx>
69#include <DNaming_PrismDriver.hxx>
70#include <DNaming_RevolutionDriver.hxx>
71#include <DNaming_SphereDriver.hxx>
72#include <DNaming_PointDriver.hxx>
73#include <DNaming_Line3DDriver.hxx>
57c28b61 74#ifdef _WIN32
7fd59977 75#define EXCEPTION ...
76#else
77#define EXCEPTION Standard_Failure
78#endif
79#include <ModelDefinitions.hxx>
80//#define DEBUG
81//=======================================================================
82static Handle(TDataStd_UAttribute) AddObject(const Handle(TDocStd_Document)& aDoc)
83{
84 Handle(TDataStd_TreeNode) aRootNode = TDataStd_TreeNode::Set(aDoc->Main());
85 const TDF_Label& aLabel = TDF_TagSource::NewChild(aDoc->Main());
86
87 Handle(TDataStd_UAttribute) anObj = TDataStd_UAttribute::Set(aLabel,GEOMOBJECT_GUID);
88 Handle(TDataStd_TreeNode) aNode = TDataStd_TreeNode::Set(aLabel);
89 aRootNode->Append(aNode);
90 return anObj;
91}
92//=======================================================================
93//function : DNaming_AddObject
94//purpose : AddObject D [Name]
95// - adds new object (UAttribute) under main label
96//=======================================================================
97static Standard_Integer DNaming_AddObject(Draw_Interpretor& di,
98 Standard_Integer nb,
99 const char** a)
100{
101 if(nb > 1) {
102 Handle(TDocStd_Document) aDoc;
103 if (!DDocStd::GetDocument(a[1],aDoc)) return 1;
104 Handle(TDataStd_UAttribute) anObj = AddObject (aDoc);
105 if(!anObj.IsNull()) {
106 if(nb == 3)
107 TDataStd_Name::Set(anObj->Label(), a[2]);
108 DDF::ReturnLabel(di, anObj->Label());
109 return 0;
110 }
111 }
586db386 112 di << "DNaming_AddObject: Error\n";
7fd59977 113 return 1;
114}
115
116#include <NCollection_DataMap.hxx>
117typedef NCollection_DataMap <TCollection_AsciiString,
118 Standard_GUID> DataMapOfAStringGUID;
119 static Standard_Boolean isBuilt(Standard_False);
120 static DataMapOfAStringGUID aDMap;
121//=======================================================================
122static Standard_Boolean GetFuncGUID(Standard_CString aKey,Standard_GUID& GUID)
123{
124 Standard_Boolean aRes(Standard_False);
125
126 if(!isBuilt) {
372ceec4 127 aDMap.Bind("PntXYZ", PNTXYZ_GUID);
128 aDMap.Bind("PntRLT", PNTRLT_GUID);
129 aDMap.Bind("Line3D", LINE3D_GUID);
130 aDMap.Bind("Box", BOX_GUID);
131 aDMap.Bind("Sph", SPH_GUID);
132 aDMap.Bind("Cyl", CYL_GUID);
133 aDMap.Bind("Cut", CUT_GUID);
134 aDMap.Bind("Fuse", FUSE_GUID);
135 aDMap.Bind("Comm", COMMON_GUID);
136 aDMap.Bind("Prism", PRISM_GUID);
137 aDMap.Bind("FulRevol", FULREVOL_GUID);
138 aDMap.Bind("SecRevol", SECREVOL_GUID);
139 aDMap.Bind("PMirr", PMIRR_GUID);
140 aDMap.Bind("PTxyz", PTXYZ_GUID);
141 aDMap.Bind("PTALine", PTALINE_GUID);
142 aDMap.Bind("PRLine", PRRLINE_GUID);
143 aDMap.Bind("Fillet", FILLT_GUID);
144 aDMap.Bind("Attach", ATTCH_GUID);
145 aDMap.Bind("XAttach", XTTCH_GUID);
146 aDMap.Bind("Section", SECTION_GUID);
7fd59977 147 isBuilt = Standard_True;
148 }
149
150 if(aDMap.IsBound(aKey)) {
151 GUID = aDMap.Find(aKey);
152 aRes = Standard_True;
153 }
154 return aRes;
155}
156//=======================================================================
157static Handle(TFunction_Driver) GetDriver(const TCollection_AsciiString& name)
158{
159 Handle(TFunction_Driver) aDrv;
160 if(name == "Box")
161 aDrv = new DNaming_BoxDriver();
162 else if(name == "Cyl")
163 aDrv = new DNaming_CylinderDriver();
164 else if(name == "Sph")
165 aDrv = new DNaming_SphereDriver();
166 else if(name == "Cut")
167 aDrv = new DNaming_BooleanOperationDriver();
168 else if(name == "Fuse")
169 aDrv = new DNaming_BooleanOperationDriver();
170 else if(name == "Comm")
171 aDrv = new DNaming_BooleanOperationDriver();
172 else if(name == "Prism")
173 aDrv = new DNaming_PrismDriver();
174 else if(name == "FulRevol")
175 aDrv = new DNaming_RevolutionDriver();
176 else if(name == "SecRevol")
177 aDrv = new DNaming_RevolutionDriver();
178 else if(name == "PTxyz")
179 aDrv = new DNaming_TransformationDriver();
180 else if(name == "PTALine")
181 aDrv = new DNaming_TransformationDriver();
182 else if(name == "PRLine")
183 aDrv = new DNaming_TransformationDriver();
184 else if(name == "PMirr")
185 aDrv = new DNaming_TransformationDriver();
186 else if(name == "Fillet")
187 aDrv = new DNaming_FilletDriver();
188 else if(name == "Attach")
189 aDrv = new DNaming_SelectionDriver();
190 else if(name == "XAttach")
191 aDrv = new DNaming_SelectionDriver();
192 else if(name == "PntXYZ")
193 aDrv = new DNaming_PointDriver();
194 else if(name == "PntRLT")
195 aDrv = new DNaming_PointDriver();
372ceec4 196 else if(name == "Line3D")
7fd59977 197 aDrv = new DNaming_Line3DDriver();
372ceec4 198 else if(name == "Section")
199 aDrv = new DNaming_BooleanOperationDriver();
7fd59977 200 else
201 cout << "the specified driver is not supported" <<endl;
202 return aDrv;
203}
204//=======================================================================
205//function : DNaming_AddDriver
206//purpose : "AddDriver Doc Name1 Name2 ..."
207//=======================================================================
35e08fe8 208static Standard_Integer DNaming_AddDriver (Draw_Interpretor& /*theDI*/,
7fd59977 209 Standard_Integer theNb,
210 const char** theArg)
211{
212 if (theNb >= 3) {
213 Handle(TDocStd_Document) aDoc;
214 Standard_CString aDocS(theArg[1]);
215 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
216 Handle(TFunction_DriverTable) aFunctionDrvTable = TFunction_DriverTable::Get();
217 for(int i = 2; i < theNb; i++) {
218 Standard_GUID drvGUID;
219 if(!GetFuncGUID(theArg[i],drvGUID)) continue;
220 aFunctionDrvTable->AddDriver(drvGUID, GetDriver(theArg[i]));
0797d9d3 221#ifdef OCCT_DEBUG
7fd59977 222 cout << "DNaming_AddDriver : " << theArg[i] << " driver is added" <<endl;
223#endif
224 }
225 return 0;
226 }
0797d9d3 227#ifdef OCCT_DEBUG
7fd59977 228 cout << "DNaming_AddDriver : Error" << endl;
63c629aa 229#endif
7fd59977 230 return 1;
231}
232
233//=======================================================================
234static Handle(TFunction_Function) SetFunctionDS(const TDF_Label& objLabel,
235 const Standard_GUID& funGUID)
236{
237 //set function
238 const TDF_Label& aLabel = TDF_TagSource::NewChild(objLabel);
239 Handle(TFunction_Function) aFun = TFunction_Function::Set(aLabel,funGUID);
240
241 Handle(TDataStd_TreeNode) aNode = TDataStd_TreeNode::Set(aLabel);
242 Handle(TDataStd_TreeNode) objNode;
243 objLabel.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), objNode);
244 if(!objNode.IsNull())
245 objNode->Append(aNode);
246
247 //set function data sub-structure
248 const TDF_Label& aLab1 = TDF_TagSource::NewChild(aLabel);
249 Handle(TDataStd_TreeNode) aNode1 = TDataStd_TreeNode::Set(aLab1);
250 TDataStd_Name::Set(aLab1, "Arguments");
251 if(!aNode.IsNull())
252 aNode->Append(aNode1);
253
254 const TDF_Label& aLab2 = TDF_TagSource::NewChild(aLabel);
255 Handle(TDataStd_TreeNode) aNode2 = TDataStd_TreeNode::Set(aLab2);
256 TDataStd_Name::Set(aLab2, "Result");
257 if(!aNode.IsNull())
258 aNode->Append(aNode2);
259 return aFun;
260}
261//=======================================================================
262//function : DNaming_AddFunction
263//purpose : AddFunction D ObjEntry FunNane
264// : - adds new function specified by FunName to an object
265// : specified by ObjEntry
266//=======================================================================
267static Standard_Integer DNaming_AddFunction(Draw_Interpretor& di,
268 Standard_Integer nb,
269 const char** a)
270{
271 if(nb == 4) {
272 Handle(TDocStd_Document) aDoc;
273 if (!DDocStd::GetDocument(a[1],aDoc)) return 1;
274 TDF_Label objLabel;
275 if (!DDF::FindLabel(aDoc->GetData(),a[2], objLabel)) return 1;
276
277 Handle(TDataStd_UAttribute) anObj;
278 if(!objLabel.FindAttribute(GEOMOBJECT_GUID, anObj)) {
279 di << "DNaming_AddFunction: Object is not found at the specified label: "<< a[2] << "\n";
280 return 1;
281 }
282 Standard_GUID funGUID;
283 if(!GetFuncGUID(a[3],funGUID)) {
284 di << "DNaming_AddFunction: the specified function is not supported: "<< a[3] << "\n";
285 return 1;
286 }
287 Handle(TFunction_Function) aFun = SetFunctionDS(objLabel, funGUID);
288 if(!aFun.IsNull()) {
289 TCollection_AsciiString aFName = TCollection_AsciiString(a[3]) + "_Function";
290 TDataStd_Name::Set(aFun->Label(), aFName);
291 TDF_Reference::Set(objLabel, aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
292 DDF::ReturnLabel(di, aFun->Label());
293 return 0;
294 }
295 }
586db386 296 di << "DNaming_AddObject: Error\n";
7fd59977 297 return 1;
298}
299
300
301//=======================================================================
302//function : DNaming_AddBox
303//purpose : "AddBox Doc dx dy dz"
304//=======================================================================
305static Standard_Integer DNaming_AddBox (Draw_Interpretor& theDI,
306 Standard_Integer theNb,
307 const char** theArg)
308{
309 if (theNb >= 4) {
310
311 Handle(TDocStd_Document) aDocument;
312 Standard_CString aDocS(theArg[1]);
313 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
314 Handle(TDataStd_UAttribute) anObj = AddObject(aDocument);
315 if(anObj.IsNull()) return 1;
316 Standard_GUID funGUID;
317 if(!GetFuncGUID("Box",funGUID)) return 1;
318
319 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
320 if(aFun.IsNull()) return 1;
321 TDataStd_Name::Set(aFun->Label(), "Box_Function");
322
323 TDF_Reference::Set(anObj->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
324 Standard_Real dx,dy,dz;
91322f44 325 dx = Draw::Atof(theArg[2]);
326 dy = Draw::Atof(theArg[3]);
327 dz = Draw::Atof(theArg[4]);
7fd59977 328
329 DNaming::GetReal(aFun,BOX_DX)->Set(dx);
330 DNaming::GetReal(aFun,BOX_DY)->Set(dy);
331 DNaming::GetReal(aFun,BOX_DZ)->Set(dz);
332
333 DDF::ReturnLabel(theDI, anObj->Label());
334 return 0;
335 }
336 cout << "DNaming_AddBox : Error" << endl;
337 return 1;
338}
339
340//=======================================================================
341static Handle(TFunction_Function) GetFunction(const TDF_Label& objLabel, const Standard_GUID& funGUID) {
342 Handle(TFunction_Function) aFun;
343 Handle(TDataStd_TreeNode) aNode;
344 objLabel.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode);
345 if(aNode.IsNull()) return aFun;
346 if(!aNode->HasFirst()) return aFun;
347 else
348 aNode = aNode->First();
349 while(!aNode.IsNull()) {
350 if(aNode->FindAttribute(TFunction_Function::GetID(), aFun)) {
351 const Standard_GUID& aGUID = aFun->GetDriverGUID();
352 if(aGUID == funGUID) break;
353 else aFun.Nullify();
354 }
355 aNode = aNode->Next();
356 }
357 return aFun;
358}
359//=======================================================================
360//function : DNaming_BoxDX
361//purpose : "BoxDX Doc BoxLabel NewDX"
362//=======================================================================
363
364static Standard_Integer DNaming_BoxDX (Draw_Interpretor& theDI,
365 Standard_Integer theNb,
366 const char** theArg)
367{
368 if (theNb == 4) {
369 Handle(TDocStd_Document) aDoc;
370 Standard_CString aDocS(theArg[1]);
371 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
372 TDF_Label objLabel;
373 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], objLabel)) return 1;
374
375 Handle(TDataStd_UAttribute) anObj;
376 if(!objLabel.FindAttribute(GEOMOBJECT_GUID, anObj)) return 1;
377 Standard_GUID funGUID;
378 if(!GetFuncGUID("Box",funGUID)) return 1;
379
380 Handle(TFunction_Function) aFun = GetFunction(objLabel,funGUID);
381 if(!aFun.IsNull()) {
91322f44 382 Standard_Real value = Draw::Atof(theArg[3]);
7fd59977 383 DNaming::GetReal(aFun,BOX_DX)->Set(value);
384 DDF::ReturnLabel(theDI, DNaming::GetReal(aFun,BOX_DX)->Label());
385 return 0;
386 }
387 }
388 cout << "DNaming_BoxDX : Error" << endl;
389 return 1;
390}
391
392//=======================================================================
393//function : DNaming_BoxDY
394//purpose : "BoxDY Doc BoxLabel NewDY"
395//=======================================================================
396
397static Standard_Integer DNaming_BoxDY (Draw_Interpretor& theDI,
398 Standard_Integer theNb,
399 const char** theArg)
400{
401 if (theNb == 4) {
402 Handle(TDocStd_Document) aDoc;
403 Standard_CString aDocS(theArg[1]);
404 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
405 TDF_Label objLabel;
406 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], objLabel)) return 1;
407
408 Handle(TDataStd_UAttribute) anObj;
409 if(!objLabel.FindAttribute(GEOMOBJECT_GUID, anObj)) return 1;
410 Standard_GUID funGUID;
411 if(!GetFuncGUID("Box",funGUID)) return 1;
412
413 Handle(TFunction_Function) aFun = GetFunction(objLabel,funGUID);
414 if(!aFun.IsNull()) {
91322f44 415 Standard_Real value = Draw::Atof(theArg[3]);
7fd59977 416 DNaming::GetReal(aFun,BOX_DY)->Set(value);
417 DDF::ReturnLabel(theDI, DNaming::GetReal(aFun,BOX_DY)->Label());
418 return 0;
419 }
420 }
421 cout << "DNaming_BoxDY : Error" << endl;
422 return 1;
423}
424
425//=======================================================================
426//function : DNaming_BoxDZ
427//purpose : "BoxDZ Doc BoxLabel NewDZ"
428//=======================================================================
429
430static Standard_Integer DNaming_BoxDZ (Draw_Interpretor& theDI,
431 Standard_Integer theNb,
432 const char** theArg)
433{
434 if (theNb == 4) {
435 Handle(TDocStd_Document) aDoc;
436 Standard_CString aDocS(theArg[1]);
437 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
438 TDF_Label objLabel;
439 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], objLabel)) return 1;
440
441 Handle(TDataStd_UAttribute) anObj;
442 if(!objLabel.FindAttribute(GEOMOBJECT_GUID, anObj)) return 1;
443 Standard_GUID funGUID;
444 if(!GetFuncGUID("Box",funGUID)) return 1;
445
446 Handle(TFunction_Function) aFun = GetFunction(objLabel,funGUID);
447 if(!aFun.IsNull()) {
91322f44 448 Standard_Real value = Draw::Atof(theArg[3]);
7fd59977 449 DNaming::GetReal(aFun,BOX_DZ)->Set(value);
450 DDF::ReturnLabel(theDI, DNaming::GetReal(aFun,BOX_DZ)->Label());
451 return 0;
452 }
453 }
454 cout << "DNaming_BoxDZ : Error" << endl;
455 return 1;
456}
457
7fd59977 458//=======================================================================
459//function : Compute
460//purpose : Performs the calling to a driver with the given Function ID.
461//=======================================================================
462static Standard_Integer ComputeFunction(const Handle(TFunction_Function)& theFun,
f486f64d 463 Handle(TFunction_Logbook)& theLog)
7fd59977 464{
465 Handle(TFunction_DriverTable) aTable = TFunction_DriverTable::Get();
466 Handle(TFunction_Driver) aDriver;
467 Standard_Integer aRes(-1);
468 if (aTable->FindDriver(theFun->GetDriverGUID(),aDriver))
469 {
470 aDriver->Init(theFun->Label());
471 aRes = aDriver->Execute(theLog);
472 }
473 else
474 aRes = 1;
475 return aRes;
476}
477
478
479//=======================================================================
480//function : DNaming_SolveFlatFrom
481//purpose : Performs sequential recomputation of all Aux Object starting from the specified.
482// : "SolveFlatFrom Doc FistAuxObjLabel"
483//=======================================================================
484
35e08fe8 485static Standard_Integer DNaming_SolveFlatFrom (Draw_Interpretor& /*theDI*/,
7fd59977 486 Standard_Integer theNb,
487 const char** theArg)
488{
489 if (theNb == 3) {
490 Handle(TDocStd_Document) aDoc;
491 Standard_CString aDocS(theArg[1]);
492 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
493 TDF_Label ObjLabel;
494 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], ObjLabel)) return 1;
495 const TDF_Label& FatherLab = ObjLabel.Father();
496 if(FatherLab.IsNull())
497 goto ERR;
498 TCollection_AsciiString entry;
499 TDF_Tool::Entry(FatherLab, entry);
0797d9d3 500#ifdef OCCT_DEBUG
7fd59977 501 cout << "DNaming_SolveFlatFrom: Father label = " << entry << endl;
502#endif
f486f64d 503 Handle(TFunction_Logbook) logbook = TFunction_Logbook::Set(FatherLab);
7fd59977 504 Standard_Boolean found(Standard_False);
505 TDF_ChildIterator it(FatherLab, Standard_False);
506 for(;it.More(); it.Next()) {
507 const TDF_Label& aLabel = it.Value();
508 if(!found) {
509 if(aLabel == ObjLabel) {
510 found = Standard_True;
511 } else
512 continue;
513 }
514 const TDF_Label& funLabel = aLabel.FindChild(FUNCTION_ARGUMENTS_LABEL, Standard_True);
515 Handle(TFunction_Function) aFun;
516 funLabel.FindAttribute(TFunction_Function::GetID(), aFun);
517 if(aFun.IsNull()) {
518 cout << "DNaming_SolveFlatFrom:: Null function is found!" << endl;
519 continue;
520 }
521 else {
522 TDF_Tool::Entry(funLabel, entry);
523 try {
f486f64d 524 // We clear the logbook because the execution starts not from the begining of the function list (some functions ar skipped).
525 logbook->Clear();
526 Standard_Integer aRes = ComputeFunction(aFun, logbook);
7fd59977 527 if(aRes != 0) {
528 cout << "DNaming_SolveFlatFrom: Driver failed at label = " << entry << endl;
529 return 1;
530 }
0797d9d3 531#ifdef OCCT_DEBUG
7fd59977 532 cout <<"DNaming_SolveFlatFrom : function from label " << entry << " is recomputed" << endl;
533#endif
534 } catch (EXCEPTION) {
535 cout <<"DNaming_SolveFlatFrom : Exception computing function at label " << entry << endl;
536 }
537 }
538 }
539 return 0;
540 }
541 ERR:
542 cout << "DNaming_SolveFlatFrom : Error" << endl;
543 return 1;
544}
545
546//=======================================================================
547//function : DNaming_InitLogBook
548//purpose : "InitLogBook Doc "
549//=======================================================================
35e08fe8 550static Standard_Integer DNaming_InitLogBook (Draw_Interpretor& /*theDI*/,
7fd59977 551 Standard_Integer theNb,
552 const char** theArg)
553{
554 if (theNb == 2) {
555 Handle(TDocStd_Document) aDoc;
556 Standard_CString aDocS(theArg[1]);
557 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
f486f64d 558 Handle(TFunction_Logbook) logbook = TFunction_Logbook::Set(aDoc->Main());
559 if(logbook->IsEmpty()) {
0797d9d3 560#ifdef OCCT_DEBUG
7fd59977 561 cout << "DNaming_InitLogBook : is empty" <<endl;
562#endif
563 }
564 else {
f486f64d 565 logbook->Clear();
0797d9d3 566#ifdef OCCT_DEBUG
7fd59977 567 cout << "DNaming_InitLogBook : cleaned" <<endl;
568#endif
569 }
570 return 0;
571 }
572 cout << "DNaming_InitLogBook : Error - No document ==> " <<theNb <<endl;
573 return 1;
574}
575
576//=======================================================================
577//function : DNaming_CheckLogBook
578//purpose : "CheckLogBook Doc"
579//=======================================================================
35e08fe8 580static Standard_Integer DNaming_CheckLogBook (Draw_Interpretor& /*theDI*/,
7fd59977 581 Standard_Integer theNb,
582 const char** theArg)
583{
584 if (theNb == 2) {
585 Handle(TDocStd_Document) aDoc;
586 Standard_CString aDocS(theArg[1]);
f486f64d 587 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
588 Handle(TFunction_Logbook) logbook = TFunction_Logbook::Set(aDoc->Main());
589 if(logbook->IsEmpty())
7fd59977 590 cout << "DNaming_CheckLogBook : is empty" <<endl;
591 else {
f486f64d 592 const TDF_LabelMap& aMap = logbook->GetValid();
7fd59977 593 TDF_MapIteratorOfLabelMap it(aMap);
594 TCollection_AsciiString entry;
595 cout << "DNaming_CheckLogBook : LogBook current state:" <<endl;
596 for (;it.More();it.Next()) {
597 TDF_Tool::Entry(it.Key(), entry);
598 cout << entry <<endl;
599 }
600 }
601 return 0;
602 }
603 cout << "DNaming_CheckLogBook : Error - No document ==> " <<theNb <<endl;
604 return 1;
605}
606
607//=======================================================================
608//function : DNaming_ComputeFun
609//purpose : "ComputeFun Doc FunctionLabel"
610//=======================================================================
35e08fe8 611static Standard_Integer DNaming_ComputeFun (Draw_Interpretor& /*theDI*/,
7fd59977 612 Standard_Integer theNb,
613 const char** theArg)
614{
615 if (theNb == 3) {
616 Handle(TDocStd_Document) aDoc;
617 Standard_CString aDocS(theArg[1]);
618 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
619 TDF_Label funLabel;
620 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], funLabel)) return 1;
621
622 Handle(TFunction_Function) aFun;
623 funLabel.FindAttribute(TFunction_Function::GetID(), aFun);
624 if(aFun.IsNull()) return 1;
625 if(!aFun.IsNull()) {
f486f64d 626 Handle(TFunction_Logbook) logbook = TFunction_Logbook::Set(funLabel);
627 Standard_Integer aRes = ComputeFunction(aFun, logbook);
7fd59977 628 if(aRes != 0) {
629 cout << "DNaming_ComputeFun : No Driver or Driver failed" << endl;
630 return 1;
631 }
0797d9d3 632#ifdef OCCT_DEBUG
7fd59977 633 cout <<"DNaming_ComputeFun : function from label " << theArg[2] << " is recomputed" << endl;
634#endif
635 return 0;
636 }
637 }
638 cout << "DNaming_ComputeFun : Error" << endl;
639 return 1;
640}
641
642//=======================================================================
643//function : DNaming_AttachShape
644//purpose : "AttachShape Doc Shape Context [Container [KeepOrientation [Geometry]]]"
645//=======================================================================
646static Standard_Integer DNaming_AttachShape (Draw_Interpretor& di,
647 Standard_Integer nb,
648 const char** a)
649{
650 if (nb >= 4) {
651 Handle(TDocStd_Document) aDoc;
652 Standard_CString aDocS(a[1]);
653 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
654 Standard_CString aSS(a[2]);
655 const TopoDS_Shape& aShape = DBRep::Get(aSS); //shape to be attached
656 if(aShape.IsNull()) return 1;
657
658 Handle(TDataStd_UAttribute) aContainer, aContext;
659 if (!DDocStd::Find(aDoc, a[3], GEOMOBJECT_GUID, aContext)) return 1;
660 if(nb > 4)
661 DDocStd::Find(aDoc, a[4], GEOMOBJECT_GUID, aContainer);
662
663 if(aContainer.IsNull()) aContainer = aContext;
664
665 Handle(TDataStd_UAttribute) anObj = AddObject (aDoc);
666 if(!anObj.IsNull()) {
667 Handle(TDataStd_TreeNode) aNode,RNode;
668 anObj->Label().FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode);
669 if(aNode.IsNull())
670 aNode = TDataStd_TreeNode::Set(anObj->Label());
671 aNode->Remove();
672 if(aContainer->Label().FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), RNode))
673 RNode->Append(aNode);
674 TDataStd_Name::Set(anObj->Label(), "Auxiliary_Object");
675 Standard_GUID funGUID;
676 if(GetFuncGUID("Attach",funGUID)) {
677 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
678 if(!aFun.IsNull()) {
679 TDataStd_Name::Set(aFun->Label(), "ISelection");
680 TDF_Label aResultLabel = aFun->Label().FindChild(FUNCTION_RESULT_LABEL, Standard_True);
681 TDF_Reference::Set(anObj->Label(), aResultLabel ); //result of the object
682 aResultLabel.ForgetAllAttributes(Standard_True);
683 Standard_Boolean aKeepOrientation(Standard_False);
684 if (nb >= 6)
dde68833 685 aKeepOrientation = Draw::Atoi(a[5]) != 0;
7fd59977 686 Standard_Boolean aGeometry(Standard_False);
687 if (nb == 7)
dde68833 688 aGeometry = Draw::Atoi(a[6]) != 0;
7fd59977 689 Handle(TNaming_NamedShape) aCont = DNaming::GetObjectValue(aContext);
0797d9d3 690#ifdef OCCT_DEBUG
7fd59977 691 if(aCont.IsNull() || aCont->IsEmpty())
692 cout <<"Wrong Context ..." <<endl;
693#endif
694 try{
695 TopoDS_Shape aCONTEXT = aCont->Get();
696 TNaming_Selector aSelector(aResultLabel);
697 if(!aSelector.Select(aShape, aCONTEXT, aGeometry, aKeepOrientation))
698 return 1;
b350f6ee 699 }
700 catch (Standard_Failure) {
7fd59977 701 cout << "EXCEPTION: SELECTION_IMPOSSIBLE" <<endl;
702 }
703
704 if(!aCont.IsNull()) {
0797d9d3 705#ifdef OCCT_DEBUG
7fd59977 706 TCollection_AsciiString entry;
707 TDF_Tool::Entry(aCont->Label(), entry);
708 cout << "ContextNS Label = " << entry <<endl;
709#endif
710 Handle(TFunction_Function) aCntFun;
711 if(aCont->Label().Father().FindAttribute(TFunction_Function::GetID(), aCntFun)) { //Fun:2 ==> result
712 // First argument of Selection function refers to father function (of context object)
713 // to which selection is attached (because sel obj. itself already has refrence to result NS
714 TDF_Reference::Set(aFun->Label().FindChild(FUNCTION_ARGUMENTS_LABEL).FindChild(ATTACH_ARG),
715 aCntFun->Label()); //ref to function produced Context shape
716
717 }
718 }
719
720 DDF::ReturnLabel(di, anObj->Label());
721 return 0;
722 }
723 }
724 } //###
725 }
726 cout << "DNaming_AttachShape : Error" << endl;
727 return 1;
728}
729
730//=======================================================================
731//function : DNaming_XAttachShape
732//purpose : "AttachShape Doc Shape Context [KeepOrientation [Geometry]]"
733//=======================================================================
734static Standard_Integer DNaming_XAttachShape (Draw_Interpretor& di,
735 Standard_Integer nb,
736 const char** a)
737{
738 if (nb >= 4) {
739 Handle(TDocStd_Document) aDoc;
740 Standard_CString aDocS(a[1]);
741 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
742 Standard_CString aSS(a[2]);
743 const TopoDS_Shape& aShape = DBRep::Get(aSS);
744 if(aShape.IsNull()) return 1;
745
746 Handle(TDataStd_UAttribute) aContext;
747 if (!DDocStd::Find(aDoc, a[3], GEOMOBJECT_GUID, aContext)) return 1;
748
749 Handle(TDataStd_UAttribute) anObj = AddObject (aDoc);
750 if(!anObj.IsNull()) {
751 TDataStd_Name::Set(anObj->Label(), "Auxiliary_Object");
752 Standard_GUID funGUID;
753 if(GetFuncGUID("XAttach",funGUID)) {
754 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
755 if(!aFun.IsNull()) {
756 TDataStd_Name::Set(aFun->Label(), "XSelection");
757 TDF_Label aResultLabel = aFun->Label().FindChild(FUNCTION_RESULT_LABEL, Standard_True);
758 TDF_Reference::Set(anObj->Label(), aResultLabel ); //result
759 aResultLabel.ForgetAllAttributes(Standard_True);
760 Standard_Boolean aKeepOrientation(Standard_False);
761 if (nb >= 5)
dde68833 762 aKeepOrientation = Draw::Atoi(a[4]) != 0;
7fd59977 763 Standard_Boolean aGeometry(Standard_False);
764 if (nb == 6)
dde68833 765 aGeometry = Draw::Atoi(a[5]) != 0;
7fd59977 766 Handle(TNaming_NamedShape) aCont = DNaming::GetObjectValue(aContext);
767
768 if(aCont.IsNull() || aCont->IsEmpty())
769 cout <<"Wrong Context ..." <<endl;
770 else {
771 TopoDS_Shape aCONTEXT = aCont->Get();
772 try{
773 TNaming_Selector aSelector(aResultLabel);
774 if(!aSelector.Select(aShape, aCONTEXT, aGeometry, aKeepOrientation))
775 return 1;
b350f6ee 776 }
777 catch (Standard_Failure) {
7fd59977 778 cout << "EXCEPTION: SELECTION_IMPOSSIBLE" <<endl;
779 }
780
781 TDF_Reference::Set(aFun->Label().FindChild(FUNCTION_ARGUMENTS_LABEL).FindChild(ATTACH_ARG),
782 aContext->Label()); //ref to Context object
783
784 DDF::ReturnLabel(di, anObj->Label());
785 return 0;
786 }
787 }
788 }
789 }
790 }
791 cout << "DNaming_XAttachShape : Error" << endl;
792 return 1;
793}
794
795//=======================================================================
796//function : DNaming_AddCyl
797//purpose : "AddCyl Doc Radius Height Axis
798//=======================================================================
799static Standard_Integer DNaming_AddCylinder (Draw_Interpretor& theDI,
800 Standard_Integer theNb,
801 const char** theArg)
802{
803 if (theNb == 5) {
804
805 Handle(TDocStd_Document) aDocument;
806 Standard_CString aDocS(theArg[1]);
807 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
808 Handle(TDataStd_UAttribute) anObj = AddObject(aDocument);
809 if(anObj.IsNull()) return 1;
810 Standard_GUID funGUID;
811 if(!GetFuncGUID("Cyl",funGUID)) return 1;
812
813 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
814 if(aFun.IsNull()) return 1;
815 TDataStd_Name::Set(aFun->Label(), "Cyl_Function");
816
817 TDF_Reference::Set(anObj->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
818
819 Standard_Real aR, aH;
91322f44 820 aR = Draw::Atof(theArg[2]);
821 aH = Draw::Atof(theArg[3]);
7fd59977 822
823 Handle(TDataStd_UAttribute) Axis;
824 if (!DDocStd::Find(aDocument, theArg[4], GEOMOBJECT_GUID, Axis)) return 1;
825 DNaming::GetReal(aFun,CYL_RADIUS)->Set(aR);
826 DNaming::GetReal(aFun,CYL_HEIGHT)->Set(aH);
827 DNaming::SetObjectArg(aFun, CYL_AXIS, Axis);
828
829 DDF::ReturnLabel(theDI, anObj->Label());
830 return 0;
831 }
832 cout << "DNaming_AddCylinder : Error" << endl;
833 return 1;
834}
835
836//=======================================================================
837//function : DNaming_CylRad
838//purpose : "CylRad Doc CylLabel NewRad"
839//=======================================================================
840
841static Standard_Integer DNaming_CylRad (Draw_Interpretor& theDI,
842 Standard_Integer theNb,
843 const char** theArg)
844{
845 if (theNb == 4) {
846 Handle(TDocStd_Document) aDoc;
847 Standard_CString aDocS(theArg[1]);
848 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
849 TDF_Label objLabel;
850 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], objLabel)) return 1;
851
852 Handle(TDataStd_UAttribute) anObj;
853 if(!objLabel.FindAttribute(GEOMOBJECT_GUID, anObj)) return 1;
854 Standard_GUID funGUID;
855 if(!GetFuncGUID("Cyl",funGUID)) return 1;
856
857 Handle(TFunction_Function) aFun = GetFunction(objLabel,funGUID);
858 if(!aFun.IsNull()) {
91322f44 859 Standard_Real value = Draw::Atof(theArg[3]);
7fd59977 860 DNaming::GetReal(aFun,CYL_RADIUS)->Set(value);
861 DDF::ReturnLabel(theDI, DNaming::GetReal(aFun,CYL_RADIUS)->Label());
862 return 0;
863 }
864 }
865 cout << "DNaming_CylRadius : Error" << endl;
866 return 1;
867}
868
869//=======================================================================
870//function : DNaming_AddFuse
871//purpose : "AddFuse Doc Object Tool"
872//=======================================================================
873
874 static Standard_Integer DNaming_AddFuse (Draw_Interpretor& theDI,
875 Standard_Integer theNb,
876 const char** theArg)
877 {
878 if (theNb == 4) {
879
880 Handle(TDocStd_Document) aDocument;
881 Standard_CString aDocS(theArg[1]);
882 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
883
884 Handle(TDataStd_UAttribute) anObject, aTool;
885 if (!DDocStd::Find(aDocument, theArg[2], GEOMOBJECT_GUID, anObject)) return 1;
886 if (!DDocStd::Find(aDocument, theArg[3], GEOMOBJECT_GUID, aTool)) return 1;
887 Standard_GUID funGUID;
888 if(!GetFuncGUID("Fuse",funGUID)) return 1;
889 Handle(TFunction_Function) aFun = SetFunctionDS(anObject->Label(), funGUID);
890 if(aFun.IsNull()) return 1;
891 TDataStd_Name::Set(aFun->Label(), "Fuse");
892
893 TDF_Reference::Set(anObject->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
894 DNaming::SetObjectArg(aFun, BOOL_TOOL, aTool);
895 DDF::ReturnLabel(theDI, aFun->Label());
896 return 0;
897 }
898 cout << "DModel_AddFuse : Error" << endl;
899 return 1;
900 }
901
902
903//=======================================================================
904//function : DNaming_AddCut
905//purpose : "AddCut Doc Object Tool"
906//=======================================================================
907
908 static Standard_Integer DNaming_AddCut (Draw_Interpretor& theDI,
909 Standard_Integer theNb,
910 const char** theArg)
911 {
912 if (theNb == 4) {
913
914 Handle(TDocStd_Document) aDocument;
915 Standard_CString aDocS(theArg[1]);
916 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
917
918 Handle(TDataStd_UAttribute) anObject, aTool;
919 if (!DDocStd::Find(aDocument, theArg[2], GEOMOBJECT_GUID, anObject)) return 1;
920 if (!DDocStd::Find(aDocument, theArg[3], GEOMOBJECT_GUID, aTool)) return 1;
921 Standard_GUID funGUID;
922 if(!GetFuncGUID("Cut",funGUID)) return 1;
923 Handle(TFunction_Function) aFun = SetFunctionDS(anObject->Label(), funGUID);
924 if(aFun.IsNull()) return 1;
925 TDataStd_Name::Set(aFun->Label(), "Cut");
926
927 TDF_Reference::Set(anObject->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
928 DNaming::SetObjectArg(aFun, BOOL_TOOL, aTool);
929 DDF::ReturnLabel(theDI, aFun->Label());
930 return 0;
931 }
932 cout << "DModel_AddCut : Error" << endl;
933 return 1;
934 }
935
936//=======================================================================
937//function : DNaming_AddCommon
938//purpose : "AddCommon Doc Object Tool"
939//=======================================================================
940
941 static Standard_Integer DNaming_AddCommon (Draw_Interpretor& theDI,
942 Standard_Integer theNb,
943 const char** theArg)
944 {
945 if (theNb == 4) {
946
947 Handle(TDocStd_Document) aDocument;
948 Standard_CString aDocS(theArg[1]);
949 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
950
951 Handle(TDataStd_UAttribute) anObject, aTool;
952 if (!DDocStd::Find(aDocument, theArg[2], GEOMOBJECT_GUID, anObject)) return 1;
953 if (!DDocStd::Find(aDocument, theArg[3], GEOMOBJECT_GUID, aTool)) return 1;
954 Standard_GUID funGUID;
955 if(!GetFuncGUID("Comm",funGUID)) return 1;
956 Handle(TFunction_Function) aFun = SetFunctionDS(anObject->Label(), funGUID);
957 if(aFun.IsNull()) return 1;
958 TDataStd_Name::Set(aFun->Label(), "Common");
959
960 TDF_Reference::Set(anObject->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
961 DNaming::SetObjectArg(aFun, BOOL_TOOL, aTool);
962 DDF::ReturnLabel(theDI, aFun->Label());
963 return 0;
964 }
965 cout << "DModel_AddComm : Error" << endl;
966 return 1;
967 }
968
372ceec4 969//=======================================================================
970//function : DNaming_AddSection
971//purpose : "AddSection Doc Object Tool"
972//=======================================================================
973
974 static Standard_Integer DNaming_AddSection (Draw_Interpretor& theDI,
975 Standard_Integer theNb, const char** theArg)
976 {
977 if (theNb == 4) {
978
979 Handle(TDocStd_Document) aDocument;
980 Standard_CString aDocS(theArg[1]);
981 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
982
983 Handle(TDataStd_UAttribute) anObject, aTool;
984 if (!DDocStd::Find(aDocument, theArg[2], GEOMOBJECT_GUID, anObject)) return 1;
985 if (!DDocStd::Find(aDocument, theArg[3], GEOMOBJECT_GUID, aTool)) return 1;
986 Standard_GUID funGUID;
987 if(!GetFuncGUID("Section",funGUID)) return 1;
988 Handle(TFunction_Function) aFun = SetFunctionDS(anObject->Label(), funGUID);
989 if(aFun.IsNull()) return 1;
990 TDataStd_Name::Set(aFun->Label(), "Section");
991
992 TDF_Reference::Set(anObject->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
993 DNaming::SetObjectArg(aFun, BOOL_TOOL, aTool);
994 DDF::ReturnLabel(theDI, aFun->Label());
995 return 0;
996 }
997 cout << "DModel_AddSection : Error" << endl;
998 return 1;
999 }
1000
7fd59977 1001//=======================================================================
1002//function : DNaming_AddFillet
1003//purpose : "AddFillet Doc Object Radius Path "
1004//=======================================================================
1005static Standard_Integer DNaming_AddFillet (Draw_Interpretor& theDI,
1006 Standard_Integer theNb,
1007 const char** theArg)
1008{
1009 if (theNb < 5) {
1010 cout<<"DNaming_AddFillet(): Wrong number of arguments"<<endl;
1011 return 1;
1012 }
1013
1014 Handle(TDocStd_Document) aDocument;
1015 Standard_CString aDocS(theArg[1]);
1016 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1017
1018 Handle(TDataStd_UAttribute) anObject;
1019 if (!DDocStd::Find(aDocument, theArg[2], GEOMOBJECT_GUID, anObject)) return 1;
1020 Standard_GUID funGUID;
1021 if(!GetFuncGUID("Fillet",funGUID)) return 1;
1022 Handle(TFunction_Function) aFun = SetFunctionDS(anObject->Label(), funGUID);
1023 if(aFun.IsNull()) return 1;
1024 TDataStd_Name::Set(aFun->Label(), "Fillet");
1025
1026 TDF_Reference::Set(anObject->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
1027
91322f44 1028 Standard_Real aRadius = Draw::Atof(theArg[3]);
7fd59977 1029 DNaming::GetReal(aFun,FILLET_RADIUS)->Set(aRadius);
1030
1031 Handle(TDataStd_UAttribute) aPath;
1032 if (!DDocStd::Find(aDocument, theArg[4], GEOMOBJECT_GUID, aPath)) return 1;
1033 DNaming::SetObjectArg(aFun, FILLET_PATH, aPath);
1034 DDF::ReturnLabel(theDI, aFun->Label());
1035 return 0;
1036}
1037
1038//=======================================================================
1039//function : DNaming_TranslatePar
1040//purpose : "TranslatePar Doc ShapeEntry dx dy dz"
1041//=======================================================================
1042static Standard_Integer DNaming_PTranslateDXYZ (Draw_Interpretor& di,
1043 Standard_Integer nb,
1044 const char** a)
1045{
1046 if (nb > 3) {
0797d9d3 1047#ifdef OCCT_DEBUG
7fd59977 1048 cout << "NB = " << nb <<endl;
1049#endif
1050 Handle(TDocStd_Document) aDocument;
1051 Standard_CString aDocS(a[1]);
1052 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1053
1054 Handle(TDataStd_UAttribute) anObject;// aShape;
1055 if (!DDocStd::Find(aDocument, a[2], GEOMOBJECT_GUID, anObject)) return 1;
1056
1057 Standard_GUID funGUID;
1058 if(!GetFuncGUID("PTxyz",funGUID)) return 1;
1059 Handle(TFunction_Function) aFun = SetFunctionDS(anObject->Label(), funGUID);
1060 if(aFun.IsNull()) return 1;
1061 TDataStd_Name::Set(aFun->Label(), "ParTranslation");
1062
1063 Standard_Real aDx=0., aDy=0., aDz=0.;
91322f44 1064 aDx = Draw::Atof(a[3]);
7fd59977 1065 //cout << "DX = " << aDx<<endl;
1066 if(nb > 4) {
91322f44 1067 aDy = Draw::Atof(a[4]);
7fd59977 1068 //cout << "DY = " << aDy<<endl;
1069 if(nb > 5) {
91322f44 1070 aDz = Draw::Atof(a[5]);
7fd59977 1071 //cout << "DZ = " << aDz<<endl;
1072 }
1073 }
1074
1075 DNaming::GetReal(aFun,PTRANSF_DX)->Set(aDx);
1076 DNaming::GetReal(aFun,PTRANSF_DY)->Set(aDy);
1077 DNaming::GetReal(aFun,PTRANSF_DZ)->Set(aDz);
1078 TDF_Reference::Set(anObject->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL));
1079 DDF::ReturnLabel(di, aFun->Label());
1080 return 0;
1081 }
1082 cout << "DNaming_Translate : Error" << endl;
1083 return 1;
1084}
1085//=======================================================================
1086//function : DNaming_PTranslateLine
1087//purpose : "PTranslateAlongLine Doc ShapeEntry Line off"
1088//=======================================================================
1089static Standard_Integer DNaming_PTranslateLine (Draw_Interpretor& di,
1090 Standard_Integer nb,
1091 const char** a)
1092{
1093 if (nb > 4) {
0797d9d3 1094#ifdef OCCT_DEBUG
7fd59977 1095 cout << "NB = " << nb <<endl;
1096#endif
1097 Handle(TDocStd_Document) aDocument;
1098 Standard_CString aDocS(a[1]);
1099 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1100
1101 Handle(TDataStd_UAttribute) anObject, aLine;// aShape, aLine;
1102 if (!DDocStd::Find(aDocument, a[2], GEOMOBJECT_GUID, anObject)) return 1;
1103 if (!DDocStd::Find(aDocument, a[3], GEOMOBJECT_GUID, aLine)) return 1;
1104
1105 Standard_GUID funGUID;
1106 if(!GetFuncGUID("PTALine",funGUID)) return 1;
1107 Handle(TFunction_Function) aFun = SetFunctionDS(anObject->Label(), funGUID);
1108 if(aFun.IsNull()) return 1;
1109 TDataStd_Name::Set(aFun->Label(), "ParTranslationAlongLine");
1110
1111 Standard_Real anOff = 0.;
91322f44 1112 anOff = Draw::Atof(a[4]);
7fd59977 1113 DNaming::GetReal(aFun,PTRANSF_OFF)->Set(anOff);
1114
1115 DNaming::SetObjectArg(aFun, PTRANSF_LINE, aLine);
1116 TDF_Reference::Set(anObject->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL));
1117
1118 DDF::ReturnLabel(di, aFun->Label());
1119 return 0;
1120 }
1121 cout << "DNaming_PTranslateAlongLine : Error" << endl;
1122 return 1;
1123}
1124
1125//=======================================================================
1126//function : DNaming_PRotateLine
1127//purpose : "PRotateRoundLine Doc ShapeEntry Line Angle"
1128//=======================================================================
1129static Standard_Integer DNaming_PRotateLine(Draw_Interpretor& di,
1130 Standard_Integer nb,
1131 const char** a)
1132{
1133 if (nb > 4) {
1134 Handle(TDocStd_Document) aDocument;
1135 Standard_CString aDocS(a[1]);
1136 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1137
1138 Handle(TDataStd_UAttribute) anObject, aLine;// aShape, aLine;
1139 if (!DDocStd::Find(aDocument, a[2], GEOMOBJECT_GUID, anObject)) return 1;
1140 if (!DDocStd::Find(aDocument, a[3], GEOMOBJECT_GUID, aLine)) return 1;
1141
1142 Standard_GUID funGUID;
1143 if(!GetFuncGUID("PRLine",funGUID)) return 1;
1144 Handle(TFunction_Function) aFun = SetFunctionDS(anObject->Label(), funGUID);
1145 if(aFun.IsNull()) return 1;
1146 TDataStd_Name::Set(aFun->Label(), "ParRotationAroundLine");
1147
1148 DNaming::SetObjectArg(aFun, PTRANSF_LINE, aLine);
1149 TDF_Reference::Set(anObject->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL));
1150
1151 Standard_Real anAngle = 0.;
91322f44 1152 anAngle = Draw::Atof(a[4]);
c6541a0c 1153 Standard_Real aK = 2*M_PI/360;
7fd59977 1154 anAngle = anAngle * aK;
1155 DNaming::GetReal(aFun,PTRANSF_ANG)->Set(anAngle);
1156
1157 DDF::ReturnLabel(di, aFun->Label());
1158 return 0;
1159 }
1160 cout << "DNaming_PRotateRoundLine : Error" << endl;
1161 return 1;
1162}
1163
1164//=======================================================================
1165//function : DNaming_PMirrorObject
1166//purpose : "PMirror Doc ShapeEntry PlaneObj"
1167//=======================================================================
1168static Standard_Integer DNaming_PMirrorObject(Draw_Interpretor& di,
1169 Standard_Integer nb,
1170 const char** a)
1171{
1172 if (nb > 3) {
1173 Handle(TDocStd_Document) aDocument;
1174 Standard_CString aDocS(a[1]);
1175 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1176
1177 Handle(TDataStd_UAttribute) anObject, aPlane;
1178 if (!DDocStd::Find(aDocument, a[2], GEOMOBJECT_GUID, anObject)) return 1;
1179 if (!DDocStd::Find(aDocument, a[3], GEOMOBJECT_GUID, aPlane)) return 1;
1180
1181 Standard_GUID funGUID;
1182 if(!GetFuncGUID("PMirr",funGUID)) return 1;
1183 Handle(TFunction_Function) aFun = SetFunctionDS(anObject->Label(), funGUID);
1184 if(aFun.IsNull()) return 1;
1185 TDataStd_Name::Set(aFun->Label(), "ParMirror");
1186
1187 DNaming::SetObjectArg(aFun, PTRANSF_PLANE, aPlane);
1188 TDF_Reference::Set(anObject->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL));
1189
1190 DDF::ReturnLabel(di, aFun->Label());
1191 return 0;
1192 }
1193 cout << "DNaming_PMirrorObject : Error" << endl;
1194 return 1;
1195}
1196//=======================================================================
1197//function : DModel_AddPrism
1198//purpose : "AddPrism Doc BasisLabel Height Reverse(0/1)"
1199//=======================================================================
1200static Standard_Integer DNaming_AddPrism (Draw_Interpretor& theDI,
1201 Standard_Integer theNb,
1202 const char** theArg)
1203{
1204 if (theNb < 5 ) {
1205 cout<<"DNaming_AddPrism(): Wrong number of arguments"<<endl;
1206 return 1;
1207 }
1208//
1209 Handle(TDocStd_Document) aDocument;
1210 Standard_CString aDocS(theArg[1]);
1211 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1212
1213 Handle(TDataStd_UAttribute) anObj = AddObject(aDocument);
1214 if(anObj.IsNull()) return 1;
1215 Standard_GUID funGUID;
1216 if(!GetFuncGUID("Prism",funGUID)) return 1;
1217 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
1218 if(aFun.IsNull()) return 1;
1219 TDataStd_Name::Set(aFun->Label(), "Prism_Function");
1220 TDF_Reference::Set(anObj->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
1221
1222 // arguments
1223 Handle(TDataStd_UAttribute) aBasisObj;
1224 if (!DDocStd::Find(aDocument, theArg[2], GEOMOBJECT_GUID, aBasisObj)) return 1;
1225 DNaming::SetObjectArg(aFun, PRISM_BASIS, aBasisObj);
91322f44 1226 Standard_Real height = Draw::Atof(theArg[3]);
7fd59977 1227 DNaming::GetReal(aFun,PRISM_HEIGHT)->Set(height);
91322f44 1228 Standard_Integer reverse = Draw::Atoi(theArg[4]);
7fd59977 1229 DNaming::GetInteger(aFun,PRISM_DIR)->Set(reverse);
1230 DDF::ReturnLabel(theDI, anObj->Label());
1231 return 0;
1232}
1233
1234//=======================================================================
1235//function : DNaming_PrismHeight
1236//purpose : "PrismHeight Doc PrismLabel NewHeight"
1237//=======================================================================
1238static Standard_Integer DNaming_PrismHeight (Draw_Interpretor& theDI,
1239 Standard_Integer theNb,
1240 const char** theArg)
1241{
1242 if (theNb == 4) {
1243 Handle(TDocStd_Document) aDoc;
1244 Standard_CString aDocS(theArg[1]);
1245 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
1246 TDF_Label objLabel;
1247 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], objLabel)) return 1;
1248
1249 Handle(TDataStd_UAttribute) anObj;
1250 if(!objLabel.FindAttribute(GEOMOBJECT_GUID, anObj)) return 1;
1251 Standard_GUID funGUID;
1252 if(!GetFuncGUID("Prism",funGUID)) return 1;
1253
1254 Handle(TFunction_Function) aFun = GetFunction(objLabel,funGUID);
1255 if(!aFun.IsNull()) {
91322f44 1256 Standard_Real value = Draw::Atof(theArg[3]);
7fd59977 1257 DNaming::GetReal(aFun, PRISM_HEIGHT)->Set(value);
1258 DDF::ReturnLabel(theDI, DNaming::GetReal(aFun,PRISM_HEIGHT)->Label());
1259 return 0;
1260 }
1261
1262 }
1263 cout << "DNaming_PrismHeight : Error" << endl;
1264 return 1;
1265}
1266
1267
1268//=======================================================================
1269//function : DModel_AddRevol
1270//purpose : "AddRevol Doc BasisLabel AxisLabel [Angle [Reverse(0/1)]] "
1271// : if Angle is presented - sectioned revolution, else - full
1272//=======================================================================
1273static Standard_Integer DNaming_AddRevol (Draw_Interpretor& theDI,
1274 Standard_Integer theNb,
1275 const char** theArg)
1276{
1277 if (theNb < 4 ) {
1278 cout<<"DNaming_AddRevol(): Wrong number of arguments"<<endl;
1279 return 1;
1280 }
1281
1282 Handle(TDocStd_Document) aDocument;
1283 Standard_CString aDocS(theArg[1]);
1284 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1285
1286 Handle(TDataStd_UAttribute) aBasisObj;
1287 if (!DDocStd::Find(aDocument, theArg[2], GEOMOBJECT_GUID, aBasisObj)) return 1;
1288
1289 Handle(TDataStd_UAttribute) anAxObj;
1290 if (!DDocStd::Find(aDocument, theArg[3], GEOMOBJECT_GUID, anAxObj)) return 1;
1291
1292 Standard_Boolean aFull = Standard_True;
1293 Handle(TDataStd_UAttribute) anObj = AddObject(aDocument);
1294 if(anObj.IsNull()) return 1;
1295 if(theNb > 4 )
1296 aFull = Standard_False;
1297 Standard_GUID funGUID;
1298 if(aFull) {
1299 if(!GetFuncGUID("FulRevol",funGUID)) return 1;
1300 }
1301 else
1302 if(!GetFuncGUID("SecRevol",funGUID)) return 1;
1303 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
1304 if(aFun.IsNull()) return 1;
1305 if(aFull)
1306 TDataStd_Name::Set(aFun->Label(), "FulRevol_Function");
1307 else
1308 TDataStd_Name::Set(aFun->Label(), "SecRevol_Function");
1309 TDF_Reference::Set(anObj->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
1310 DNaming::SetObjectArg(aFun, REVOL_BASIS, aBasisObj);
1311 DNaming::SetObjectArg(aFun, REVOL_AXIS, anAxObj);
1312
1313 if(theNb > 4 ) {
91322f44 1314 Standard_Real angle = Draw::Atof(theArg[4]);
c6541a0c 1315 Standard_Real aK = 2*M_PI/360;
7fd59977 1316 angle = angle * aK;
1317 DNaming::GetReal(aFun,REVOL_ANGLE)->Set(angle);
1318 if( theNb == 6) {
91322f44 1319 Standard_Integer reverse = Draw::Atoi(theArg[5]);
7fd59977 1320 DNaming::GetInteger(aFun, REVOL_REV)->Set(reverse);
1321 }
1322 }
1323 DDF::ReturnLabel(theDI, anObj->Label());
1324 return 0;
1325}
1326
1327//=======================================================================
1328//function : DNaming_RevolutionAngle
1329//purpose : "RevolutionAngle Doc RevolutionLabel NewAngle"
1330//=======================================================================
1331static Standard_Integer DNaming_RevolutionAngle (Draw_Interpretor& theDI,
1332 Standard_Integer theNb,
1333 const char** theArg)
1334{
1335 if (theNb == 4) {
1336 Handle(TDocStd_Document) aDoc;
1337 Standard_CString aDocS(theArg[1]);
1338 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
1339 TDF_Label objLabel;
1340 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], objLabel)) return 1;
1341
1342 Handle(TDataStd_UAttribute) anObj;
1343 if(!objLabel.FindAttribute(GEOMOBJECT_GUID, anObj)) return 1;
1344 Standard_GUID funGUID;
1345 if(!GetFuncGUID("SecRevol",funGUID)) return 1;
1346
1347 Handle(TFunction_Function) aFun = GetFunction(objLabel,funGUID);
1348 if(!aFun.IsNull()) {
91322f44 1349 Standard_Real value = Draw::Atof(theArg[3]);
7fd59977 1350 DNaming::GetReal(aFun, REVOL_ANGLE)->Set(value);
1351 DDF::ReturnLabel(theDI, DNaming::GetReal(aFun,REVOL_ANGLE)->Label());
1352 return 0;
1353 }
1354 }
1355 cout << "DNaming_RevolutionAngle : Error" << endl;
1356 return 1;
1357}
1358
1359//=======================================================================
1360//function : DNaming_AddSphere
1361//purpose : "AddSphere Doc CenterLabel Radius "
1362//=======================================================================
1363static Standard_Integer DNaming_AddSphere (Draw_Interpretor& theDI,
1364 Standard_Integer theNb,
1365 const char** theArg)
1366{
1367 if (theNb != 4) {
1368 cout<<"DNaming_AddSphere(): Wrong number of arguments"<<endl;
1369 return 1;
1370 }
1371 Handle(TDocStd_Document) aDocument;
1372 Standard_CString aDocS(theArg[1]);
1373 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1374
1375 Handle(TDataStd_UAttribute) anObj = AddObject(aDocument);
1376 if(anObj.IsNull()) return 1;
1377 Standard_GUID funGUID;
1378 if(!GetFuncGUID("Sph",funGUID)) return 1;
1379 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
1380 if(aFun.IsNull()) return 1;
1381 TDataStd_Name::Set(aFun->Label(), "Sphere_Function");
1382 TDF_Reference::Set(anObj->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
1383
1384 Handle(TDataStd_UAttribute) aCenterObj;
1385 if (!DDocStd::Find(aDocument, theArg[2], GEOMOBJECT_GUID, aCenterObj)) return 1;
1386 DNaming::SetObjectArg(aFun, SPHERE_CENTER, aCenterObj);
1387
91322f44 1388 Standard_Real aRadius = Draw::Atof(theArg[3]);
7fd59977 1389 DNaming::GetReal(aFun,SPHERE_RADIUS)->Set(aRadius);
1390
1391 DDF::ReturnLabel(theDI, anObj->Label());
1392 return 0;
1393}
1394
1395//=======================================================================
1396//function : DNaming_SphereRadius
1397//purpose : "SphereRadius Doc SphLabel NewRadius"
1398//=======================================================================
1399static Standard_Integer DNaming_SphereRadius (Draw_Interpretor& theDI,
1400 Standard_Integer theNb,
1401 const char** theArg)
1402{
1403 if (theNb == 4) {
1404 Handle(TDocStd_Document) aDoc;
1405 Standard_CString aDocS(theArg[1]);
1406 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
1407 TDF_Label objLabel;
1408 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], objLabel)) return 1;
1409
1410 Handle(TDataStd_UAttribute) anObj;
1411 if(!objLabel.FindAttribute(GEOMOBJECT_GUID, anObj)) return 1;
1412 Standard_GUID funGUID;
1413 if(!GetFuncGUID("Sph",funGUID)) return 1;
1414
1415 Handle(TFunction_Function) aFun = GetFunction(objLabel,funGUID);
1416 if(!aFun.IsNull()) {
91322f44 1417 Standard_Real value = Draw::Atof(theArg[3]);
7fd59977 1418 DNaming::GetReal(aFun, SPHERE_RADIUS)->Set(value);
1419 DDF::ReturnLabel(theDI, DNaming::GetReal(aFun, SPHERE_RADIUS)->Label());
1420 return 0;
1421 }
1422 }
6e6cd5d9 1423
7fd59977 1424 cout << "DNaming_SphRadius : Error" << endl;
1425 return 1;
1426}
1427//=======================================================================
1428//function : DNaming_AddPoint
1429//purpose : "AddPoint Doc x y z"
1430//=======================================================================
1431static Standard_Integer DNaming_AddPoint (Draw_Interpretor& theDI,
1432 Standard_Integer theNb,
1433 const char** theArg)
1434{
1435 if (theNb >= 4) {
1436
1437 Handle(TDocStd_Document) aDocument;
1438 Standard_CString aDocS(theArg[1]);
1439 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1440 Handle(TDataStd_UAttribute) anObj = AddObject(aDocument);
1441 if(anObj.IsNull()) return 1;
1442 Standard_GUID funGUID;
1443 if(!GetFuncGUID("PntXYZ",funGUID)) return 1;
1444
1445 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
1446 if(aFun.IsNull()) return 1;
1447 TDataStd_Name::Set(aFun->Label(), "PntXYZ_Function");
1448
1449 TDF_Reference::Set(anObj->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
1450 Standard_Real x,y,z;
91322f44 1451 x = Draw::Atof(theArg[2]);
1452 y = Draw::Atof(theArg[3]);
1453 z = Draw::Atof(theArg[4]);
7fd59977 1454
1455 DNaming::GetReal(aFun,PNT_DX)->Set(x);
1456 DNaming::GetReal(aFun,PNT_DY)->Set(y);
1457 DNaming::GetReal(aFun,PNT_DZ)->Set(z);
1458
1459 DDF::ReturnLabel(theDI, anObj->Label());
1460 return 0;
1461 }
1462 cout << "DNaming_AddPoint : Error" << endl;
1463 return 1;
1464}
1465
1466//=======================================================================
1467//function : DNaming_AddPointRlt
1468//purpose : "AddPointRlt Doc RefPnt dx dy dz"
1469//=======================================================================
1470static Standard_Integer DNaming_AddPointRlt (Draw_Interpretor& theDI,
1471 Standard_Integer theNb,
1472 const char** theArg)
1473{
1474 if (theNb >= 5) {
1475
1476 Handle(TDocStd_Document) aDocument;
1477 Standard_CString aDocS(theArg[1]);
1478 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1479 Handle(TDataStd_UAttribute) anObj = AddObject(aDocument);
1480 if(anObj.IsNull()) return 1;
1481 Standard_GUID funGUID;
1482 if(!GetFuncGUID("PntRLT",funGUID)) return 1;
1483
1484 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
1485 if(aFun.IsNull()) return 1;
1486 TDataStd_Name::Set(aFun->Label(), "PntRLT_Function");
1487
1488 TDF_Reference::Set(anObj->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
1489
1490 Handle(TDataStd_UAttribute) aRefPnt;
1491 if (!DDocStd::Find(aDocument, theArg[2], GEOMOBJECT_GUID, aRefPnt)) return 1;
1492
1493 Standard_Real dx,dy,dz;
91322f44 1494 dx = Draw::Atof(theArg[3]);
1495 dy = Draw::Atof(theArg[4]);
1496 dz = Draw::Atof(theArg[5]);
7fd59977 1497
1498 DNaming::GetReal(aFun,PNT_DX)->Set(dx);
1499 DNaming::GetReal(aFun,PNT_DY)->Set(dy);
1500 DNaming::GetReal(aFun,PNT_DZ)->Set(dz);
1501
1502 DNaming::SetObjectArg(aFun, PNTRLT_REF, aRefPnt);
1503
1504 DDF::ReturnLabel(theDI, anObj->Label());
1505 return 0;
1506 }
1507 cout << "DNaming_AddPoint : Error" << endl;
1508 return 1;
1509}
1510
1511//=======================================================================
1512//function : DNaming_PntOffset
1513//purpose : "PntOffset Doc PntLabel newDX newDY newDZ "
1514//=======================================================================
1515
1516static Standard_Integer DNaming_PntOffset (Draw_Interpretor& theDI,
1517 Standard_Integer theNb,
1518 const char** theArg)
1519{
1520 if (theNb == 6) {
1521 Handle(TDocStd_Document) aDoc;
1522 Standard_CString aDocS(theArg[1]);
1523 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
1524 TDF_Label objLabel;
1525 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], objLabel)) return 1;
1526
1527 Handle(TDataStd_UAttribute) anObj;
1528 if(!objLabel.FindAttribute(GEOMOBJECT_GUID, anObj)) return 1;
1529 Standard_GUID funGUID;
1530
1531 if(!GetFuncGUID("PntXYZ",funGUID)) {
1532 if(!GetFuncGUID("PntRLT",funGUID))
1533 return 1;
1534 }
1535
1536 Handle(TFunction_Function) aFun = GetFunction(objLabel,funGUID);
1537 if(!aFun.IsNull()) {
1538 Standard_Real value(0.0);
dde68833 1539 Standard_Boolean isDX = strcmp(theArg[3],"skip") != 0;
7fd59977 1540 if(isDX) {
91322f44 1541 value = Draw::Atof(theArg[3]);
7fd59977 1542 DNaming::GetReal(aFun,PNT_DX)->Set(value);
1543 }
dde68833 1544 Standard_Boolean isDY = strcmp(theArg[4],"skip") != 0;
7fd59977 1545 if(isDY) {
91322f44 1546 value = Draw::Atof(theArg[4]);
7fd59977 1547 DNaming::GetReal(aFun,PNT_DY)->Set(value);
1548 }
dde68833 1549 Standard_Boolean isDZ = strcmp(theArg[5],"skip") != 0;
7fd59977 1550 if(isDZ) {
91322f44 1551 value = Draw::Atof(theArg[5]);
7fd59977 1552 DNaming::GetReal(aFun,PNT_DZ)->Set(value);
1553 }
1554 if(isDX || isDY || isDZ)
1555 DDF::ReturnLabel(theDI, objLabel);
1556 else
1557 cout <<"DNaming_PntOffset : Nothing changed" << endl;
1558 return 0;
1559 }
1560 }
1561 cout << "DNaming_PntOffset : Error" << endl;
1562 return 1;
1563}
1564
1565//=======================================================================
1566//function : DNaming_AddLine3D
1567//purpose : "AddLine3D Doc CurveType(0|1) Pnt1Lab Pnt2Lab [Pnt3Lab [Pnt4Lab [...]]]"
1568// : Type = 0 - open, Type = 1 - closed
1569//=======================================================================
1570static Standard_Integer DNaming_Line3D (Draw_Interpretor& theDI,
1571 Standard_Integer theNb,
1572 const char** theArg)
1573{
1574 if (theNb < 5) {
1575 cout<<"DNaming_AddLine3D: Wrong number of arguments"<<endl;
1576 return 1;
1577 }
1578 Handle(TDocStd_Document) aDocument;
1579 Standard_CString aDocS(theArg[1]);
1580 if (!DDocStd::GetDocument(aDocS, aDocument)) return 1;
1581
1582 Handle(TDataStd_UAttribute) anObj = AddObject(aDocument);
1583 if(anObj.IsNull()) return 1;
1584 Standard_GUID funGUID;
1585 if(!GetFuncGUID("Line3D",funGUID)) return 1;
1586 Handle(TFunction_Function) aFun = SetFunctionDS(anObj->Label(), funGUID);
1587 if(aFun.IsNull()) return 1;
1588 TDataStd_Name::Set(aFun->Label(), "Line3D_Function");
1589 TDF_Reference::Set(anObj->Label(), aFun->Label().FindChild(FUNCTION_RESULT_LABEL)); //result is here
1590
91322f44 1591 Standard_Integer aType = Draw::Atoi(theArg[2]);
7fd59977 1592 DNaming::GetInteger(aFun,LINE3D_TYPE)->Set(aType);
1593
1594//LINE3D_PNTNB
1595 //set Pnts
1596 Standard_Integer aPos = LINE3D_TYPE;
1597 for(Standard_Integer i=3; i < theNb; i++) {
1598 Handle(TDataStd_UAttribute) aPntObj;
1599 if (!DDocStd::Find(aDocument, theArg[i], GEOMOBJECT_GUID, aPntObj)) return 1;
1600 aPos++;
1601 DNaming::SetObjectArg(aFun, aPos, aPntObj);
1602 }
1603
1604 DNaming::GetInteger(aFun,LINE3D_PNTNB)->Set(aPos - 1);//set number of points
1605
1606 DDF::ReturnLabel(theDI, anObj->Label());
1607 return 0;
1608}
1609// ***
1610//==========================================================================================
1611inline static void MapOfOrientedShapes(const TopoDS_Shape& S, TopTools_MapOfOrientedShape& M)
1612{
1613 M.Add(S);
1614 TopoDS_Iterator It(S,Standard_True,Standard_True);
1615 while (It.More()) {
1616 MapOfOrientedShapes(It.Value(),M);
1617 It.Next();
1618 }
1619}
1620//==========================================================================================
1621static void MapOfOrientedShapes(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
1622 TopTools_MapOfOrientedShape& M) {
1623
1624 TopoDS_Iterator it(S2,Standard_True,Standard_True);
1625 while (it.More()) {
1626 if(it.Value().ShapeType() == S1.ShapeType())
1627 M.Add(it.Value());
1628 it.Next();
1629 }
1630}
1631
1632//==========================================================================================
1633static void MapOfShapes(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
1634 TopTools_MapOfShape& M) {
1635
1636 TopoDS_Iterator it(S2,Standard_True,Standard_True);
1637 while (it.More()) {
1638 if(it.Value().ShapeType() == S1.ShapeType())
1639 M.Add(it.Value());
1640 it.Next();
1641 }
1642}
1643//==========================================================================================
1644inline static void CollectShapes(const TopoDS_Shape& S, TopTools_ListOfShape& List)
1645{
1646 List.Append(S);
1647 TopoDS_Iterator It(S,Standard_True,Standard_True);
1648 while (It.More()) {
1649 CollectShapes(It.Value(),List);
1650 It.Next();
1651 }
1652}
1653
1654//==========================================================================================
1655inline static void CollectMultShapes(const TopoDS_Shape& S, TopTools_ListOfShape& List)
1656{
1657 TopAbs_ShapeEnum aType = S.ShapeType();
1658 Standard_Integer aStop (TopAbs_SHAPE);
1659 for(Standard_Integer i = (Standard_Integer)aType +1; i < aStop; i++) {
1660 BRep_Builder aBuilder;
1661 TopoDS_Compound aCompound;
1662 aBuilder.MakeCompound(aCompound);
1663 TopExp_Explorer exp(S,(TopAbs_ShapeEnum)i);
1664 for (;exp.More();exp.Next())
1665 aBuilder.Add(aCompound, exp.Current());
1666 List.Append(aCompound);
1667 }
1668}
1669//==========================================================================================
1670static Standard_Boolean MakeSelection (const Handle(TDataStd_UAttribute)& Obj,
1671 const TopoDS_Shape& Selection,
1672 const Handle(TDataStd_UAttribute)& ContextObj,
1673 const Standard_Boolean Geometry,
1674 const Standard_Boolean KeepOrientation)
1675{
1676 if(!Obj.IsNull()) {
1677 Handle(TDataStd_TreeNode) aNode,RNode;
1678 Obj->Label().FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode);
1679 if(aNode.IsNull())
1680 aNode = TDataStd_TreeNode::Set(Obj->Label());
1681 aNode->Remove();
1682 Handle(TDataStd_UAttribute) aContainer = ContextObj;
1683 if(aContainer->Label().FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), RNode))
1684 RNode->Append(aNode);
1685 TDataStd_Name::Set(Obj->Label(), "Auxiliary_Object");
1686 Standard_GUID funGUID;
1687 if(GetFuncGUID("Attach",funGUID)) {
1688 Handle(TFunction_Function) aFun = SetFunctionDS(Obj->Label(), funGUID);
1689 if(!aFun.IsNull()) {
1690 TDataStd_Name::Set(aFun->Label(), "ISelection");
1691 TDF_Label aResultLabel = aFun->Label().FindChild(FUNCTION_RESULT_LABEL, Standard_True);
1692 TDF_Reference::Set(Obj->Label(), aResultLabel ); //result of the object
1693 aResultLabel.ForgetAllAttributes(Standard_True);
7fd59977 1694 Handle(TNaming_NamedShape) aNS = DNaming::GetObjectValue( ContextObj);
1695 try{
1696 const TopoDS_Shape& aContext = aNS->Get();
1697 TNaming_Selector aSelector(aResultLabel);
1698 if(!aSelector.Select(Selection, aContext, Geometry, KeepOrientation))
1699 return Standard_False;
1700 }catch (...) {
1701 cout << "EXCEPTION: SELECTION_IMPOSSIBLE" <<endl;
1702 }
1703
1704 if(!aNS.IsNull()) {
1705
1706 //TCollection_AsciiString entry;
1707 //TDF_Tool::Entry(aNS->Label(), entry);
1708 //cout << "ContextNS Label = " << entry <<endl;
1709 Handle(TFunction_Function) aCntFun;
1710 if(aNS->Label().Father().FindAttribute(TFunction_Function::GetID(), aCntFun)) { //Fun:2 ==> result
1711 // First argument of Selection function refers to father function (of context object)
1712 // to which selection is attached (because sel obj. itself already has refrence to result NS
1713 TDF_Reference::Set(aFun->Label().FindChild(FUNCTION_ARGUMENTS_LABEL).FindChild(ATTACH_ARG),
1714 aCntFun->Label()); //ref to function produced Context shape
1715
1716 }
1717 }
1718 return Standard_True;
1719 }
1720 }
1721 }
1722 return Standard_False;
1723}
1724
1725//==========================================================================================
1726static Standard_Boolean MakeXSelection (const Handle(TDataStd_UAttribute)& Obj,
1727 const TopoDS_Shape& Selection,
1728 const Handle(TDataStd_UAttribute)& ContextObj,
1729 const Standard_Boolean Geometry,
1730 const Standard_Boolean KeepOrientation)
1731{
1732 if(!Obj.IsNull()) {
1733/* Handle(TDataStd_TreeNode) aNode,RNode;
1734 Obj->Label().FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode);
1735 if(aNode.IsNull())
1736 aNode = TDataStd_TreeNode::Set(Obj->Label());
1737 aNode->Remove();
1738 Handle(TDataStd_UAttribute) aContainer = ContextObj;
1739 if(aContainer->Label().FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), RNode))
1740 RNode->Append(aNode);
1741*/
1742 TDataStd_Name::Set(Obj->Label(), "Auxiliary_Object");
1743 Standard_GUID funGUID;
1744 if(GetFuncGUID("XAttach",funGUID)) {
1745 Handle(TFunction_Function) aFun = SetFunctionDS(Obj->Label(), funGUID);
1746 if(!aFun.IsNull()) {
1747 TDataStd_Name::Set(aFun->Label(), "XSelection");
1748 TDF_Label aResultLabel = aFun->Label().FindChild(FUNCTION_RESULT_LABEL, Standard_True);
1749 TDF_Reference::Set(Obj->Label(), aResultLabel ); //result of the object
1750 aResultLabel.ForgetAllAttributes(Standard_True);
1751
7fd59977 1752 Handle(TNaming_NamedShape) aNS = DNaming::GetObjectValue( ContextObj);
1753 try{
1754 const TopoDS_Shape& aContext = aNS->Get();
1755 TNaming_Selector aSelector(aResultLabel);
1756 if(!aSelector.Select(Selection, aContext, Geometry, KeepOrientation))
1757 return Standard_False;
1758 }catch (...) {
1759 cout << "EXCEPTION: SELECTION_IMPOSSIBLE" <<endl;
1760 }
1761
1762 if(!aNS.IsNull()) {
1763
1764 //TCollection_AsciiString entry;
1765 //TDF_Tool::Entry(aNS->Label(), entry);
1766 //cout << "ContextNS Label = " << entry <<endl;
1767 Handle(TFunction_Function) aCntFun;
1768 if(aNS->Label().Father().FindAttribute(TFunction_Function::GetID(), aCntFun)) { //Fun:2 ==> result
1769 // First argument of Selection function refers to father function (of context object)
1770 // to which selection is attached (because sel obj. itself already has refrence to result NS
1771 TDF_Reference::Set(aFun->Label().FindChild(FUNCTION_ARGUMENTS_LABEL).FindChild(ATTACH_ARG),
1772 aCntFun->Label()); //ref to function produced Context shape
1773
1774 }
1775 }
1776 return Standard_True;
1777 }
1778 }
1779 }
1780 return Standard_False;
1781}
1782//=======================================================================
1783inline static TCollection_ExtendedString compareShapes(const TopoDS_Shape& theShape1,
1784 const TopoDS_Shape& theShape2,
1785 const Standard_Boolean keepOrientation)
1786{
1787 TCollection_ExtendedString aResult("");
1788
1789 if((theShape1.ShapeType() != TopAbs_COMPOUND) &&
1790 theShape2.ShapeType() == TopAbs_COMPOUND) {
1791 if(keepOrientation) {
1792 TopTools_MapOfOrientedShape M;
1793 MapOfOrientedShapes(theShape1, theShape2, M);
1794 if(M.Contains(theShape1)) {
1795 aResult+=" Warning => Type migration to Compound";
1796 return aResult;
1797 }
1798 } else {
1799 TopTools_MapOfShape M;
1800 MapOfShapes(theShape1, theShape2, M);
1801 if(M.Contains(theShape1)) {
1802 aResult+=" Warning => Type migration to Compound";
1803 return aResult;
1804 }
1805 }
1806 }
1807 Standard_Boolean isComma=Standard_False;
1808 if(theShape1.ShapeType() != theShape2.ShapeType()) {
1809 aResult+=" Type was changed:";
1810 aResult+=" Initial type = "; aResult+= TCollection_ExtendedString(theShape1.ShapeType());
1811 aResult+="; Resulting type = "; aResult+= TCollection_ExtendedString(theShape2.ShapeType());
1812 isComma = Standard_True;
1813 } else if(theShape1.TShape() != theShape2.TShape()) {
1814 aResult+=" TShape was changed";
1815 isComma = Standard_True;
1816 } else if(theShape1.Location()!=theShape2.Location()) {
1817 aResult+=" Location was changed";
1818 isComma = Standard_True;
1819 }
1820
1821 if(keepOrientation) {
1822 if(theShape1.Orientation()!=theShape2.Orientation() && theShape1.ShapeType() != TopAbs_VERTEX) {
1823 if(theShape2.ShapeType() != TopAbs_COMPOUND) {
1824 if(isComma)
1825 aResult+=",";
1826 aResult+=" Orientation was changed";
1827 }
1828 else {
1829 TopoDS_Iterator it(theShape2);
1830 for(;it.More(); it.Next()) {
1831 if(it.Value().IsSame(theShape1))
1832 if(theShape1.Orientation()!=it.Value().Orientation()) {
1833 if(isComma)
1834 aResult+=",";
1835 aResult+=" Orientation was changed";
1836 }
1837 }
1838 }
1839 }
1840 }
1841 return aResult;
1842}
1843
1844//=======================================================================
1845inline static TCollection_ExtendedString compareShapes(const TopoDS_Shape& theShape,
1846 //theShape - Compound of Multiple selection
1847 const TopTools_MapOfOrientedShape& aMap)
1848{
1849 TCollection_ExtendedString aResult("");
1850 if(theShape.ShapeType() != TopAbs_COMPOUND) {
1851 aResult+="the specified shape is not COMPOUND";
1852 } else {
1853 TopoDS_Iterator it(theShape);
1854 for(;it.More();it.Next()) {
1855 const TopoDS_Shape& newShape = it.Value();
1856 if(!aMap.Contains(newShape)) {
1857 aResult+=" Not in the context";
1858 }
1859 }
1860 }
1861 return aResult;
1862}
1863//=======================================================================
1864//function : IntegerToShapeEnum
1865//purpose :
1866//=======================================================================
1867
1868static TCollection_AsciiString ShapeEnumToString (const TopAbs_ShapeEnum type)
1869{
1870 switch(type)
1871 {
1872 case TopAbs_COMPOUND : return TCollection_AsciiString("COMPOUND");
1873 case TopAbs_COMPSOLID : return TCollection_AsciiString("COMPSOLID");
1874 case TopAbs_SOLID : return TCollection_AsciiString("SOLID");
1875 case TopAbs_SHELL : return TCollection_AsciiString("SHELL");
1876 case TopAbs_FACE : return TCollection_AsciiString("FACE");
1877 case TopAbs_WIRE : return TCollection_AsciiString("WIRE");
1878 case TopAbs_EDGE : return TCollection_AsciiString("EDGE");
1879 case TopAbs_VERTEX : return TCollection_AsciiString("VERTEX");
1880 case TopAbs_SHAPE : return TCollection_AsciiString("SHAPE");
1881 }
1882 return TCollection_AsciiString("SHAPE");
1883}
1884//=======================================================================
1885//function : DNaming_TestSingle
1886//purpose : "TestSingleSelection Doc ObjectLabel [Orientation [Xselection [Geometry]]]"
1887// : returns DDF::ReturnLabel of a first Aux object
1888//=======================================================================
1889static Standard_Integer DNaming_TestSingle (Draw_Interpretor& theDI,
1890 Standard_Integer theNb,
1891 const char** theArg)
1892{
1893 if (theNb >= 3) {
1894 Handle(TDocStd_Document) aDoc;
1895 Standard_CString aDocS(theArg[1]);
1896 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
1897 TDF_Label ObjLabel;
1898 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], ObjLabel)) return 1;
1899
1900 Handle(TDataStd_UAttribute) aCntObj;
1901 if(!ObjLabel.FindAttribute(GEOMOBJECT_GUID, aCntObj)) return 1;
1902 Standard_Boolean Orientation(Standard_False);
1903 Standard_Boolean XSelection(Standard_False);
1904 Standard_Boolean Geometry(Standard_False);
1905 if(theNb == 4)
dde68833 1906 Orientation = Draw::Atoi(theArg[3]) != 0;
7fd59977 1907 if(theNb == 5)
dde68833 1908 XSelection = Draw::Atoi(theArg[4]) != 0;
7fd59977 1909 if (theNb == 6)
dde68833 1910 Geometry = Draw::Atoi(theArg[5]) != 0;
7fd59977 1911 Handle(TNaming_NamedShape) aNS = DNaming::GetObjectValue( aCntObj);
1912
1913 if(!aNS.IsNull() && !aNS->IsEmpty()) {
1914 const TopoDS_Shape& aRootShape = aNS->Get();
7fd59977 1915 //TopTools_MapOfOrientedShape aMap0;
1916 //MapOfOrientedShapes(aRootShape, aMap0);
1917 TopTools_ListOfShape aList, aFailedList;
1918 CollectShapes(aRootShape, aList);
1919 if(aList.Extent())
1920 aList.RemoveFirst();
1921 Standard_Boolean isFirst(Standard_True);
1922 Handle(TDataStd_UAttribute) FirstAuxObj;
1923 TopTools_ListIteratorOfListOfShape it(aList);
1924 for(; it.More(); it.Next()) {
1925 const TopoDS_Shape& aCurShape = it.Value();
1926 if(aCurShape.IsNull()) continue;
1927 if(aCurShape.ShapeType() == TopAbs_EDGE) {
1928 if (BRep_Tool::Degenerated(TopoDS::Edge(aCurShape)))
1929 continue;
1930 }
1931 Handle(TDataStd_UAttribute) auxObj = AddObject (aDoc);
1932 if(isFirst) {
1933 FirstAuxObj = auxObj;
1934 isFirst = Standard_False;
1935 TCollection_AsciiString entry;
1936 TDF_Tool::Entry(FirstAuxObj->Label(), entry);
0797d9d3 1937#ifdef OCCT_DEBUG
7fd59977 1938 cout << "First Selection function at " << entry <<endl;
1939#endif
1940 }
1941 Standard_Boolean isSelected (Standard_False);
1942 try {
1943 OCC_CATCH_SIGNALS
1944 {
1945 if(!XSelection)
1946 isSelected = MakeSelection(auxObj, aCurShape, aCntObj, Geometry, Orientation);
1947 else
1948 isSelected = MakeXSelection(auxObj, aCurShape, aCntObj, Geometry, Orientation);
1949 }
1950 }
1951 catch (Standard_Failure) {
1952 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
1953 cout << "%%%INFO:Error: ::TestSingleSelection failed :";
1954 if (!aFailure.IsNull())
1955 cout << aFailure->GetMessageString() << endl;
1956 else
1957 cout << "%%%INFO:Error: ::TestSingleSelection : Standard_Failure with null caught failure"<< endl;
1958 }
1959 catch(...) {
1960 cout << "%%%INFO:Error: ::TestSingleSelection selection failed : unknown exception type";
1961 }
1962 TCollection_AsciiString entry;
1963 TDF_Tool::Entry(auxObj->Label(), entry);
1964 TCollection_ExtendedString aResult("");
1965 if(isSelected) {
1966 const Handle(TNaming_NamedShape)& aSelNS = DNaming::GetObjectValue(auxObj);
1967 if(!aSelNS.IsNull() && !aSelNS->IsEmpty()) {
1968 const TopoDS_Shape& aSelectedShape = aSelNS->Get();
1969 aResult += compareShapes(aCurShape, aSelectedShape,Orientation);
1970 TDF_ChildIDIterator itn(auxObj->Label(),TNaming_Naming::GetID(), Standard_True);
1971 for(;itn.More();itn.Next()) {
1972 Handle(TNaming_Naming) aNaming = Handle(TNaming_Naming)::DownCast(itn.Value());
1973 if(!aNaming.IsNull()) {
1974 const TNaming_Name& aName = aNaming->GetName();
1975 if(aName.Type() == TNaming_UNKNOWN) {
1976 aResult += " Selection at label = ";
1977 aResult += entry;
1978 aResult += " has UNKNOWN name type, shape type = ";
1979 aResult += ShapeEnumToString(aCurShape.ShapeType());
1980 }
1981
1982 }
1983 }
1984 }
1985 } else {
1986 aResult += " Selection at label = ";
1987 aResult += entry;
1988 aResult += " failed, shape type = ";
1989 aResult += ShapeEnumToString(aCurShape.ShapeType());
1990 aFailedList.Append(aCurShape);
1991 }
1992 if(aResult.Length()) {
1993 if(aResult.Search("Warning") == -1)
1994 cout << "Failed units: " << aResult << " at " << entry << endl;
1995 else
1996 cout << aResult << " at " << entry << endl;
1997 TDataStd_Name::Set(auxObj->Label(), aResult);
1998 }
1999 }
2000 if(aFailedList.Extent()) {
2001 cout << "Failed units are kept at: ";
2002 TopTools_ListIteratorOfListOfShape it1(aFailedList);
2003 for(; it1.More(); it1.Next()) {
2004 const TDF_Label& aLabel = TDF_TagSource::NewChild(aDoc->Main());
2005
2006 TNaming_Builder B(aLabel);
2007 B.Generated(it1.Value());
2008 TCollection_AsciiString entry;
2009 TDF_Tool::Entry(aLabel, entry);
2010 cout << "\t" <<entry <<endl;
2011 }
2012 }
2013 if(!FirstAuxObj.IsNull())
2014 DDF::ReturnLabel(theDI, FirstAuxObj->Label());
2015 return 0;
2016 }
2017 }
6e6cd5d9 2018
7fd59977 2019 cout << "DNaming_TestSingle : Error" << endl;
2020 return 1;
2021}
2022
2023//=======================================================================
2024//function : DNaming_Multiple
2025//purpose : "TestMultipleSelection Doc ObjectLabel [Orientation [Xselection [Geometry]]]"
2026// : returns DDF::ReturnLabel of a first Aux object
2027//=======================================================================
2028static Standard_Integer DNaming_Multiple (Draw_Interpretor& theDI,
2029 Standard_Integer theNb,
2030 const char** theArg)
2031{
2032 if (theNb >= 3) {
2033 Handle(TDocStd_Document) aDoc;
2034 Standard_CString aDocS(theArg[1]);
2035 if (!DDocStd::GetDocument(aDocS, aDoc)) return 1;
2036 TDF_Label ObjLabel;
2037 if (!DDF::FindLabel(aDoc->GetData(),theArg[2], ObjLabel)) return 1;
2038
2039 Handle(TDataStd_UAttribute) aCntObj;
2040 if(!ObjLabel.FindAttribute(GEOMOBJECT_GUID, aCntObj)) return 1;
2041 Standard_Boolean Orientation(Standard_False);
2042 Standard_Boolean XSelection(Standard_False);
2043 Standard_Boolean Geometry(Standard_False);
2044 if(theNb == 4)
dde68833 2045 Orientation = Draw::Atoi(theArg[3]) != 0;
7fd59977 2046 if(theNb == 5)
dde68833 2047 XSelection = Draw::Atoi(theArg[4]) != 0;
7fd59977 2048 if (theNb == 6)
dde68833 2049 Geometry = Draw::Atoi(theArg[5]) != 0;
7fd59977 2050 Handle(TNaming_NamedShape) aNS = DNaming::GetObjectValue( aCntObj);
2051
2052 if(!aNS.IsNull() && !aNS->IsEmpty()) {
2053 const TopoDS_Shape& aRootShape = aNS->Get();
7fd59977 2054 TopTools_MapOfOrientedShape aMap0;
2055 MapOfOrientedShapes(aRootShape, aMap0);
2056 TopTools_ListOfShape aList, aFailedList;
2057 CollectMultShapes(aRootShape, aList);
2058
2059 Standard_Boolean isFirst(Standard_True);
2060 Handle(TDataStd_UAttribute) FirstAuxObj;
2061 TopTools_ListIteratorOfListOfShape it(aList);
2062 for(; it.More(); it.Next()) {
2063 const TopoDS_Shape& aCurShape = it.Value();
2064 if(aCurShape.IsNull()) continue;
2065 if(aCurShape.ShapeType() == TopAbs_EDGE) {
2066 if (BRep_Tool::Degenerated(TopoDS::Edge(aCurShape)))
2067 continue;
2068 }//
2069 Handle(TDataStd_UAttribute) auxObj = AddObject (aDoc);
2070 if(isFirst) {
2071 FirstAuxObj = auxObj;
2072 isFirst = Standard_False;
0797d9d3 2073#ifdef OCCT_DEBUG
7fd59977 2074 TCollection_AsciiString entry;
2075 TDF_Tool::Entry(FirstAuxObj->Label(), entry);
2076 cout << "First Selection function at " << entry <<endl;
2077#endif
2078 }
2079 Standard_Boolean isSelected (Standard_False);
2080 try {
2081 OCC_CATCH_SIGNALS
2082 {
2083 if(!XSelection)
2084 isSelected = MakeSelection(auxObj, aCurShape, aCntObj, Geometry, Orientation);
2085 else
2086 isSelected = MakeXSelection(auxObj, aCurShape, aCntObj, Geometry, Orientation);
2087 }
2088 }
2089 catch (Standard_Failure) {
2090 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
2091 cout << "%%%INFO:Error: ::TestSingleSelection failed :";
2092 if (!aFailure.IsNull())
2093 cout << aFailure->GetMessageString() << endl;
2094 else
2095 cout << "%%%INFO:Error: ::TestSingleSelection : Standard_Failure with null caught failure"<< endl;
2096 }
2097 catch(...) {
2098 cout << "%%%INFO:Error: ::TestSingleSelection selection failed : unknown exception type";
2099 }
2100 TCollection_AsciiString entry;
2101 TDF_Tool::Entry(auxObj->Label(), entry);
2102 TCollection_ExtendedString aResult("");
2103 if(isSelected) {
2104 const Handle(TNaming_NamedShape)& aSelNS = DNaming::GetObjectValue(auxObj);
2105 if(!aSelNS.IsNull() && !aSelNS->IsEmpty()) {
2106 const TopoDS_Shape& aSelectedShape = aSelNS->Get();
2107 aResult += compareShapes(aSelectedShape, aMap0);
2108 TDF_ChildIDIterator itn(auxObj->Label(),TNaming_Naming::GetID(), Standard_True);
2109 for(;itn.More();itn.Next()) {
2110 Handle(TNaming_Naming) aNaming = Handle(TNaming_Naming)::DownCast(itn.Value());
2111 if(!aNaming.IsNull()) {
2112 const TNaming_Name& aName = aNaming->GetName();
2113 if(aName.Type() == TNaming_UNKNOWN) {
2114 aResult += " Selection at label = ";
2115 aResult += entry;
2116 aResult += " has UNKNOWN name type, shape type = ";
2117 aResult += ShapeEnumToString(aCurShape.ShapeType());
2118 }
2119
2120 }
2121 }
2122 }
2123 } else {
2124 aResult += " Selection at label = ";
2125 aResult += entry;
2126 aResult += " failed, shape type = ";
2127 aResult += ShapeEnumToString(aCurShape.ShapeType());
2128 aFailedList.Append(aCurShape);
2129 }
2130 if(aResult.Length())
2131 cout << "Failed units: " << aResult << endl;
2132 }
2133
2134 if(aFailedList.Extent()) {
2135 TopTools_ListIteratorOfListOfShape it1(aFailedList);
2136 for(; it1.More(); it1.Next()) {
2137 const TDF_Label& aLabel = TDF_TagSource::NewChild(aDoc->Main());
2138
2139 TNaming_Builder B(aLabel);
2140 B.Generated(it1.Value());
2141 }
2142 }
2143 if(!FirstAuxObj.IsNull())
2144 DDF::ReturnLabel(theDI, FirstAuxObj->Label());
2145 return 0;
2146 }
2147 }
6e6cd5d9 2148
7fd59977 2149 cout << "DNaming_TestMultiple : Error" << endl;
2150 return 1;
2151}
2152
2153//=======================================================================
2154//function : ModelingCommands
2155//purpose :
2156//=======================================================================
2157
2158void DNaming::ModelingCommands (Draw_Interpretor& theCommands)
2159{
2160
2161 static Standard_Boolean done = Standard_False;
2162 if (done) return;
2163 done = Standard_True;
2164 const char* g2 = "Naming modeling commands" ;
2165
2166 theCommands.Add ("AddObject",
2167 "AddObject D",
2168 __FILE__, DNaming_AddObject, g2);
2169
2170 theCommands.Add ("AddFunction",
f486f64d 2171 "AddFunction D ObjEntry FunName[Box|Sph|Cyl|Cut|Fuse|Prism|Revol|PMove|Fillet|Attach|XAttach]",
7fd59977 2172 __FILE__, DNaming_AddFunction, g2);
2173
2174 theCommands.Add ("AddBox", "AddBox Doc dx dy dz", __FILE__, DNaming_AddBox, g2);
2175
2176 theCommands.Add ("BoxDX", "BoxDX Doc BoxLabel NewDX", __FILE__, DNaming_BoxDX, g2);
2177
2178 theCommands.Add ("BoxDY", "BoxDY Doc BoxLabel NewDY", __FILE__, DNaming_BoxDY, g2);
2179
2180 theCommands.Add ("BoxDZ", "BoxDZ Doc BoxLabel NewDZ", __FILE__, DNaming_BoxDZ, g2);
2181
2182 theCommands.Add ("ComputeFun", "ComputeFun Doc FunLabel", __FILE__, DNaming_ComputeFun, g2);
2183
2184 theCommands.Add ("InitLogBook", "InitLogBook Doc", __FILE__, DNaming_InitLogBook, g2);
2185
2186 theCommands.Add ("AddDriver",
2187 "AddDriver Doc Name [Box|Sph|Cyl|Cut|Fuse|Prism|Revol|PTxyz|PTALine|PRLine|PMirr|Fillet|Attach|XAttach]",
2188 __FILE__, DNaming_AddDriver, g2);
2189
2190 theCommands.Add ("AttachShape",
2191 "AttachShape Doc Shape Context [Container [KeepOrientation [Geometry]]]",
2192 __FILE__, DNaming_AttachShape, g2);
2193
2194 theCommands.Add ("XAttachShape",
2195 "XAttachShape Doc Shape Context [KeepOrientation [Geometry]]",
2196 __FILE__, DNaming_XAttachShape, g2);
2197
2198 theCommands.Add ("AddCyl", "AddCyl Doc Radius Height Axis", __FILE__, DNaming_AddCylinder, g2);
2199
2200 theCommands.Add ("CylRad", "CylRad Doc CylLabel NewRad", __FILE__, DNaming_CylRad, g2);
2201
2202
2203 theCommands.Add ("AddFuse", "AddFuse Doc Object Tool", __FILE__, DNaming_AddFuse, g2);
2204
2205 theCommands.Add ("AddCut", "AddCut Doc Object Tool", __FILE__, DNaming_AddCut, g2);
2206
2207 theCommands.Add ("AddCommon", "AddCommon Doc Object Tool", __FILE__, DNaming_AddCommon, g2);
2208
372ceec4 2209 theCommands.Add ("AddSection", "AddSection Doc Object Tool", __FILE__, DNaming_AddSection, g2);
2210
7fd59977 2211 theCommands.Add ("AddFillet",
2212 "AddFillet Doc Object Radius Path [SurfaceType(0-Rational;1-QuasiAngular;2-Polynomial)]",
2213 __FILE__, DNaming_AddFillet, g2);
2214
2215 theCommands.Add ("PTranslateDXYZ", "PTranslateDXYZ Doc ShapeEntry dx dy dz",
2216 __FILE__, DNaming_PTranslateDXYZ, g2);
2217
2218 theCommands.Add ("PTranslateAlongLine", "PTranslateAlongLine Doc ShapeEntry Line off",
2219 __FILE__, DNaming_PTranslateLine, g2);
2220
2221 theCommands.Add ("PRotateRoundLine", "PRotateRoundLine Doc ShapeEntry Line Angle",
2222 __FILE__, DNaming_PRotateLine, g2);
2223
2224 theCommands.Add ("PMirror", "PMirror Doc ShapeEntry PlaneObj",
2225 __FILE__, DNaming_PMirrorObject, g2);
2226
2227
2228 theCommands.Add ("AddPrism", "AddPrism Doc BasisLabel Height Reverse(0/1) ",
2229 __FILE__, DNaming_AddPrism, g2);
2230
2231 theCommands.Add ("PrismHeight", "PrismHeight Doc PrismLabel NewHeight",
2232 __FILE__, DNaming_PrismHeight, g2);
2233
2234 theCommands.Add ("AddRevol", "AddRevol Doc BasisLabel AxisLabel [Angle [Reverse(0/1)]] ",
2235 __FILE__, DNaming_AddRevol, g2);
2236
2237 theCommands.Add ("RevolutionAngle", "RevolutionAngle Doc RevolutionLabel NewAngle",
2238 __FILE__, DNaming_RevolutionAngle, g2);
2239
2240 theCommands.Add ("AddSphere", "AddSphere Doc CenterLabel Radius ",
2241 __FILE__, DNaming_AddSphere, g2);
2242
2243 theCommands.Add ("SphereRadius", "SphereRadius Doc SphereLabel NewRadius",
2244 __FILE__, DNaming_SphereRadius, g2);
2245
2246 theCommands.Add ("TestSingleSelection",
2247 "TestSingleSelection Doc ObjectLabel [Orientation [Xselection [Geometry]]]",
2248 __FILE__, DNaming_TestSingle, g2);
2249
2250 theCommands.Add ("SolveFlatFrom", "SolveFlatFrom Doc FistAuxObjLabel",
2251 __FILE__, DNaming_SolveFlatFrom, g2);
2252
2253 theCommands.Add ("CheckLogBook", "CheckLogBook Doc", __FILE__, DNaming_CheckLogBook, g2);
2254
2255 theCommands.Add ("TestMultipleSelection",
2256 "TestMultipleSelection Doc ObjectLabel [Orientation [Xselection [Geometry]]]",
2257 __FILE__, DNaming_Multiple, g2);
2258
2259 theCommands.Add ("AddPoint", "AddPoint Doc x y z", __FILE__, DNaming_AddPoint, g2);
2260
2261 theCommands.Add ("AddPointRlt", "AddPointRlt Doc RefPntObj dx dy dz",
2262 __FILE__, DNaming_AddPointRlt, g2);
2263
2264 theCommands.Add ("PntOffset", "PntOffset Doc PntLabel newDX|skip newDY|skip newDZ|skip",
2265 __FILE__, DNaming_PntOffset, g2);
2266
2267 theCommands.Add ("AddLine3D", "AddLine3D Doc CurveType(0|1) Pnt1 Pnt2 [Pnt3 [Pnt4 [...]]]",
2268 __FILE__, DNaming_Line3D, g2);
2269}
2270
2271