0029296: Data Exchange - implement import of mesh data from files in OBJ format
[occt.git] / src / DDataStd / DDataStd_NameCommands.cxx
CommitLineData
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
48static 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
81static 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
e3249d8e 108 di << N->Get();
7fd59977 109 return 0;
110 }
586db386 111 di << "DDataStd_SetName : Error\n";
7fd59977 112 return 1;
113}
114
115
116
fa53efef 117
7fd59977 118//=======================================================================
119//function : SetCommands
120//purpose :
121//=======================================================================
122
123void DDataStd::NameCommands (Draw_Interpretor& theCommands)
124{
125
126 static Standard_Boolean done = Standard_False;
127 if (done) return;
128 done = Standard_True;
129
130 const char* g = "DDataStd : Name attribute commands";
131
132 theCommands.Add ("SetName",
fa53efef 133 "SetName (DF, entry, name [,guid])",
7fd59977 134 __FILE__, DDataStd_SetName, g);
135
136 theCommands.Add ("GetName",
fa53efef 137 "GetNmae (DF, entry [,guid])",
7fd59977 138 __FILE__, DDataStd_GetName, g);
139
7fd59977 140
141}
142