1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "GEOM_Object.hxx"
25 #include <TDataStd_Integer.hxx>
26 #include <TDataStd_Real.hxx>
27 #include <TDataStd_RealArray.hxx>
29 #include "utilities.h"
31 // #define FUNCTION_LABEL(theNb) (_label.FindChild(1).FindChild((theNb)))
32 // #define TYPE_LABEL 2 -- Labels used by GEOM_BaseObject
33 // #define FREE_LABEL 3
34 // #define TIC_LABEL 4
36 #define AUTO_COLOR_LABEL 6
37 #define MARKER_LABEL 7
39 #define MARKER_LABEL_TYPE 1
40 #define MARKER_LABEL_SIZE 2
41 #define MARKER_LABEL_ID 3
43 //=============================================================================
47 //=============================================================================
49 Handle(GEOM_Object) GEOM_Object::GetObject(const TDF_Label& theLabel)
51 Handle(GEOM_BaseObject) base = GEOM_BaseObject::GetObject(theLabel);
52 return Handle(GEOM_Object)::DownCast( base );
55 //=============================================================================
59 //=============================================================================
61 Handle(GEOM_Object) GEOM_Object::GetReferencedObject(const TDF_Label& theLabel)
63 Handle(GEOM_BaseObject) base = GEOM_BaseObject::GetReferencedObject(theLabel);
64 return Handle(GEOM_Object)::DownCast( base );
67 //=============================================================================
69 * Constructor: private
71 //=============================================================================
73 GEOM_Object::GEOM_Object(TDF_Label& theEntry)
74 : GEOM_BaseObject(theEntry)
78 //=============================================================================
82 //=============================================================================
84 GEOM_Object::GEOM_Object(TDF_Label& theEntry, int theType)
85 : GEOM_BaseObject( theEntry, theType )
89 //=============================================================================
93 //=============================================================================
94 GEOM_Object::~GEOM_Object()
96 //MESSAGE("GEOM_Object::~GEOM_Object()");
99 //=============================================================================
103 //=============================================================================
104 TopoDS_Shape GEOM_Object::GetValue()
108 Handle(GEOM_Function) aFunction = GetLastFunction();
110 if (!aFunction.IsNull())
111 aShape = aFunction->GetValue();
116 //=============================================================================
120 //=============================================================================
121 void GEOM_Object::SetColor(const GEOM_Object::Color& theColor)
123 Handle(TDataStd_RealArray) anArray = new TDataStd_RealArray();
124 anArray->Init( 1, 3 );
125 anArray->SetValue( 1, theColor.R );
126 anArray->SetValue( 2, theColor.G );
127 anArray->SetValue( 3, theColor.B );
129 Handle(TDataStd_RealArray) anAttr =
130 TDataStd_RealArray::Set(_label.FindChild(COLOR_LABEL), anArray->Lower(), anArray->Upper());
131 anAttr->ChangeArray(anArray->Array());
134 //=============================================================================
138 //=============================================================================
139 GEOM_Object::Color GEOM_Object::GetColor()
141 Handle(TDataStd_RealArray) anArray;
142 bool isFound = _label.FindChild(COLOR_LABEL).FindAttribute(TDataStd_RealArray::GetID(), anArray);
144 GEOM_Object::Color aColor;
145 aColor.R = isFound ? anArray->Value( 1 ) : -1;
146 aColor.G = isFound ? anArray->Value( 2 ) : -1;
147 aColor.B = isFound ? anArray->Value( 3 ) : -1;
152 //=============================================================================
156 //=============================================================================
157 void GEOM_Object::SetAutoColor(bool theAutoColor)
159 TDataStd_Integer::Set(_label.FindChild(AUTO_COLOR_LABEL), (int)theAutoColor);
162 //=============================================================================
166 //=============================================================================
167 bool GEOM_Object::GetAutoColor()
169 Handle(TDataStd_Integer) anAutoColor;
170 if(!_label.FindChild(AUTO_COLOR_LABEL).FindAttribute(TDataStd_Integer::GetID(), anAutoColor)) return false;
172 return bool(anAutoColor->Get());
175 //=============================================================================
179 //=============================================================================
180 void GEOM_Object::SetMarkerStd(const Aspect_TypeOfMarker theType, double theSize)
182 TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL);
183 TDataStd_Integer::Set(aMarkerLabel.FindChild(MARKER_LABEL_TYPE), (int)theType);
184 TDataStd_Real::Set(aMarkerLabel.FindChild(MARKER_LABEL_SIZE), theSize);
187 //=============================================================================
191 //=============================================================================
192 void GEOM_Object::SetMarkerTexture(int theTextureId)
194 TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL);
195 TDataStd_Integer::Set(aMarkerLabel.FindChild(MARKER_LABEL_TYPE), (int)Aspect_TOM_USERDEFINED);
196 TDataStd_Integer::Set(aMarkerLabel.FindChild(MARKER_LABEL_ID), theTextureId);
199 //=============================================================================
203 //=============================================================================
204 Aspect_TypeOfMarker GEOM_Object::GetMarkerType()
206 Standard_Integer aType = -1;
207 TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL, Standard_False);
208 if(!aMarkerLabel.IsNull()) {
209 TDF_Label aTypeLabel = aMarkerLabel.FindChild(MARKER_LABEL_TYPE, Standard_False);
210 Handle(TDataStd_Integer) aTypeAttr;
211 if (!aTypeLabel.IsNull() && aTypeLabel.FindAttribute(TDataStd_Integer::GetID(), aTypeAttr))
212 aType = aTypeAttr->Get();
214 return (Aspect_TypeOfMarker)aType;
217 //=============================================================================
221 //=============================================================================
222 double GEOM_Object::GetMarkerSize()
224 Standard_Real aSize = 0.;
225 TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL, Standard_False);
226 if(!aMarkerLabel.IsNull()) {
227 TDF_Label aSizeLabel = aMarkerLabel.FindChild(MARKER_LABEL_SIZE, Standard_False);
228 Handle(TDataStd_Real) aSizeAttr;
229 if (!aSizeLabel.IsNull() && aSizeLabel.FindAttribute(TDataStd_Real::GetID(), aSizeAttr))
230 aSize = aSizeAttr->Get();
235 //=============================================================================
239 //=============================================================================
240 int GEOM_Object::GetMarkerTexture()
242 Standard_Integer anId = 0;
243 if ( GetMarkerType() == Aspect_TOM_USERDEFINED) {
244 TDF_Label aMarkerLabel = _label.FindChild(MARKER_LABEL, Standard_False);
245 if(!aMarkerLabel.IsNull()) {
246 TDF_Label aTypeLabel = aMarkerLabel.FindChild(MARKER_LABEL_ID, Standard_False);
247 Handle(TDataStd_Integer) anIdAttr;
248 if (!aTypeLabel.IsNull() && aTypeLabel.FindAttribute(TDataStd_Integer::GetID(), anIdAttr))
249 anId = anIdAttr->Get();
255 //=============================================================================
259 //=============================================================================
260 void GEOM_Object::UnsetMarker()
262 SetMarkerStd((Aspect_TypeOfMarker)-1, 0.);
265 //=============================================================================
269 //=============================================================================
270 bool GEOM_Object::IsMainShape()
272 Handle(GEOM_Function) aFunction = GetFunction(1);
273 if(aFunction.IsNull() || aFunction->GetDriverGUID() != GetSubShapeID())
274 return true; // mkr : IPAL9921
278 //================================================================================
280 * \brief Returns GetLastFunction() of given objects
282 //================================================================================
284 Handle(TColStd_HSequenceOfTransient)
285 GEOM_Object::GetLastFunctions( const std::list< Handle(GEOM_Object) >& theObjects )
287 Handle(TColStd_HSequenceOfTransient) funs = new TColStd_HSequenceOfTransient;
288 std::list<Handle(GEOM_Object)>::const_iterator it = theObjects.begin();
289 for (; it != theObjects.end(); it++)
291 Handle(GEOM_Function) fun = (*it)->GetLastFunction();
293 return Handle(TColStd_HSequenceOfTransient)();
299 IMPLEMENT_STANDARD_RTTIEXT(GEOM_Object, GEOM_BaseObject )