1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Graphic3d_Group.hxx>
20 #include <Graphic3d_ArrayOfPoints.hxx>
21 #include <Graphic3d_ArrayOfPrimitives.hxx>
22 #include <Graphic3d_AspectFillArea3d.hxx>
23 #include <Graphic3d_AspectLine3d.hxx>
24 #include <Graphic3d_AspectMarker3d.hxx>
25 #include <Graphic3d_AspectText3d.hxx>
26 #include <Graphic3d_CStructure.hxx>
27 #include <Graphic3d_GroupDefinitionError.hxx>
28 #include <Graphic3d_ShaderProgram.hxx>
29 #include <Graphic3d_Structure.hxx>
30 #include "Graphic3d_Structure.pxx"
31 #include <Graphic3d_StructureManager.hxx>
32 #include <Graphic3d_TextureMap.hxx>
33 #include <Graphic3d_TransModeFlags.hxx>
34 #include <Message.hxx>
35 #include <Message_Messenger.hxx>
36 #include <NCollection_String.hxx>
37 #include <Standard_OutOfRange.hxx>
38 #include <Standard_Type.hxx>
39 #include <TCollection_AsciiString.hxx>
40 #include <TCollection_ExtendedString.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Group,Standard_Transient)
44 // =======================================================================
45 // function : Graphic3d_Group
47 // =======================================================================
48 Graphic3d_Group::Graphic3d_Group (const Handle(Graphic3d_Structure)& theStruct)
49 : myStructure (theStruct.operator->()),
51 myContainsFacet (false)
56 // =======================================================================
57 // function : ~Graphic3d_Group
59 // =======================================================================
60 Graphic3d_Group::~Graphic3d_Group()
62 // tell graphics driver to clear internal resources of the group
63 Clear (Standard_False);
66 // =======================================================================
69 // =======================================================================
70 void Graphic3d_Group::Clear (Standard_Boolean theUpdateStructureMgr)
81 myStructure->GroupsWithFacet (-1);
82 myContainsFacet = false;
85 // clear method could be used on Graphic3d_Structure destruction,
86 // and its structure manager could be already destroyed, in that
87 // case we don't need to update it;
88 if (theUpdateStructureMgr)
94 // =======================================================================
97 // =======================================================================
98 void Graphic3d_Group::Remove()
107 myStructure->GroupsWithFacet (-1);
108 myContainsFacet = false;
110 myStructure->Remove (this);
117 // =======================================================================
118 // function : IsDeleted
120 // =======================================================================
121 Standard_Boolean Graphic3d_Group::IsDeleted() const
123 return myStructure == NULL
124 || myStructure->IsDeleted();
127 // =======================================================================
128 // function : IsEmpty
130 // =======================================================================
131 Standard_Boolean Graphic3d_Group::IsEmpty() const
135 return Standard_True;
138 return !myStructure->IsInfinite()
139 && !myBounds.IsValid();
142 // =======================================================================
143 // function : SetMinMaxValues
145 // =======================================================================
146 void Graphic3d_Group::SetMinMaxValues (const Standard_Real theXMin, const Standard_Real theYMin, const Standard_Real theZMin,
147 const Standard_Real theXMax, const Standard_Real theYMax, const Standard_Real theZMax)
149 myBounds = Graphic3d_BndBox4f (Graphic3d_Vec4 (static_cast<Standard_ShortReal> (theXMin),
150 static_cast<Standard_ShortReal> (theYMin),
151 static_cast<Standard_ShortReal> (theZMin),
153 Graphic3d_Vec4 (static_cast<Standard_ShortReal> (theXMax),
154 static_cast<Standard_ShortReal> (theYMax),
155 static_cast<Standard_ShortReal> (theZMax),
159 // =======================================================================
160 // function : Structure
162 // =======================================================================
163 Handle(Graphic3d_Structure) Graphic3d_Group::Structure() const
168 // =======================================================================
169 // function : MinMaxValues
171 // =======================================================================
172 void Graphic3d_Group::MinMaxValues (Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
173 Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax) const
178 theXMin = theYMin = theZMin = ShortRealFirst();
179 theXMax = theYMax = theZMax = ShortRealLast();
181 else if (myBounds.IsValid())
183 const Graphic3d_Vec4& aMinPt = myBounds.CornerMin();
184 const Graphic3d_Vec4& aMaxPt = myBounds.CornerMax();
185 theXMin = Standard_Real (aMinPt.x());
186 theYMin = Standard_Real (aMinPt.y());
187 theZMin = Standard_Real (aMinPt.z());
188 theXMax = Standard_Real (aMaxPt.x());
189 theYMax = Standard_Real (aMaxPt.y());
190 theZMax = Standard_Real (aMaxPt.z());
194 // for consistency with old API
195 theXMin = theYMin = theZMin = ShortRealLast();
196 theXMax = theYMax = theZMax = ShortRealFirst();
200 // =======================================================================
203 // =======================================================================
204 void Graphic3d_Group::Update() const
211 myStructure->StructureManager()->Update();
214 // =======================================================================
215 // function : AddPrimitiveArray
217 // =======================================================================
218 void Graphic3d_Group::AddPrimitiveArray (const Handle(Graphic3d_ArrayOfPrimitives)& thePrim,
219 const Standard_Boolean theToEvalMinMax)
222 || !thePrim->IsValid())
227 AddPrimitiveArray (thePrim->Type(), thePrim->Indices(), thePrim->Attributes(), thePrim->Bounds(), theToEvalMinMax);
230 // =======================================================================
231 // function : AddPrimitiveArray
233 // =======================================================================
234 void Graphic3d_Group::AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
235 const Handle(Graphic3d_IndexBuffer)& ,
236 const Handle(Graphic3d_Buffer)& theAttribs,
237 const Handle(Graphic3d_BoundBuffer)& ,
238 const Standard_Boolean theToEvalMinMax)
241 || theAttribs.IsNull())
247 && theType != Graphic3d_TOPA_POLYLINES
248 && theType != Graphic3d_TOPA_SEGMENTS
249 && theType != Graphic3d_TOPA_POINTS)
251 myStructure->GroupsWithFacet (1);
252 myContainsFacet = true;
255 if (!theToEvalMinMax)
261 const Standard_Integer aNbVerts = theAttribs->NbElements;
262 Standard_Integer anAttribIndex = 0;
263 Standard_Size anAttribStride = 0;
264 const Standard_Byte* aDataPtr = theAttribs->AttributeData (Graphic3d_TOA_POS, anAttribIndex, anAttribStride);
265 if (aDataPtr == NULL)
271 switch (theAttribs->Attribute (anAttribIndex).DataType)
273 case Graphic3d_TOD_VEC2:
275 for (Standard_Integer aVertIter = 0; aVertIter < aNbVerts; ++aVertIter)
277 const Graphic3d_Vec2& aVert = *reinterpret_cast<const Graphic3d_Vec2* >(aDataPtr + anAttribStride * aVertIter);
278 myBounds.Add (Graphic3d_Vec4 (aVert.x(), aVert.y(), 0.0f, 1.0f));
282 case Graphic3d_TOD_VEC3:
283 case Graphic3d_TOD_VEC4:
285 for (Standard_Integer aVertIter = 0; aVertIter < aNbVerts; ++aVertIter)
287 const Graphic3d_Vec3& aVert = *reinterpret_cast<const Graphic3d_Vec3* >(aDataPtr + anAttribStride * aVertIter);
288 myBounds.Add (Graphic3d_Vec4 (aVert.x(), aVert.y(), aVert.z(), 1.0f));
297 // =======================================================================
300 // =======================================================================
301 void Graphic3d_Group::Marker (const Graphic3d_Vertex& thePoint,
302 const Standard_Boolean theToEvalMinMax)
304 Handle(Graphic3d_ArrayOfPoints) aPoints = new Graphic3d_ArrayOfPoints (1);
305 aPoints->AddVertex (thePoint.X(), thePoint.Y(), thePoint.Z());
306 AddPrimitiveArray (aPoints, theToEvalMinMax);
309 // =======================================================================
312 // =======================================================================
313 void Graphic3d_Group::Text (const Standard_CString /*theText*/,
314 const Graphic3d_Vertex& thePoint,
315 const Standard_Real /*theHeight*/,
316 const Standard_Real /*theAngle*/,
317 const Graphic3d_TextPath /*theTp*/,
318 const Graphic3d_HorizontalTextAlignment /*theHta*/,
319 const Graphic3d_VerticalTextAlignment /*theVta*/,
320 const Standard_Boolean theToEvalMinMax)
329 Standard_ShortReal x, y, z;
330 thePoint.Coord (x, y, z);
331 myStructure->CStructure()->Is2dText = Standard_True;
332 myBounds.Add (Graphic3d_Vec4 (static_cast<Standard_ShortReal> (x),
333 static_cast<Standard_ShortReal> (y),
334 static_cast<Standard_ShortReal> (z),
340 // =======================================================================
343 // =======================================================================
344 void Graphic3d_Group::Text (const Standard_CString theText,
345 const Graphic3d_Vertex& thePoint,
346 const Standard_Real theHeight,
347 const Standard_Boolean theToEvalMinMax)
349 Text (theText, thePoint, theHeight, 0.0,
350 Graphic3d_TP_RIGHT, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM, theToEvalMinMax);
353 // =======================================================================
356 // =======================================================================
357 void Graphic3d_Group::Text (const TCollection_ExtendedString& theText,
358 const Graphic3d_Vertex& thePoint,
359 const Standard_Real theHeight,
360 const Standard_Real theAngle,
361 const Graphic3d_TextPath theTp,
362 const Graphic3d_HorizontalTextAlignment theHta,
363 const Graphic3d_VerticalTextAlignment theVta,
364 const Standard_Boolean theToEvalMinMax)
366 const NCollection_String aText (theText.ToExtString());
367 Text (aText.ToCString(), thePoint, theHeight, theAngle,
368 theTp, theHta, theVta, theToEvalMinMax);
371 // =======================================================================
374 // =======================================================================
375 void Graphic3d_Group::Text (const TCollection_ExtendedString& theText,
376 const gp_Ax2& theOrientation,
377 const Standard_Real theHeight,
378 const Standard_Real theAngle,
379 const Graphic3d_TextPath theTP,
380 const Graphic3d_HorizontalTextAlignment theHTA,
381 const Graphic3d_VerticalTextAlignment theVTA,
382 const Standard_Boolean theToEvalMinMax,
383 const Standard_Boolean theHasOwnAnchor)
385 const NCollection_String aText (theText.ToExtString());
386 Text (aText.ToCString(),
397 // =======================================================================
400 // =======================================================================
401 void Graphic3d_Group::Text (const Standard_CString /*theText*/,
402 const gp_Ax2& theOrientation,
403 const Standard_Real /*theHeight*/,
404 const Standard_Real /*theAngle*/,
405 const Graphic3d_TextPath /*theTp*/,
406 const Graphic3d_HorizontalTextAlignment /*theHta*/,
407 const Graphic3d_VerticalTextAlignment /*theVta*/,
408 const Standard_Boolean theToEvalMinMax,
409 const Standard_Boolean /*theHasOwnAnchor*/)
418 myStructure->CStructure()->Is2dText = Standard_False;
419 myBounds.Add (Graphic3d_Vec4 (static_cast<Standard_ShortReal> (theOrientation.Location().X()),
420 static_cast<Standard_ShortReal> (theOrientation.Location().Y()),
421 static_cast<Standard_ShortReal> (theOrientation.Location().Z()),
427 // =======================================================================
430 // =======================================================================
431 void Graphic3d_Group::Text (const TCollection_ExtendedString& theText,
432 const Graphic3d_Vertex& thePoint,
433 const Standard_Real theHeight,
434 const Standard_Boolean theToEvalMinMax)
436 const NCollection_String aText (theText.ToExtString());
437 Text (aText.ToCString(), thePoint, theHeight, 0.0,
438 Graphic3d_TP_RIGHT, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM, theToEvalMinMax);