85096844c09d3b042c910be291a6e34bc9523cae
[occt.git] / src / DDataStd / DDataStd_NameCommands.cxx
1 // Created on: 1999-08-19
2 // Created by: Sergey RUIN
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <DDataStd.hxx>
18 #include <DDF.hxx>
19 #include <Draw_Interpretor.hxx>
20 #include <Draw_Appli.hxx>
21 #include <DrawTrSurf.hxx>
22
23 #include <DDF.hxx>
24
25 #include <TDF_Data.hxx>
26 #include <TDF_Label.hxx>
27 #include <TDF_Tool.hxx>
28 #include <TDF_AttributeSequence.hxx>
29 #include <TDF_AttributeList.hxx>
30 #include <TDF_ListIteratorOfAttributeList.hxx>
31
32 // ATTRIBUTES
33
34 #include <TDataStd.hxx>
35 #include <TDataStd_Name.hxx>
36
37 #include <TCollection_AsciiString.hxx>
38 #include <TDataStd_ListOfExtendedString.hxx>
39
40
41
42
43 //=======================================================================
44 //function : DDataStd_SetName
45 //purpose  : SetName (DF, entry, name [,guid])
46 //=======================================================================
47
48 static Standard_Integer DDataStd_SetName (Draw_Interpretor& di,
49                                           Standard_Integer nb, 
50                                           const char** arg) 
51 {
52
53   if (nb == 4 || nb == 5) {     
54     Handle(TDF_Data) DF;
55     if (!DDF::GetDF(arg[1],DF)) return 1;
56     TDF_Label L;
57     DDF::AddLabel(DF, arg[2], L);
58     if(L.IsNull()) di << "Label is not found"   << "\n";
59         if(nb == 4) 
60       TDataStd_Name::Set(L,TCollection_ExtendedString(arg[3],Standard_True)); 
61         else {  
62           if (!Standard_GUID::CheckGUIDFormat(arg[4])) {
63         di<<"DDataStd_SetReal: The format of GUID is invalid\n";
64         return 1;
65           }
66           Standard_GUID guid(arg[4]);
67           TDataStd_Name::Set(L, guid, TCollection_ExtendedString(arg[3],Standard_True)); 
68      }
69     return 0;
70   }
71   di << "DDataStd_SetName : Error\n";
72   return 1;
73 }
74
75 //#define DEB_DDataStd
76 //=======================================================================
77 //function : DDataStd_GetName
78 //purpose  : GetName (DF, entry [,guid])
79 //=======================================================================
80
81 static Standard_Integer DDataStd_GetName (Draw_Interpretor& di,
82                                           Standard_Integer nb, 
83                                           const char** arg) 
84 {   
85   if (nb == 3 || nb == 4) {    
86     Handle(TDF_Data) DF;
87     if (!DDF::GetDF(arg[1],DF)) return 1; 
88     TDF_Label L;
89     DDF::FindLabel(DF, arg[2], L);
90     if(L.IsNull()) di << "Label is not found"   << "\n";
91         Standard_GUID aGuid (TDataStd_Name::GetID());
92         if(nb == 4) {
93       if (!Standard_GUID::CheckGUIDFormat(arg[3])) {
94         di<<"DDataStd_GetAsciiString: The format of GUID is invalid\n";
95         return 1;
96           }
97           aGuid = Standard_GUID(arg[3]);
98         }
99         Handle(TDataStd_Name) N;          
100         if( !L.FindAttribute(aGuid, N) ) {
101       cout << "Name attribute is not found or not set"  << endl;
102           return 1;
103         }
104 #ifdef DEB_DDataStd
105         if(!N.IsNull()) 
106       cout << "String = " << TCollection_AsciiString(N->Get(), '?').ToCString()  << endl;
107 #endif
108     TCollection_AsciiString s(N->Get(),'?');
109     di << s.ToCString();
110     return 0;
111   }
112   di << "DDataStd_SetName : Error\n";
113   return 1;
114 }
115
116
117
118
119 //=======================================================================
120 //function : SetCommands
121 //purpose  : 
122 //=======================================================================
123
124 void DDataStd::NameCommands (Draw_Interpretor& theCommands)
125 {  
126
127   static Standard_Boolean done = Standard_False;
128   if (done) return;
129   done = Standard_True;
130
131   const char* g = "DDataStd : Name attribute commands";
132
133   theCommands.Add ("SetName", 
134                    "SetName (DF, entry, name [,guid])",
135                    __FILE__, DDataStd_SetName, g);   
136
137   theCommands.Add ("GetName", 
138                    "GetNmae (DF, entry [,guid])",
139                     __FILE__, DDataStd_GetName, g);  
140
141
142 }
143