Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-25 09:20:01

0001 // Created on: 1991-06-12
0002 // Created by: NW,JPB,CAL
0003 // Copyright (c) 1991-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Graphic3d_Structure_HeaderFile
0018 #define _Graphic3d_Structure_HeaderFile
0019 
0020 #include <Graphic3d_CStructure.hxx>
0021 #include <NCollection_Map.hxx>
0022 #include <Graphic3d_Group.hxx>
0023 #include <NCollection_Sequence.hxx>
0024 #include <Graphic3d_SequenceOfHClipPlane.hxx>
0025 #include <Graphic3d_TypeOfConnection.hxx>
0026 #include <Graphic3d_TypeOfStructure.hxx>
0027 #include <Graphic3d_TransformPers.hxx>
0028 #include <Graphic3d_ZLayerId.hxx>
0029 #include <NCollection_IndexedMap.hxx>
0030 class Graphic3d_Structure;
0031 
0032 class Graphic3d_StructureManager;
0033 class Graphic3d_DataStructureManager;
0034 class Bnd_Box;
0035 
0036 //! This class allows the definition a graphic object.
0037 //! This graphic structure can be displayed, erased, or highlighted.
0038 //! This graphic structure can be connected with another graphic structure.
0039 class Graphic3d_Structure : public Standard_Transient
0040 {
0041   DEFINE_STANDARD_RTTIEXT(Graphic3d_Structure, Standard_Transient)
0042   friend class Graphic3d_Group;
0043 
0044 public:
0045   //! Creates a graphic object in the manager theManager.
0046   //! It will appear in all the views of the visualiser.
0047   //! The structure is not displayed when it is created.
0048   //! @param theManager structure manager holding this structure
0049   //! @param theLinkPrs another structure for creating a shadow (linked) structure
0050   Standard_EXPORT Graphic3d_Structure(
0051     const occ::handle<Graphic3d_StructureManager>& theManager,
0052     const occ::handle<Graphic3d_Structure>&        theLinkPrs = occ::handle<Graphic3d_Structure>());
0053 
0054   //! if WithDestruction == true then
0055   //! suppress all the groups of primitives in the structure.
0056   //! and it is mandatory to create a new group in <me>.
0057   //! if WithDestruction == false then
0058   //! clears all the groups of primitives in the structure.
0059   //! and all the groups are conserved and empty.
0060   //! They will be erased at the next screen update.
0061   //! The structure itself is conserved.
0062   //! The transformation and the attributes of <me> are conserved.
0063   //! The childs of <me> are conserved.
0064   virtual void Clear(const bool WithDestruction = true) { clear(WithDestruction); }
0065 
0066   //! Suppresses the structure <me>.
0067   //! It will be erased at the next screen update.
0068   Standard_EXPORT ~Graphic3d_Structure() override;
0069 
0070   //! Displays the structure <me> in all the views of the visualiser.
0071   Standard_EXPORT virtual void Display();
0072 
0073   //! Returns the current display priority for this structure.
0074   Graphic3d_DisplayPriority DisplayPriority() const { return myCStructure->Priority(); }
0075 
0076   //! Modifies the order of displaying the structure.
0077   //! Values are between 0 and 10.
0078   //! Structures are drawn according to their display priorities in ascending order.
0079   //! A structure of priority 10 is displayed the last and appears over the others.
0080   //! The default value is 5.
0081   //! Warning: If structure is displayed then the SetDisplayPriority method erases it and displays
0082   //! with the new priority. Raises Graphic3d_PriorityDefinitionError if Priority is greater than 10
0083   //! or a negative value.
0084   Standard_EXPORT void SetDisplayPriority(const Graphic3d_DisplayPriority thePriority);
0085 
0086   Standard_DEPRECATED("Deprecated since OCCT7.7, Graphic3d_DisplayPriority should be passed "
0087                       "instead of integer number to SetDisplayPriority()")
0088   void SetDisplayPriority(const int thePriority)
0089   {
0090     SetDisplayPriority((Graphic3d_DisplayPriority)thePriority);
0091   }
0092 
0093   //! Reset the current priority of the structure to the previous priority.
0094   //! Warning: If structure is displayed then the SetDisplayPriority() method erases it and displays
0095   //! with the previous priority.
0096   Standard_EXPORT void ResetDisplayPriority();
0097 
0098   //! Erases this structure in all the views of the visualiser.
0099   virtual void Erase() { erase(); }
0100 
0101   //! Highlights the structure in all the views with the given style
0102   //! @param[in] theStyle  the style (type of highlighting: box/color, color and opacity)
0103   //! @param[in] theToUpdateMgr  defines whether related computed structures will be
0104   //! highlighted via structure manager or not
0105   Standard_EXPORT void Highlight(const occ::handle<Graphic3d_PresentationAttributes>& theStyle,
0106                                  const bool theToUpdateMgr = true);
0107 
0108   //! Suppress the structure <me>.
0109   //! It will be erased at the next screen update.
0110   //! Warning: No more graphic operations in <me> after this call.
0111   //! Category: Methods to modify the class definition
0112   Standard_EXPORT void Remove();
0113 
0114   //! Computes axis-aligned bounding box of a structure.
0115   Standard_EXPORT virtual void CalculateBoundBox();
0116 
0117   //! Sets infinite flag.
0118   //! When TRUE, the MinMaxValues method returns:
0119   //! theXMin = theYMin = theZMin = RealFirst().
0120   //! theXMax = theYMax = theZMax = RealLast().
0121   //! By default, structure is created not infinite but empty.
0122   void SetInfiniteState(const bool theToSet)
0123   {
0124     if (!myCStructure.IsNull())
0125     {
0126       myCStructure->IsInfinite = theToSet ? 1 : 0;
0127     }
0128   }
0129 
0130   //! Set Z layer ID for the structure. The Z layer mechanism
0131   //! allows to display structures presented in higher layers in overlay
0132   //! of structures in lower layers by switching off z buffer depth
0133   //! test between layers
0134   Standard_EXPORT void SetZLayer(const Graphic3d_ZLayerId theLayerId);
0135 
0136   //! Get Z layer ID of displayed structure.
0137   //! The method returns -1 if the structure has no ID (deleted from graphic driver).
0138   Graphic3d_ZLayerId GetZLayer() const { return myCStructure->ZLayer(); }
0139 
0140   //! Changes a sequence of clip planes slicing the structure on rendering.
0141   //! @param[in] thePlanes  the set of clip planes.
0142   void SetClipPlanes(const occ::handle<Graphic3d_SequenceOfHClipPlane>& thePlanes)
0143   {
0144     if (!myCStructure.IsNull())
0145     {
0146       myCStructure->SetClipPlanes(thePlanes);
0147     }
0148   }
0149 
0150   //! Get clip planes slicing the structure on rendering.
0151   //! @return set of clip planes.
0152   const occ::handle<Graphic3d_SequenceOfHClipPlane>& ClipPlanes() const
0153   {
0154     return myCStructure->ClipPlanes();
0155   }
0156 
0157   //! Modifies the visibility indicator to true or
0158   //! false for the structure <me>.
0159   //! The default value at the definition of <me> is
0160   //! true.
0161   Standard_EXPORT void SetVisible(const bool AValue);
0162 
0163   //! Modifies the visualisation mode for the structure <me>.
0164   Standard_EXPORT virtual void SetVisual(const Graphic3d_TypeOfStructure AVisual);
0165 
0166   //! Modifies the minimum and maximum zoom coefficients
0167   //! for the structure <me>.
0168   //! The default value at the definition of <me> is unlimited.
0169   //! Category: Methods to modify the class definition
0170   //! Warning: Raises StructureDefinitionError if <LimitInf> is
0171   //! greater than <LimitSup> or if <LimitInf> or
0172   //! <LimitSup> is a negative value.
0173   Standard_EXPORT void SetZoomLimit(const double LimitInf, const double LimitSup);
0174 
0175   //! Marks the structure <me> representing wired structure needed for highlight only so it won't be
0176   //! added to BVH tree.
0177   void SetIsForHighlight(const bool isForHighlight)
0178   {
0179     if (!myCStructure.IsNull())
0180     {
0181       myCStructure->IsForHighlight = isForHighlight;
0182     }
0183   }
0184 
0185   //! Suppresses the highlight for the structure <me>
0186   //! in all the views of the visualiser.
0187   Standard_EXPORT void UnHighlight();
0188 
0189   virtual void Compute()
0190   {
0191     //
0192   }
0193 
0194   //! Returns the new Structure defined for the new visualization
0195   virtual void computeHLR(const occ::handle<Graphic3d_Camera>& theProjector,
0196                           occ::handle<Graphic3d_Structure>&    theStructure)
0197   {
0198     (void)theProjector;
0199     (void)theStructure;
0200   }
0201 
0202   //! Calculates structure transformation for specific camera position
0203   virtual void RecomputeTransformation(const occ::handle<Graphic3d_Camera>& theProjector)
0204   {
0205     (void)theProjector;
0206   }
0207 
0208   //! Forces a new construction of the structure <me>
0209   //! if <me> is displayed and TOS_COMPUTED.
0210   Standard_EXPORT void ReCompute();
0211 
0212   //! Forces a new construction of the structure <me>
0213   //! if <me> is displayed in <aProjetor> and TOS_COMPUTED.
0214   Standard_EXPORT void ReCompute(const occ::handle<Graphic3d_DataStructureManager>& aProjector);
0215 
0216   //! Returns the groups sequence included in this structure.
0217   const NCollection_Sequence<occ::handle<Graphic3d_Group>>& Groups() const
0218   {
0219     return myCStructure->Groups();
0220   }
0221 
0222   //! Returns the current number of groups in this structure.
0223   int NumberOfGroups() const { return myCStructure->Groups().Length(); }
0224 
0225   //! Append new group to this structure.
0226   Standard_EXPORT occ::handle<Graphic3d_Group> NewGroup();
0227 
0228   //! Returns the last created group or creates new one if list is empty.
0229   occ::handle<Graphic3d_Group> CurrentGroup()
0230   {
0231     if (Groups().IsEmpty())
0232     {
0233       return NewGroup();
0234     }
0235     return Groups().Last();
0236   }
0237 
0238   //! Returns the highlight attributes.
0239   const occ::handle<Graphic3d_PresentationAttributes>& HighlightStyle() const
0240   {
0241     return myCStructure->HighlightStyle();
0242   }
0243 
0244   //! Returns TRUE if this structure is deleted (after Remove() call).
0245   bool IsDeleted() const { return myCStructure.IsNull(); }
0246 
0247   //! Returns the display indicator for this structure.
0248   virtual bool IsDisplayed() const { return !myCStructure.IsNull() && myCStructure->stick != 0; }
0249 
0250   //! Returns true if the structure <me> is empty.
0251   //! Warning: A structure is empty if :
0252   //! it do not have group or all the groups are empties
0253   //! and it do not have descendant or all the descendants
0254   //! are empties.
0255   Standard_EXPORT bool IsEmpty() const;
0256 
0257   //! Returns true if the structure <me> is infinite.
0258   bool IsInfinite() const { return IsDeleted() || myCStructure->IsInfinite; }
0259 
0260   //! Returns the highlight indicator for this structure.
0261   virtual bool IsHighlighted() const
0262   {
0263     return !myCStructure.IsNull() && myCStructure->highlight != 0;
0264   }
0265 
0266   //! Returns TRUE if the structure is transformed.
0267   bool IsTransformed() const
0268   {
0269     return !myCStructure.IsNull() && !myCStructure->Transformation().IsNull()
0270            && myCStructure->Transformation()->Form() != gp_Identity;
0271   }
0272 
0273   //! Returns the visibility indicator for this structure.
0274   bool IsVisible() const { return !myCStructure.IsNull() && myCStructure->visible != 0; }
0275 
0276   //! Returns the coordinates of the boundary box of the structure <me>.
0277   //! If <theToIgnoreInfiniteFlag> is TRUE, the method returns actual graphical
0278   //! boundaries of the Graphic3d_Group components. Otherwise, the
0279   //! method returns boundaries taking into account infinite state
0280   //! of the structure. This approach generally used for application
0281   //! specific fit operation (e.g. fitting the model into screen,
0282   //! not taking into account infinite helper elements).
0283   //! Warning: If the structure <me> is empty then the empty box is returned,
0284   //! If the structure <me> is infinite then the whole box is returned.
0285   Standard_EXPORT Bnd_Box MinMaxValues(const bool theToIgnoreInfiniteFlag = false) const;
0286 
0287   //! Returns the visualisation mode for the structure <me>.
0288   Graphic3d_TypeOfStructure Visual() const { return myVisual; }
0289 
0290   //! Returns true if the connection is possible between
0291   //! <AStructure1> and <AStructure2> without a creation
0292   //! of a cycle.
0293   //!
0294   //! It's not possible to call the method
0295   //! AStructure1->Connect (AStructure2, TypeOfConnection)
0296   //! if
0297   //! - the set of all ancestors of <AStructure1> contains
0298   //! <AStructure1> and if the
0299   //! TypeOfConnection == TOC_DESCENDANT
0300   //! - the set of all descendants of <AStructure1> contains
0301   //! <AStructure2> and if the
0302   //! TypeOfConnection == TOC_ANCESTOR
0303   Standard_EXPORT static bool AcceptConnection(Graphic3d_Structure*       theStructure1,
0304                                                Graphic3d_Structure*       theStructure2,
0305                                                Graphic3d_TypeOfConnection theType);
0306 
0307   //! Returns the group of structures to which <me> is connected.
0308   Standard_EXPORT void Ancestors(NCollection_Map<occ::handle<Graphic3d_Structure>>& SG) const;
0309 
0310   //! If Atype is TOC_DESCENDANT then add <AStructure>
0311   //! as a child structure of <me>.
0312   //! If Atype is TOC_ANCESTOR then add <AStructure>
0313   //! as a parent structure of <me>.
0314   //! The connection propagates Display, Highlight, Erase,
0315   //! Remove, and stacks the transformations.
0316   //! No connection if the graph of the structures
0317   //! contains a cycle and <WithCheck> is true;
0318   Standard_EXPORT void Connect(Graphic3d_Structure*       theStructure,
0319                                Graphic3d_TypeOfConnection theType,
0320                                bool                       theWithCheck = false);
0321 
0322   Standard_DEPRECATED("Deprecated short-cut")
0323   void Connect(const occ::handle<Graphic3d_Structure>& thePrs)
0324   {
0325     Connect(thePrs.get(), Graphic3d_TOC_DESCENDANT);
0326   }
0327 
0328   //! Returns the group of structures connected to <me>.
0329   Standard_EXPORT void Descendants(NCollection_Map<occ::handle<Graphic3d_Structure>>& SG) const;
0330 
0331   //! Suppress the connection between <AStructure> and <me>.
0332   Standard_EXPORT void Disconnect(Graphic3d_Structure* theStructure);
0333 
0334   Standard_DEPRECATED("Deprecated alias for Disconnect()")
0335   void Remove(const occ::handle<Graphic3d_Structure>& thePrs) { Disconnect(thePrs.get()); }
0336 
0337   //! If Atype is TOC_DESCENDANT then suppress all
0338   //! the connections with the child structures of <me>.
0339   //! If Atype is TOC_ANCESTOR then suppress all
0340   //! the connections with the parent structures of <me>.
0341   Standard_EXPORT void DisconnectAll(const Graphic3d_TypeOfConnection AType);
0342 
0343   Standard_DEPRECATED("Deprecated alias for DisconnectAll()")
0344   void RemoveAll() { DisconnectAll(Graphic3d_TOC_DESCENDANT); }
0345 
0346   //! Returns <ASet> the group of structures :
0347   //! - directly or indirectly connected to <AStructure> if the
0348   //! TypeOfConnection == TOC_DESCENDANT
0349   //! - to which <AStructure> is directly or indirectly connected
0350   //! if the TypeOfConnection == TOC_ANCESTOR
0351   Standard_EXPORT static void Network(Graphic3d_Structure*                   theStructure,
0352                                       const Graphic3d_TypeOfConnection       theType,
0353                                       NCollection_Map<Graphic3d_Structure*>& theSet);
0354 
0355   void SetOwner(void* const theOwner) { myOwner = theOwner; }
0356 
0357   void* Owner() const { return myOwner; }
0358 
0359   void SetHLRValidation(const bool theFlag)
0360   {
0361     if (!myCStructure.IsNull())
0362     {
0363       myCStructure->HLRValidation = theFlag ? 1 : 0;
0364     }
0365   }
0366 
0367   //! Hidden parts stored in this structure are valid if:
0368   //! 1) the owner is defined.
0369   //! 2) they are not invalid.
0370   bool HLRValidation() const { return myOwner != nullptr && myCStructure->HLRValidation != 0; }
0371 
0372   //! Return local transformation.
0373   const occ::handle<TopLoc_Datum3D>& Transformation() const
0374   {
0375     return myCStructure->Transformation();
0376   }
0377 
0378   //! Modifies the current local transformation
0379   Standard_EXPORT void SetTransformation(const occ::handle<TopLoc_Datum3D>& theTrsf);
0380 
0381   //! Modifies the current transform persistence (pan, zoom or rotate)
0382   Standard_EXPORT void SetTransformPersistence(
0383     const occ::handle<Graphic3d_TransformPers>& theTrsfPers);
0384 
0385   //! @return transform persistence of the presentable object.
0386   const occ::handle<Graphic3d_TransformPers>& TransformPersistence() const
0387   {
0388     return myCStructure->TransformPersistence();
0389   }
0390 
0391   //! Sets if the structure location has mutable nature (content or location will be changed
0392   //! regularly).
0393   void SetMutable(const bool theIsMutable)
0394   {
0395     if (!myCStructure.IsNull())
0396     {
0397       myCStructure->IsMutable = theIsMutable;
0398     }
0399   }
0400 
0401   //! Returns true if structure has mutable nature (content or location are be changed regularly).
0402   //! Mutable structure will be managed in different way than static ones.
0403   bool IsMutable() const { return !myCStructure.IsNull() && myCStructure->IsMutable; }
0404 
0405   Graphic3d_TypeOfStructure ComputeVisual() const { return myComputeVisual; }
0406 
0407   //! Clears the structure <me>.
0408   Standard_EXPORT void GraphicClear(const bool WithDestruction);
0409 
0410   void GraphicConnect(const occ::handle<Graphic3d_Structure>& theDaughter)
0411   {
0412     if (!myCStructure.IsNull())
0413     {
0414       myCStructure->Connect(*theDaughter->myCStructure);
0415     }
0416   }
0417 
0418   void GraphicDisconnect(const occ::handle<Graphic3d_Structure>& theDaughter)
0419   {
0420     if (!myCStructure.IsNull())
0421     {
0422       myCStructure->Disconnect(*theDaughter->myCStructure);
0423     }
0424   }
0425 
0426   //! Internal method which sets new transformation without calling graphic manager callbacks.
0427   void GraphicTransform(const occ::handle<TopLoc_Datum3D>& theTrsf)
0428   {
0429     if (!myCStructure.IsNull())
0430     {
0431       myCStructure->SetTransformation(theTrsf);
0432     }
0433   }
0434 
0435   //! Returns the identification number of this structure.
0436   int Identification() const { return myCStructure->Identification(); }
0437 
0438   //! Prints information about the network associated
0439   //! with the structure <AStructure>.
0440   Standard_EXPORT static void PrintNetwork(const occ::handle<Graphic3d_Structure>& AStructure,
0441                                            const Graphic3d_TypeOfConnection        AType);
0442 
0443   //! Suppress the structure in the list of descendants or in the list of ancestors.
0444   Standard_EXPORT void Remove(Graphic3d_Structure*             thePtr,
0445                               const Graphic3d_TypeOfConnection theType);
0446 
0447   void SetComputeVisual(const Graphic3d_TypeOfStructure theVisual)
0448   {
0449     // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or
0450     // TOS_SHADING. This declaration permits to calculate proper representation of the structure
0451     // calculated by Compute instead of passage to TOS_COMPUTED.
0452     if (theVisual != Graphic3d_TOS_COMPUTED)
0453     {
0454       myComputeVisual = theVisual;
0455     }
0456   }
0457 
0458   //! Returns the low-level structure
0459   const occ::handle<Graphic3d_CStructure>& CStructure() const { return myCStructure; }
0460 
0461   //! Dumps the content of me into the stream
0462   Standard_EXPORT virtual void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0463 
0464 protected:
0465   //! Appends new descendant structure.
0466   Standard_EXPORT bool AppendDescendant(Graphic3d_Structure* theDescendant);
0467 
0468   //! Removes the given descendant structure.
0469   Standard_EXPORT bool RemoveDescendant(Graphic3d_Structure* theDescendant);
0470 
0471   //! Appends new ancestor structure.
0472   Standard_EXPORT bool AppendAncestor(Graphic3d_Structure* theAncestor);
0473 
0474   //! Removes the given ancestor structure.
0475   Standard_EXPORT bool RemoveAncestor(Graphic3d_Structure* theAncestor);
0476 
0477   //! Clears all the groups of primitives in the structure.
0478   Standard_EXPORT void clear(const bool WithDestruction);
0479 
0480   //! Erases this structure in all the views of the visualiser.
0481   Standard_EXPORT void erase();
0482 
0483 private:
0484   //! Suppress in the structure <me>, the group theGroup.
0485   //! It will be erased at the next screen update.
0486   Standard_EXPORT void Remove(const occ::handle<Graphic3d_Group>& theGroup);
0487 
0488   //! Returns the extreme coordinates found in the structure <me> without transformation applied.
0489   Standard_EXPORT Graphic3d_BndBox4f minMaxCoord() const;
0490 
0491   //! Gets untransformed bounding box from structure.
0492   Standard_EXPORT void getBox(Graphic3d_BndBox3d& theBox,
0493                               const bool          theToIgnoreInfiniteFlag = false) const;
0494 
0495   //! Adds transformed (with myCStructure->Transformation) bounding box of structure to theBox.
0496   Standard_EXPORT void addTransformed(Graphic3d_BndBox3d& theBox,
0497                                       const bool          theToIgnoreInfiniteFlag = false) const;
0498 
0499   //! Returns the manager to which <me> is associated.
0500   Standard_EXPORT occ::handle<Graphic3d_StructureManager> StructureManager() const;
0501 
0502   //! Calls the Update method of the StructureManager which contains the Structure <me>.
0503   //! If theUpdateLayer is true then invalidates bounding box of ZLayer.
0504   Standard_EXPORT void Update(const bool theUpdateLayer = false) const;
0505 
0506 protected:
0507   Graphic3d_StructureManager*                  myStructureManager;
0508   occ::handle<Graphic3d_CStructure>            myCStructure;
0509   NCollection_IndexedMap<Graphic3d_Structure*> myAncestors;
0510   NCollection_IndexedMap<Graphic3d_Structure*> myDescendants;
0511   void*                                        myOwner;
0512   Graphic3d_TypeOfStructure                    myVisual;
0513   Graphic3d_TypeOfStructure                    myComputeVisual;
0514 };
0515 
0516 #endif // _Graphic3d_Structure_HeaderFile