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