summaryrefslogtreecommitdiff
path: root/src/DDataStd/DDataStd_NameCommands.cxx
blob: 70867eddd86b8a1375191a3be0a2aa259f0057ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// File:	DDataStd_NameCommands.cxx
// Created:	Thu Aug 19 12:19:35 1999
// Author:      Sergey RUIN
//		<s-ruin@nnov.matra-dtv.fr>


#include <DDataStd.hxx>
#include <DDF.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_Appli.hxx>
#include <DrawTrSurf.hxx>

#include <DDF.hxx>

#include <TDF_Data.hxx>
#include <TDF_Label.hxx>
#include <TDF_Tool.hxx>
#include <TDF_AttributeSequence.hxx>
#include <TDF_AttributeList.hxx>
#include <TDF_ListIteratorOfAttributeList.hxx>

// ATTRIBUTES

#include <TDataStd.hxx>
#include <TDataStd_Name.hxx>

#include <TCollection_AsciiString.hxx>
#include <TDataStd_ListOfExtendedString.hxx>




//=======================================================================
//function : DDataStd_SetName
//purpose  : SetName (DF, entry, name)
//=======================================================================

static Standard_Integer DDataStd_SetName (Draw_Interpretor& di,
					  Standard_Integer nb, 
					  const char** arg) 
{
//   if (nb == 3) {    
//     Handle(TDF_Data) DF;
//     if (!DDF::GetDF(arg[1],DF)) return 1;
//     TDF_Label L;
//     DDF::FindLabel(DF, arg[2], L);
//     if(L.IsNull()) cout << "Label is not found"   << endl;
//     Handle(TDataStd_Name) N = TDataStd_Name::Set(L);
//     return 0;
//  }
  // else if (nb == 4) {  
  if (nb == 4) {     
    Handle(TDF_Data) DF;
    if (!DDF::GetDF(arg[1],DF)) return 1;
    TDF_Label L;
    DDF::FindLabel(DF, arg[2], L);
    if(L.IsNull()) di << "Label is not found"   << "\n";
    Handle(TDataStd_Name) N;
    //if( !L.FindAttribute(TDataStd_Name::GetID(), N) ) N = TDataStd_Name::Set(L);
    //N->Set(arg[3]); 
    N = TDataStd_Name::Set(L,arg[3]); 
    return 0;
  }
  di << "DDataStd_SetName : Error" << "\n";
  return 1;
}


//=======================================================================
//function : DDataStd_GetName
//purpose  : GetName (DF, entry)
//=======================================================================

static Standard_Integer DDataStd_GetName (Draw_Interpretor& di,
					  Standard_Integer nb, 
					  const char** arg) 
{   
  if (nb == 3) {    
    Handle(TDF_Data) DF;
    if (!DDF::GetDF(arg[1],DF)) return 1; 
    TDF_Label L;
    DDF::FindLabel(DF, arg[2], L);
    if(L.IsNull()) di << "Label is not found"   << "\n";
    Handle(TDataStd_Name) N;
    if( !L.FindAttribute(TDataStd_Name::GetID(), N) ) return 1;
    TCollection_AsciiString s(N->Get(),'?');
    di << s.ToCString();
    return 0;
  }
  di << "DDataStd_SetName : Error" << "\n";
  return 1;
}



//=======================================================================
//function : LabelName (DF, [entry], path)
//=======================================================================
// static Standard_Integer DDataStd_LabelName (Draw_Interpretor& di,
// 					    Standard_Integer nb, 
// 					    const char** arg) 
// {
//   Handle(TDF_Data) DF;
//   TDF_Label label;
//   Handle(TDataStd_Name) result;
//   TDataStd_ListOfExtendedString myList;
//   Standard_Integer i = 2;
//   Standard_Boolean Found = Standard_False;

//   if (!DDF::GetDF(arg[1],DF))  return 1;
//   if( nb == 4 ) {
//     if( !DDF::FindLabel(DF, arg[2], label) ) {   
//       cout << "No label for entry"  << endl;
//       return 1;   
//     }
//     i = 3;
//   }
  
//   if( !TDataStd_Name::MakePath(arg[i], myList) ) return 1;

//   if( nb == 4 ) {
//     Handle(TDataStd_Name) current;
//     if (TDataStd_Name::Find(label,current)) {
//       if (current->Find(myList ,result)) Found = Standard_True;
//     }
//   }
//   else {
//     if(TDataStd_Name::Find(DF, myList ,result)) Found = Standard_True;
//   }
  
//   if(Found) {
//     DDF::ReturnLabel(di,  result->Label());
//     return 0;
//   }

//   cout << "Label wasn't found"  << endl;
//   return 1;
// }


// //=======================================================================
// //function : FullPath (DF, entry)
// //=======================================================================
// static Standard_Integer DDataStd_FullPath (Draw_Interpretor& di,
// 					   Standard_Integer nb, 
// 					   const char** arg) 
// {
//   Handle(TDF_Data) DF;
//   if (!DDF::GetDF(arg[1],DF))  return 1; 
//   TDF_Label label;
//   if( !DDF::FindLabel(DF, arg[2], label) ) {   
//     cout << "No label for entry"  << endl;
//     return 1;   
//   } 
//   Handle(TDataStd_Name) current;
//   if (TDataStd_Name::Find(label,current)) {
//     TDF_AttributeList myList;
//     if (!current->FullPath(myList)) return 1;
//     TDF_ListIteratorOfAttributeList itr(myList);
//     TCollection_AsciiString str;
//     for(;itr.More(); itr.Next() ) { 
//       str+=Handle(TDataStd_Name)::DownCast(itr.Value())->Get();
//       str+=":";
//     }
//     str.Remove(str.Length());       //remove last ":"
//     di << str.ToCString(); 
//   }  
// #ifndef DEB
//   return 0 ;
// #endif
// }
//=======================================================================
//function : SetCommands
//purpose  : 
//=======================================================================

void DDataStd::NameCommands (Draw_Interpretor& theCommands)
{  

  static Standard_Boolean done = Standard_False;
  if (done) return;
  done = Standard_True;

  const char* g = "DDataStd : Name attribute commands";

  theCommands.Add ("SetName", 
                   "SetName (DF, entry, name)",
		   __FILE__, DDataStd_SetName, g);   

  theCommands.Add ("GetName", 
                   "GetNmae (DF, entry)",
                    __FILE__, DDataStd_GetName, g);  

//   theCommands.Add ("LabelName", 
//                    "GetLabel (DF, [entry], path(name1:name2:...nameN)",
// 		   __FILE__, DDataStd_LabelName, g);

//   theCommands.Add ("FullPath", 
//                    "FullPath (DF, entry)",
// 		   __FILE__, DDataStd_FullPath, g);

}