b311480e |
1 | // Created on: 1999-08-19 |
2 | // Created by: Sergey RUIN |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
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 |
fa53efef |
45 | //purpose : SetName (DF, entry, name [,guid]) |
7fd59977 |
46 | //======================================================================= |
47 | |
48 | static Standard_Integer DDataStd_SetName (Draw_Interpretor& di, |
49 | Standard_Integer nb, |
50 | const char** arg) |
51 | { |
fa53efef |
52 | |
53 | if (nb == 4 || nb == 5) { |
7fd59977 |
54 | Handle(TDF_Data) DF; |
55 | if (!DDF::GetDF(arg[1],DF)) return 1; |
56 | TDF_Label L; |
fa53efef |
57 | DDF::AddLabel(DF, arg[2], L); |
7fd59977 |
58 | if(L.IsNull()) di << "Label is not found" << "\n"; |
fa53efef |
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 | } |
7fd59977 |
69 | return 0; |
70 | } |
586db386 |
71 | di << "DDataStd_SetName : Error\n"; |
7fd59977 |
72 | return 1; |
73 | } |
74 | |
fa53efef |
75 | //#define DEB_DDataStd |
7fd59977 |
76 | //======================================================================= |
77 | //function : DDataStd_GetName |
fa53efef |
78 | //purpose : GetName (DF, entry [,guid]) |
7fd59977 |
79 | //======================================================================= |
80 | |
81 | static Standard_Integer DDataStd_GetName (Draw_Interpretor& di, |
82 | Standard_Integer nb, |
83 | const char** arg) |
84 | { |
fa53efef |
85 | if (nb == 3 || nb == 4) { |
7fd59977 |
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"; |
fa53efef |
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 |
7fd59977 |
108 | TCollection_AsciiString s(N->Get(),'?'); |
109 | di << s.ToCString(); |
110 | return 0; |
111 | } |
586db386 |
112 | di << "DDataStd_SetName : Error\n"; |
7fd59977 |
113 | return 1; |
114 | } |
115 | |
116 | |
117 | |
fa53efef |
118 | |
7fd59977 |
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", |
fa53efef |
134 | "SetName (DF, entry, name [,guid])", |
7fd59977 |
135 | __FILE__, DDataStd_SetName, g); |
136 | |
137 | theCommands.Add ("GetName", |
fa53efef |
138 | "GetNmae (DF, entry [,guid])", |
7fd59977 |
139 | __FILE__, DDataStd_GetName, g); |
140 | |
7fd59977 |
141 | |
142 | } |
143 | |