Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:49

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