1 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOMEDS_GenericAttribute_i.cxx
8 // Author : Mikhail PONIKAROV
12 #include <TDataStd_TreeNode.hxx>
13 #include <TDataStd_UAttribute.hxx>
15 #include "SALOMEDS_AttributeDrawable_i.hxx"
16 #include "SALOMEDS_AttributeSelectable_i.hxx"
17 #include "SALOMEDS_AttributeOpened_i.hxx"
18 #include "SALOMEDS_AttributeFlags_i.hxx"
19 #include "SALOMEDS_AttributeGraphic_i.hxx"
20 #include "SALOMEDS_AttributeTextColor_i.hxx"
21 #include "SALOMEDS_AttributeTextHighlightColor_i.hxx"
22 #include "SALOMEDS_AttributePixMap_i.hxx"
23 #include "SALOMEDS_AttributeExpandable_i.hxx"
24 #include "SALOMEDS_AttributeLocalID_i.hxx"
25 #include "SALOMEDS_AttributeTarget_i.hxx"
26 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
27 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
28 #include "SALOMEDS_AttributeTableOfString_i.hxx"
29 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
30 #include "SALOMEDS_AttributePythonObject_i.hxx"
31 #include "SALOMEDS_AttributeTreeNode_i.hxx"
32 #include "SALOMEDS_AttributeUserID_i.hxx"
33 #include "SALOMEDS_AttributeExternalFileDef_i.hxx"
34 #include "SALOMEDS_AttributeFileType_i.hxx"
35 #include "SALOMEDS_StudyBuilder_i.hxx"
37 #include "SALOMEDS_SequenceOfRealAttribute.hxx"
38 #include "SALOMEDS_SequenceOfIntegerAttribute.hxx"
39 #include "SALOMEDS_IORAttribute.hxx"
40 #include "SALOMEDS_PersRefAttribute.hxx"
41 #include "SALOMEDS_DrawableAttribute.hxx"
42 #include "SALOMEDS_SelectableAttribute.hxx"
43 #include "SALOMEDS_ExpandableAttribute.hxx"
44 #include "SALOMEDS_OpenedAttribute.hxx"
45 #include "SALOMEDS_FlagsAttribute.hxx"
46 #include "SALOMEDS_GraphicAttribute.hxx"
47 #include "SALOMEDS_TextColorAttribute.hxx"
48 #include "SALOMEDS_TextHighlightColorAttribute.hxx"
49 #include "SALOMEDS_PixMapAttribute.hxx"
50 #include "SALOMEDS_LocalIDAttribute.hxx"
51 #include "SALOMEDS_PythonObjectAttribute.hxx"
52 #include "SALOMEDS_TargetAttribute.hxx"
53 #include "SALOMEDS_StudyPropertiesAttribute.hxx"
54 #include "SALOMEDS_TableOfIntegerAttribute.hxx"
55 #include "SALOMEDS_TableOfRealAttribute.hxx"
56 #include "SALOMEDS_TableOfStringAttribute.hxx"
57 #include "SALOMEDS_ExternalFileDef.hxx"
58 #include "SALOMEDS_FileType.hxx"
59 #include "Utils_ExceptHandlers.hxx"
63 #define RegisteredAttributes 28
65 UNEXPECT_CATCH(GALockProtection, SALOMEDS::GenericAttribute::LockProtection);
67 const char AttributesTypeNames[RegisteredAttributes][30] = {
68 "AttributeReal", "AttributeInteger",
69 "AttributeSequenceOfReal", "AttributeSequenceOfInteger",
70 "AttributeName", "AttributeComment",
71 "AttributeIOR", "AttributePersistentRef",
72 "AttributeDrawable", "AttributeSelectable",
73 "AttributeExpandable", "AttributeOpened",
74 "AttributeTextColor", "AttributeTextHighlightColor", "AttributePixMap",
75 "AttributeTreeNode", "AttributeLocalID",
77 "AttributeTableOfInteger", "AttributeTableOfReal", "AttributeTableOfString",
78 "AttributeStudyProperties",
79 "AttributePythonObject",
81 "AttributeExternalFileDef", "AttributeFileType",
86 const Standard_GUID AttributesGUIDs[RegisteredAttributes] = {
87 TDataStd_Real::GetID(), TDataStd_Integer::GetID(),
88 SALOMEDS_SequenceOfRealAttribute::GetID(), SALOMEDS_SequenceOfIntegerAttribute::GetID(),
89 TDataStd_Name::GetID(), TDataStd_Comment::GetID(),
90 SALOMEDS_IORAttribute::GetID(), SALOMEDS_PersRefAttribute::GetID(),
91 SALOMEDS_DrawableAttribute::GetID(), SALOMEDS_SelectableAttribute::GetID(),
92 SALOMEDS_ExpandableAttribute::GetID(), SALOMEDS_OpenedAttribute::GetID(),
93 SALOMEDS_TextColorAttribute::GetID(), SALOMEDS_TextHighlightColorAttribute::GetID(), SALOMEDS_PixMapAttribute::GetID(),
94 TDataStd_TreeNode::GetDefaultTreeID(), SALOMEDS_LocalIDAttribute::GetID(),
95 SALOMEDS_TargetAttribute::GetID(),
96 SALOMEDS_TableOfIntegerAttribute::GetID(), SALOMEDS_TableOfRealAttribute::GetID(), SALOMEDS_TableOfStringAttribute::GetID(),
97 SALOMEDS_StudyPropertiesAttribute::GetID(),
98 SALOMEDS_PythonObjectAttribute::GetID(),
99 Standard_GUID("FFFFFFFF-D9CD-11d6-945D-1050DA506788"),
100 SALOMEDS_ExternalFileDef::GetID(), SALOMEDS_FileType::GetID(),
101 SALOMEDS_FlagsAttribute::GetID(),
102 SALOMEDS_GraphicAttribute::GetID()
105 void SALOMEDS_GenericAttribute_i::CheckLocked() throw (SALOMEDS::GenericAttribute::LockProtection) {
106 Unexpect aCatch(GALockProtection);
107 if (!_myAttr.IsNull() && _myAttr->IsValid() && !CORBA::is_nil(_myOrb)) {
108 Handle(SALOMEDS_IORAttribute) Att;
109 if (_myAttr->Label().Root().FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){
110 TCollection_AsciiString ch(Att->Get());
111 char* IOR = CORBA::string_dup(ch.ToCString());
112 CORBA::Object_var obj = _myOrb->string_to_object(IOR);
113 SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj);
114 // ASSERT(!CORBA::is_nil(aStudy));
115 if (aStudy->NewBuilder()->HasOpenCommand()) return;
116 if (aStudy->GetProperties()->IsLocked()) {
117 // MESSAGE("Locked document modification !!!");
118 throw SALOMEDS::GenericAttribute::LockProtection();
124 SALOMEDS::SObject_ptr SALOMEDS_GenericAttribute_i::GetSObject() {
125 if (_myAttr.IsNull() || _myAttr->Label().IsNull()) return SALOMEDS::SObject::_nil();
126 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (_myAttr->Label(),_myOrb);
127 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
131 Standard_GUID SALOMEDS_GenericAttribute_i::GetGUID(const char* theType) {
133 for(i = 0; i < RegisteredAttributes; i++) {
134 if (strcmp(AttributesTypeNames[i], theType) == 0) return AttributesGUIDs[i];
137 if (strncmp(theType, "AttributeTreeNodeGUID",21) == 0) {
138 char* aGUIDString = new char[40];
139 sprintf(aGUIDString, &(theType[21]));
140 Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
144 return Standard_GUID();
147 char* SALOMEDS_GenericAttribute_i::Type() {
148 if (_myAttr.IsNull()) return "";
150 for(i = 0; i < RegisteredAttributes; i++) {
151 if (_myAttr->ID() == AttributesGUIDs[i]) {
152 CORBA::String_var aString(AttributesTypeNames[i]);
153 return aString._retn();
156 Handle(TDataStd_TreeNode) aNode = Handle(TDataStd_TreeNode)::DownCast(_myAttr);
157 if (!aNode.IsNull()) {
158 char* aNodeName = new char[60];
160 aNode->ID().ToCString(aGUID);
161 sprintf(aNodeName, "AttributeTreeNodeGUID%s",aGUID);
165 Handle(TDataStd_UAttribute) aUAttr = Handle(TDataStd_UAttribute)::DownCast(_myAttr);
166 if (!aUAttr.IsNull()) {
167 char* aUAttrName = new char[60];
169 aUAttr->ID().ToCString(aGUID);
170 sprintf(aUAttrName, "AttributeUserID_%s",aGUID);
177 SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute(CORBA::ORB_ptr theOrb,
178 const Handle(TDF_Attribute)& theAttr) {
180 __ReturnCORBAAttribute(TDataStd_Real, AttributeReal);
181 __ReturnCORBAAttribute(TDataStd_Integer, AttributeInteger);
182 __ReturnCORBAAttribute(SALOMEDS_SequenceOfRealAttribute, AttributeSequenceOfReal);
183 __ReturnCORBAAttribute(SALOMEDS_SequenceOfIntegerAttribute, AttributeSequenceOfInteger);
184 __ReturnCORBAAttribute(TDataStd_Name, AttributeName);
185 __ReturnCORBAAttribute(TDataStd_Comment, AttributeComment);
186 __ReturnCORBAAttribute(SALOMEDS_IORAttribute, AttributeIOR);
187 __ReturnCORBAAttribute(SALOMEDS_PersRefAttribute, AttributePersistentRef);
188 __ReturnCORBAAttribute(SALOMEDS_DrawableAttribute, AttributeDrawable);
189 __ReturnCORBAAttribute(SALOMEDS_SelectableAttribute, AttributeSelectable);
190 __ReturnCORBAAttribute(SALOMEDS_ExpandableAttribute, AttributeExpandable);
191 __ReturnCORBAAttribute(SALOMEDS_OpenedAttribute, AttributeOpened);
192 __ReturnCORBAAttribute(SALOMEDS_TextColorAttribute, AttributeTextColor);
193 __ReturnCORBAAttribute(SALOMEDS_TextHighlightColorAttribute, AttributeTextHighlightColor);
194 __ReturnCORBAAttribute(SALOMEDS_PixMapAttribute, AttributePixMap);
195 __ReturnCORBAAttribute(SALOMEDS_LocalIDAttribute, AttributeLocalID);
196 __ReturnCORBAAttribute(SALOMEDS_TargetAttribute, AttributeTarget);
197 __ReturnCORBAAttribute(SALOMEDS_TableOfIntegerAttribute, AttributeTableOfInteger);
198 __ReturnCORBAAttribute(SALOMEDS_TableOfRealAttribute, AttributeTableOfReal);
199 __ReturnCORBAAttribute(SALOMEDS_TableOfStringAttribute, AttributeTableOfString);
200 __ReturnCORBAAttribute(SALOMEDS_StudyPropertiesAttribute, AttributeStudyProperties);
201 __ReturnCORBAAttribute(SALOMEDS_PythonObjectAttribute, AttributePythonObject);
202 __ReturnCORBAAttribute(SALOMEDS_ExternalFileDef, AttributeExternalFileDef);
203 __ReturnCORBAAttribute(SALOMEDS_FileType, AttributeFileType);
204 __ReturnCORBAAttribute(SALOMEDS_FlagsAttribute, AttributeFlags);
205 __ReturnCORBAAttribute(SALOMEDS_GraphicAttribute, AttributeGraphic);
207 Handle(TDataStd_TreeNode) aNode = Handle(TDataStd_TreeNode)::DownCast(theAttr);
208 if (!aNode.IsNull()) {
209 SALOMEDS_AttributeTreeNode_i* Attr = new SALOMEDS_AttributeTreeNode_i(aNode, theOrb); \
210 return Attr->AttributeTreeNode::_this(); \
213 Handle(TDataStd_UAttribute) aUAttr = Handle(TDataStd_UAttribute)::DownCast(theAttr);
214 if (!aUAttr.IsNull()) {
215 SALOMEDS_AttributeUserID_i* Attr = new SALOMEDS_AttributeUserID_i(aUAttr, theOrb); \
216 return Attr->AttributeUserID::_this(); \
218 return SALOMEDS::GenericAttribute::_nil();