diff --git a/src/AIS/AIS_ConnectedInteractive.cxx b/src/AIS/AIS_ConnectedInteractive.cxx index d2d5010762..d65c174872 100644 --- a/src/AIS/AIS_ConnectedInteractive.cxx +++ b/src/AIS/AIS_ConnectedInteractive.cxx @@ -14,21 +14,16 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. - #include + #include -#include #include #include -#include -#include #include #include #include -#include #include #include -#include #include #include #include @@ -57,12 +52,17 @@ AIS_InteractiveObject(aTypeOfPresentation3d) } //======================================================================= -//function : Connect -//purpose : +//function : connect +//purpose : //======================================================================= -void AIS_ConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj) +void AIS_ConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj, + const Handle(Geom_Transformation)& theLocation) { - if (myReference == theAnotherObj) return; + if (myReference == theAnotherObj) + { + setLocalTransformation (theLocation); + return; + } Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (theAnotherObj); if (!aConnected.IsNull()) @@ -82,21 +82,9 @@ void AIS_ConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& the { myTypeOfPresentation3d = myReference->TypeOfPresentation3d(); } + setLocalTransformation (theLocation); } -//======================================================================= -//function : Connect -//purpose : -//======================================================================= -void AIS_ConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, - const gp_Trsf& theLocation) -{ - Connect (theAnotherObj); - - SetLocalTransformation (theLocation); -} - - //======================================================================= //function : Disconnect //purpose : diff --git a/src/AIS/AIS_ConnectedInteractive.hxx b/src/AIS/AIS_ConnectedInteractive.hxx index 31255f1fe2..8531496a80 100644 --- a/src/AIS/AIS_ConnectedInteractive.hxx +++ b/src/AIS/AIS_ConnectedInteractive.hxx @@ -17,28 +17,9 @@ #ifndef _AIS_ConnectedInteractive_HeaderFile #define _AIS_ConnectedInteractive_HeaderFile -#include -#include - -#include #include -#include #include -#include -#include -#include -#include -class AIS_InteractiveObject; -class Standard_NotImplemented; -class gp_Trsf; -class Prs3d_Presentation; -class Prs3d_Projector; -class Geom_Transformation; -class TopoDS_Shape; - - -class AIS_ConnectedInteractive; -DEFINE_STANDARD_HANDLE(AIS_ConnectedInteractive, AIS_InteractiveObject) +#include //! Creates an arbitrary located instance of another Interactive Object, //! which serves as a reference. @@ -54,7 +35,7 @@ DEFINE_STANDARD_HANDLE(AIS_ConnectedInteractive, AIS_InteractiveObject) //! Also ConnectedInteractive will handle HLR if its reference based on AIS_Shape. class AIS_ConnectedInteractive : public AIS_InteractiveObject { - + DEFINE_STANDARD_RTTIEXT(AIS_ConnectedInteractive, AIS_InteractiveObject) public: //! Disconnects the previous view and sets highlight @@ -71,12 +52,19 @@ public: //! Establishes the connection between the Connected //! Interactive Object, anotherIobj, and its reference. - Standard_EXPORT virtual void Connect (const Handle(AIS_InteractiveObject)& anotherIObj); + Standard_EXPORT void Connect (const Handle(AIS_InteractiveObject)& theAnotherObj) { connect (theAnotherObj, Handle(Geom_Transformation)()); } //! Establishes the connection between the Connected //! Interactive Object, anotherIobj, and its reference. //! Locates instance in aLocation. - Standard_EXPORT virtual void Connect (const Handle(AIS_InteractiveObject)& anotherIobj, const gp_Trsf& aLocation); + Standard_EXPORT void Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, + const gp_Trsf& theLocation) { connect (theAnotherObj, new Geom_Transformation (theLocation)); } + + //! Establishes the connection between the Connected + //! Interactive Object, anotherIobj, and its reference. + //! Locates instance in aLocation. + Standard_EXPORT void Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, + const Handle(Geom_Transformation)& theLocation) { connect (theAnotherObj, theLocation); } //! Returns true if there is a connection established //! between the presentation and its source reference. @@ -104,8 +92,6 @@ public: || myReference->AcceptDisplayMode (theMode); } - DEFINE_STANDARD_RTTIEXT(AIS_ConnectedInteractive,AIS_InteractiveObject) - protected: //! Calculates the view aPresentation and its updates. @@ -148,6 +134,9 @@ protected: //! given by . Standard_EXPORT void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation, const TopoDS_Shape& aShape); + Standard_EXPORT void connect (const Handle(AIS_InteractiveObject)& theAnotherObj, + const Handle(Geom_Transformation)& theLocation); + protected: Handle(AIS_InteractiveObject) myReference; @@ -155,4 +144,6 @@ protected: }; +DEFINE_STANDARD_HANDLE(AIS_ConnectedInteractive, AIS_InteractiveObject) + #endif // _AIS_ConnectedInteractive_HeaderFile diff --git a/src/AIS/AIS_Manipulator.cxx b/src/AIS/AIS_Manipulator.cxx index 2bd71c1cbd..7b46d2b7d0 100644 --- a/src/AIS/AIS_Manipulator.cxx +++ b/src/AIS/AIS_Manipulator.cxx @@ -640,10 +640,11 @@ void AIS_Manipulator::updateTransformation() aTrsf.SetTransformation (gp_Ax2 (gp::Origin(), aVDir, aXDir), gp::XOY()); } - AIS_InteractiveObject::SetLocalTransformation (aTrsf); - - Handle(Geom_Transformation) aGeomTrsf = new Geom_Transformation (this->Transformation()); - + Handle(Geom_Transformation) aGeomTrsf = new Geom_Transformation (aTrsf); + // we explicitly call here setLocalTransformation() of the base class + // since AIS_Manipulator::setLocalTransformation() implementation throws exception + // as protection from external calls + AIS_InteractiveObject::setLocalTransformation (aGeomTrsf); for (Standard_Integer anIt = 0; anIt < 3; ++anIt) { myAxes[anIt].Transform (aGeomTrsf); @@ -769,14 +770,13 @@ void AIS_Manipulator::setTransformPersistence (const Handle(Graphic3d_TransformP } //======================================================================= -//function : SetLocalTransformation -//purpose : +//function : setLocalTransformation +//purpose : //======================================================================= -void AIS_Manipulator::SetLocalTransformation (const gp_Trsf& /*theTransformation*/) +void AIS_Manipulator::setLocalTransformation (const Handle(Geom_Transformation)& /*theTrsf*/) { - Standard_ASSERT_INVOKE ( - "AIS_Manipulator::SetLocalTransformation: " - "Custom transformation is not supported by this class"); + Standard_ASSERT_INVOKE ("AIS_Manipulator::setLocalTransformation: " + "Custom transformation is not supported by this class"); } //======================================================================= diff --git a/src/AIS/AIS_Manipulator.hxx b/src/AIS/AIS_Manipulator.hxx index 358ee17e20..2cc9c864b3 100644 --- a/src/AIS/AIS_Manipulator.hxx +++ b/src/AIS/AIS_Manipulator.hxx @@ -252,14 +252,6 @@ public: //! @name Configuration of graphical transformations //! when enabling zoom persistence. Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE; - //! Redefines local transformation management method to inform user of inproper use. - //! @warning this interactive object does not support setting custom local transformation, - //! this class solely uses this property to implement visual positioning of the manipulator - //! without need for recomputing presentation. - //! @warning Invokes debug assertion in debug to catch incompatible usage of the - //! method, silently does nothing in release mode. - Standard_EXPORT virtual void SetLocalTransformation (const gp_Trsf& theTransformation) Standard_OVERRIDE; - public: //! @name Setters for parameters AIS_ManipulatorMode ActiveMode() const { return myCurrentMode; } @@ -349,6 +341,15 @@ protected: Standard_EXPORT void setTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers); + //! Redefines local transformation management method to inform user of inproper use. + //! @warning this interactive object does not support setting custom local transformation, + //! this class solely uses this property to implement visual positioning of the manipulator + //! without need for recomputing presentation. + //! @warning Invokes debug assertion in debug to catch incompatible usage of the + //! method, silently does nothing in release mode. + Standard_EXPORT virtual void setLocalTransformation (const Handle(Geom_Transformation)& theTrsf) Standard_OVERRIDE; + using AIS_InteractiveObject::SetLocalTransformation; // hide visibility + protected: //! @name Auxilliary classes to fill presentation with proper primitives class Quadric @@ -511,17 +512,17 @@ protected: //! @name Auxilliary classes to fill presentation with proper primiti { if (!myHighlightTranslator.IsNull()) { - myHighlightTranslator->Transform (theTransformation); + myHighlightTranslator->SetTransformation (theTransformation); } if (!myHighlightScaler.IsNull()) { - myHighlightScaler->Transform (theTransformation); + myHighlightScaler->SetTransformation (theTransformation); } if (!myHighlightRotator.IsNull()) { - myHighlightRotator->Transform (theTransformation); + myHighlightRotator->SetTransformation (theTransformation); } } diff --git a/src/AIS/AIS_MultipleConnectedInteractive.cxx b/src/AIS/AIS_MultipleConnectedInteractive.cxx index 087b82460d..0aa8061564 100644 --- a/src/AIS/AIS_MultipleConnectedInteractive.cxx +++ b/src/AIS/AIS_MultipleConnectedInteractive.cxx @@ -14,23 +14,16 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include #include -#include -#include -#include -#include -#include -#include #include #include -#include #include #include #include -#include #include IMPLEMENT_STANDARD_RTTIEXT(AIS_MultipleConnectedInteractive,AIS_InteractiveObject) @@ -190,11 +183,11 @@ Standard_Integer AIS_MultipleConnectedInteractive::Signature() const } //======================================================================= -//function : Connect +//function : connect //purpose : //======================================================================= -Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, - const gp_Trsf& theTransformation, +Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj, + const Handle(Geom_Transformation)& theTrsf, const Handle(Graphic3d_TransformPers)& theTrsfPers) { if (myAssemblyOwner.IsNull()) @@ -207,7 +200,7 @@ Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const H { Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive(); aNewMultiConnected->myAssemblyOwner = myAssemblyOwner; - aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformation()); + aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformationGeom()); // Perform deep copy of instance tree for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next()) @@ -226,13 +219,12 @@ Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const H else { Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive(); - aNewConnected->Connect (theAnotherObj); - aNewConnected->SetLocalTransformation (theAnotherObj->LocalTransformation()); + aNewConnected->Connect (theAnotherObj, theAnotherObj->LocalTransformationGeom()); anObjectToAdd = aNewConnected; } - anObjectToAdd->SetLocalTransformation (theTransformation); + anObjectToAdd->SetLocalTransformation (theTrsf); if (!theTrsfPers.IsNull()) { anObjectToAdd->SetTransformPersistence (theTrsfPers); @@ -241,25 +233,6 @@ Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const H return anObjectToAdd; } -//======================================================================= -//function : Connect -//purpose : -//======================================================================= -Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj) -{ - return Connect (theAnotherObj, theAnotherObj->LocalTransformation(), theAnotherObj->TransformPersistence()); -} - -//======================================================================= -//function : Connect -//purpose : -//======================================================================= -Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, - const gp_Trsf& theTransformation) -{ - return Connect (theAnotherObj, theTransformation, theAnotherObj->TransformPersistence()); -} - //======================================================================= //function : HasConnection //purpose : diff --git a/src/AIS/AIS_MultipleConnectedInteractive.hxx b/src/AIS/AIS_MultipleConnectedInteractive.hxx index b90e5051cc..144f93198e 100644 --- a/src/AIS/AIS_MultipleConnectedInteractive.hxx +++ b/src/AIS/AIS_MultipleConnectedInteractive.hxx @@ -17,26 +17,8 @@ #ifndef _AIS_MultipleConnectedInteractive_HeaderFile #define _AIS_MultipleConnectedInteractive_HeaderFile -#include -#include - #include -#include #include -#include -#include -#include -#include -class AIS_InteractiveObject; -class gp_Trsf; -class gp_Pnt; -class Prs3d_Presentation; -class Prs3d_Projector; -class Geom_Transformation; - - -class AIS_MultipleConnectedInteractive; -DEFINE_STANDARD_HANDLE(AIS_MultipleConnectedInteractive, AIS_InteractiveObject) //! Defines an Interactive Object by gathering together //! several object presentations. This is done through a @@ -45,40 +27,23 @@ DEFINE_STANDARD_HANDLE(AIS_MultipleConnectedInteractive, AIS_InteractiveObject) //! calculations of presentation are avoided. class AIS_MultipleConnectedInteractive : public AIS_InteractiveObject { - + DEFINE_STANDARD_RTTIEXT(AIS_MultipleConnectedInteractive, AIS_InteractiveObject) public: - //! Initializes the Interactive Object with multiple //! connections to AIS_Interactive objects. Standard_EXPORT AIS_MultipleConnectedInteractive(); - - //! Establishes the connection between the Connected Interactive Object, theInteractive, and its reference. - //! Copies local transformation and transformation persistence mode from theInteractive. - //! @return created instance object (AIS_ConnectedInteractive or AIS_MultipleConnectedInteractive) - Standard_EXPORT Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theInteractive); - - //! Establishes the connection between the Connected Interactive Object, theInteractive, and its reference. - //! Locates instance in theLocation and copies transformation persistence mode from theInteractive. - //! @return created instance object (AIS_ConnectedInteractive or AIS_MultipleConnectedInteractive) - Standard_EXPORT Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theInteractive, const gp_Trsf& theLocation); - + //! Establishes the connection between the Connected Interactive Object, theInteractive, and its reference. //! Locates instance in theLocation and applies specified transformation persistence mode. //! @return created instance object (AIS_ConnectedInteractive or AIS_MultipleConnectedInteractive) - Standard_EXPORT virtual Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theInteractive, - const gp_Trsf& theLocation, - const Handle(Graphic3d_TransformPers)& theTrsfPers); - - Standard_DEPRECATED("This method is deprecated - Connect() taking Graphic3d_TransformPers should be called instead") - Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theInteractive, - const gp_Trsf& theLocation, - const Graphic3d_TransModeFlags& theTrsfPersFlag, - const gp_Pnt& theTrsfPersPoint) + Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, + const Handle(Geom_Transformation)& theLocation, + const Handle(Graphic3d_TransformPers)& theTrsfPers) { - return Connect (theInteractive, theLocation, Graphic3d_TransformPers::FromDeprecatedParams (theTrsfPersFlag, theTrsfPersPoint)); + return connect (theAnotherObj, theLocation, theTrsfPers); } - + Standard_EXPORT virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE; Standard_EXPORT virtual Standard_Integer Signature() const Standard_OVERRIDE; @@ -114,10 +79,45 @@ public: //! children of multiple connected interactive object. Standard_EXPORT virtual Standard_Boolean HasSelection (const Standard_Integer theMode) const Standard_OVERRIDE; - DEFINE_STANDARD_RTTIEXT(AIS_MultipleConnectedInteractive,AIS_InteractiveObject) +public: // short aliases to Connect() method + + //! Establishes the connection between the Connected Interactive Object, theInteractive, and its reference. + //! Copies local transformation and transformation persistence mode from theInteractive. + //! @return created instance object (AIS_ConnectedInteractive or AIS_MultipleConnectedInteractive) + Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theAnotherObj) + { + return connect (theAnotherObj, theAnotherObj->LocalTransformationGeom(), theAnotherObj->TransformPersistence()); + } + + //! Establishes the connection between the Connected Interactive Object, theInteractive, and its reference. + //! Locates instance in theLocation and copies transformation persistence mode from theInteractive. + //! @return created instance object (AIS_ConnectedInteractive or AIS_MultipleConnectedInteractive) + Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, + const gp_Trsf& theLocation) + { + return connect (theAnotherObj, new Geom_Transformation (theLocation), theAnotherObj->TransformPersistence()); + } + + //! Establishes the connection between the Connected Interactive Object, theInteractive, and its reference. + //! Locates instance in theLocation and applies specified transformation persistence mode. + //! @return created instance object (AIS_ConnectedInteractive or AIS_MultipleConnectedInteractive) + Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, + const gp_Trsf& theLocation, + const Handle(Graphic3d_TransformPers)& theTrsfPers) + { + return connect (theAnotherObj, new Geom_Transformation (theLocation), theTrsfPers); + } + + Standard_DEPRECATED("This method is deprecated - Connect() taking Graphic3d_TransformPers should be called instead") + Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theInteractive, + const gp_Trsf& theLocation, + const Graphic3d_TransModeFlags& theTrsfPersFlag, + const gp_Pnt& theTrsfPersPoint) + { + return connect (theInteractive, new Geom_Transformation (theLocation), Graphic3d_TransformPers::FromDeprecatedParams (theTrsfPersFlag, theTrsfPersPoint)); + } protected: - //! this method is redefined virtual; //! when the instance is connected to another @@ -127,22 +127,20 @@ protected: //! a transformation if there's one stored. Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPresentation, const Standard_Integer aMode = 0) Standard_OVERRIDE; - + //! Establishes the connection between the Connected Interactive Object, theInteractive, and its reference. + //! Locates instance in theLocation and applies specified transformation persistence mode. + //! @return created instance object (AIS_ConnectedInteractive or AIS_MultipleConnectedInteractive) + Standard_EXPORT virtual Handle(AIS_InteractiveObject) connect (const Handle(AIS_InteractiveObject)& theInteractive, + const Handle(Geom_Transformation)& theLocation, + const Handle(Graphic3d_TransformPers)& theTrsfPers); private: - //! Computes the selection for whole subtree in scene hierarchy. Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) Standard_OVERRIDE; - - }; - - - - - +DEFINE_STANDARD_HANDLE(AIS_MultipleConnectedInteractive, AIS_InteractiveObject) #endif // _AIS_MultipleConnectedInteractive_HeaderFile diff --git a/src/AIS/AIS_Trihedron.cxx b/src/AIS/AIS_Trihedron.cxx index 62e4c4d1bb..27d55068ee 100644 --- a/src/AIS/AIS_Trihedron.cxx +++ b/src/AIS/AIS_Trihedron.cxx @@ -14,13 +14,13 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include #include #include #include -#include #include #include #include @@ -102,18 +102,18 @@ void AIS_Trihedron::SetComponent(const Handle(Geom_Axis2Placement)& aComponent) } //======================================================================= -//function : SetLocation -//purpose : +//function : setLocalTransformation +//purpose : //======================================================================= -void AIS_Trihedron::SetLocalTransformation (const gp_Trsf& theTransformation) +void AIS_Trihedron::setLocalTransformation (const Handle(Geom_Transformation)& theTrsf) { // Update location to the subshapes Standard_Integer anIdx; for (anIdx = 0; anIdx < 7; anIdx++) - myShapes[anIdx]->SetLocalTransformation (theTransformation); + myShapes[anIdx]->SetLocalTransformation (theTrsf); - AIS_InteractiveObject::SetLocalTransformation (theTransformation); + AIS_InteractiveObject::setLocalTransformation (theTrsf); } //======================================================================= diff --git a/src/AIS/AIS_Trihedron.hxx b/src/AIS/AIS_Trihedron.hxx index 03887c81ba..30c400638a 100644 --- a/src/AIS/AIS_Trihedron.hxx +++ b/src/AIS/AIS_Trihedron.hxx @@ -68,7 +68,7 @@ DEFINE_STANDARD_HANDLE(AIS_Trihedron, AIS_InteractiveObject) //! Plane to retrieve the shapes. class AIS_Trihedron : public AIS_InteractiveObject { - + DEFINE_STANDARD_RTTIEXT(AIS_Trihedron, AIS_InteractiveObject) public: @@ -132,9 +132,7 @@ public: //! WARNING : must be applied //! to the object to display before computation !!! Standard_EXPORT virtual void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTrsf, const Handle(Prs3d_Presentation)& aPresentation) Standard_OVERRIDE; - - Standard_EXPORT void SetLocalTransformation (const gp_Trsf& theTransformation) Standard_OVERRIDE; - + //! Returns index 3, selection of the planes XOY, YOZ, XOZ. Standard_EXPORT virtual Standard_Integer Signature() const Standard_OVERRIDE; @@ -168,15 +166,11 @@ public: //! Removes the non-default settings for width set in SetWidth. Standard_EXPORT void UnsetWidth() Standard_OVERRIDE; - DEFINE_STANDARD_RTTIEXT(AIS_Trihedron,AIS_InteractiveObject) - protected: - - + Standard_EXPORT virtual void setLocalTransformation (const Handle(Geom_Transformation)& theTrsf) Standard_OVERRIDE; private: - Standard_EXPORT void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPresentation, const Standard_Integer aMode = 0) Standard_OVERRIDE; diff --git a/src/Geom/Geom_Transformation.cxx b/src/Geom/Geom_Transformation.cxx index ed7ed87744..480717b5b0 100644 --- a/src/Geom/Geom_Transformation.cxx +++ b/src/Geom/Geom_Transformation.cxx @@ -14,27 +14,9 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. - #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -IMPLEMENT_STANDARD_RTTIEXT(Geom_Transformation,MMgt_TShared) - -typedef Geom_Transformation Transformation; -typedef gp_Ax1 Ax1; -typedef gp_Ax2 Ax2; -typedef gp_Ax3 Ax3; -typedef gp_Pnt Pnt; -typedef gp_TrsfForm TrsfForm; -typedef gp_Vec Vec; +IMPLEMENT_STANDARD_RTTIEXT(Geom_Transformation, Standard_Transient) Geom_Transformation::Geom_Transformation () { } @@ -46,99 +28,27 @@ Geom_Transformation::Geom_Transformation (const gp_Trsf& T) Handle(Geom_Transformation) Geom_Transformation::Copy() const { Handle(Geom_Transformation) T; - T = new Transformation (gpTrsf); + T = new Geom_Transformation (gpTrsf); return T; } - -void Geom_Transformation::SetMirror (const gp_Pnt& P) { gpTrsf.SetMirror (P); } - -void Geom_Transformation::SetMirror (const gp_Ax1& A1) { gpTrsf.SetMirror (A1); } - -void Geom_Transformation::SetMirror (const gp_Ax2& A2) { gpTrsf.SetMirror (A2);} - -void Geom_Transformation::SetRotation (const gp_Ax1& A1, const Standard_Real Ang) { - - gpTrsf.SetRotation (A1, Ang); -} - -void Geom_Transformation::SetScale (const gp_Pnt& P, const Standard_Real S) { - - gpTrsf.SetScale (P, S); -} - - -void Geom_Transformation::SetTransformation (const gp_Ax3& ToAxis) { - - gpTrsf.SetTransformation (ToAxis); -} - - -void Geom_Transformation::SetTransformation ( -const gp_Ax3& FromAxis1, const gp_Ax3& ToAxis2) { - - gpTrsf.SetTransformation (FromAxis1, ToAxis2); -} - - -void Geom_Transformation::SetTranslation (const gp_Vec& V) { - - gpTrsf.SetTranslation (V); -} - - -void Geom_Transformation::SetTranslation (const gp_Pnt& P1, const gp_Pnt& P2) { - - gpTrsf.SetTranslation (P1, P2); -} - - -void Geom_Transformation::SetTrsf (const gp_Trsf& T) { gpTrsf = T; } - -Standard_Boolean Geom_Transformation::IsNegative () const {return gpTrsf.IsNegative();} - -TrsfForm Geom_Transformation::Form () const { return gpTrsf.Form(); } - -Standard_Real Geom_Transformation::ScaleFactor () const { return gpTrsf.ScaleFactor(); } - -const gp_Trsf& Geom_Transformation::Trsf () const { return gpTrsf; } - -Standard_Real Geom_Transformation::Value (const Standard_Integer Row, const Standard_Integer Col) const { - - return gpTrsf.Value (Row, Col); -} - - -void Geom_Transformation::Invert () { gpTrsf.Invert(); } - - Handle(Geom_Transformation) Geom_Transformation::Inverted () const { - return new Transformation (gpTrsf.Inverted()); + return new Geom_Transformation (gpTrsf.Inverted()); } Handle(Geom_Transformation) Geom_Transformation::Multiplied ( const Handle(Geom_Transformation)& Other) const { - return new Transformation (gpTrsf.Multiplied (Other->Trsf())); + return new Geom_Transformation (gpTrsf.Multiplied (Other->Trsf())); } - -void Geom_Transformation::Multiply (const Handle(Geom_Transformation)& Other) { - - gpTrsf.Multiply (Other->Trsf()); -} - - -void Geom_Transformation::Power (const Standard_Integer N) { gpTrsf.Power (N); } - - Handle(Geom_Transformation) Geom_Transformation::Powered (const Standard_Integer N) const { gp_Trsf T = gpTrsf; T.Power (N); - return new Transformation (T); + return new Geom_Transformation (T); } @@ -146,10 +56,3 @@ void Geom_Transformation::PreMultiply (const Handle(Geom_Transformation)& Other) gpTrsf.PreMultiply (Other->Trsf()); } - - -void Geom_Transformation::Transforms (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const { - - gpTrsf.Transforms (X, Y, Z); -} - diff --git a/src/Geom/Geom_Transformation.hxx b/src/Geom/Geom_Transformation.hxx index 178b8a4f2e..46e69c60a6 100644 --- a/src/Geom/Geom_Transformation.hxx +++ b/src/Geom/Geom_Transformation.hxx @@ -17,27 +17,15 @@ #ifndef _Geom_Transformation_HeaderFile #define _Geom_Transformation_HeaderFile -#include -#include - #include -#include -#include +#include #include -#include #include -class Standard_ConstructionError; -class Standard_OutOfRange; -class gp_Trsf; -class gp_Pnt; -class gp_Ax1; -class gp_Ax2; -class gp_Ax3; -class gp_Vec; +#include +#include +#include - -class Geom_Transformation; -DEFINE_STANDARD_HANDLE(Geom_Transformation, MMgt_TShared) +DEFINE_STANDARD_HANDLE(Geom_Transformation, Standard_Transient) //! Describes how to construct the following elementary transformations //! - translations, @@ -73,48 +61,41 @@ DEFINE_STANDARD_HANDLE(Geom_Transformation, MMgt_TShared) //! Geom_Transformation transformations are used in //! a context where they can be shared by several //! objects contained inside a common data structure. -class Geom_Transformation : public MMgt_TShared +class Geom_Transformation : public Standard_Transient { - + DEFINE_STANDARD_RTTIEXT(Geom_Transformation, Standard_Transient) public: - //! Creates an identity transformation. Standard_EXPORT Geom_Transformation(); //! Creates a transient copy of T. Standard_EXPORT Geom_Transformation(const gp_Trsf& T); - //! Makes the transformation into a symmetrical transformation //! with respect to a point P. //! P is the center of the symmetry. - Standard_EXPORT void SetMirror (const gp_Pnt& P); - + void SetMirror (const gp_Pnt& thePnt) { gpTrsf.SetMirror (thePnt); } //! Makes the transformation into a symmetrical transformation //! with respect to an axis A1. //! A1 is the center of the axial symmetry. - Standard_EXPORT void SetMirror (const gp_Ax1& A1); - + void SetMirror (const gp_Ax1& theA1) { gpTrsf.SetMirror (theA1); } //! Makes the transformation into a symmetrical transformation //! with respect to a plane. The plane of the symmetry is //! defined with the axis placement A2. It is the plane //! (Location, XDirection, YDirection). - Standard_EXPORT void SetMirror (const gp_Ax2& A2); - + void SetMirror (const gp_Ax2& theA2) { gpTrsf.SetMirror (theA2); } //! Makes the transformation into a rotation. //! A1 is the axis rotation and Ang is the angular value //! of the rotation in radians. - Standard_EXPORT void SetRotation (const gp_Ax1& A1, const Standard_Real Ang); - + void SetRotation (const gp_Ax1& theA1, const Standard_Real theAng) { gpTrsf.SetRotation (theA1, theAng); } //! Makes the transformation into a scale. P is the center of //! the scale and S is the scaling value. - Standard_EXPORT void SetScale (const gp_Pnt& P, const Standard_Real S); - + void SetScale (const gp_Pnt& thePnt, const Standard_Real theScale) { gpTrsf.SetScale (thePnt, theScale); } //! Makes a transformation allowing passage from the coordinate //! system "FromSystem1" to the coordinate system "ToSystem2". @@ -129,8 +110,7 @@ public: //! T.SetTransformation (FromSystem1, ToSystem2); //! gp_Pnt P2 = P1.Transformed (T); //! P2.Coord (x2, y2, z2); - Standard_EXPORT void SetTransformation (const gp_Ax3& FromSystem1, const gp_Ax3& ToSystem2); - + void SetTransformation (const gp_Ax3& theFromSystem1, const gp_Ax3& theToSystem2) { gpTrsf.SetTransformation (theFromSystem1, theToSystem2); } //! Makes the transformation allowing passage from the basic //! coordinate system @@ -138,69 +118,58 @@ public: //! to the local coordinate system defined with the Ax2 ToSystem. //! Same utilisation as the previous method. FromSystem1 is //! defaulted to the absolute coordinate system. - Standard_EXPORT void SetTransformation (const gp_Ax3& ToSystem); - + void SetTransformation (const gp_Ax3& theToSystem) { gpTrsf.SetTransformation (theToSystem); } //! Makes the transformation into a translation. //! V is the vector of the translation. - Standard_EXPORT void SetTranslation (const gp_Vec& V); - + void SetTranslation (const gp_Vec& theVec) { gpTrsf.SetTranslation (theVec); } //! Makes the transformation into a translation from the point //! P1 to the point P2. - Standard_EXPORT void SetTranslation (const gp_Pnt& P1, const gp_Pnt& P2); - + void SetTranslation (const gp_Pnt& P1, const gp_Pnt& P2) { gpTrsf.SetTranslation (P1, P2); } + //! Converts the gp_Trsf transformation T into this transformation. - Standard_EXPORT void SetTrsf (const gp_Trsf& T); + void SetTrsf (const gp_Trsf& theTrsf) { gpTrsf = theTrsf; } //! Checks whether this transformation is an indirect //! transformation: returns true if the determinant of the //! matrix of the vectorial part of the transformation is less than 0. - Standard_EXPORT Standard_Boolean IsNegative() const; + Standard_Boolean IsNegative() const { return gpTrsf.IsNegative(); } //! Returns the nature of this transformation as a value //! of the gp_TrsfForm enumeration. - Standard_EXPORT gp_TrsfForm Form() const; - + gp_TrsfForm Form() const { return gpTrsf.Form(); } + //! Returns the scale value of the transformation. - Standard_EXPORT Standard_Real ScaleFactor() const; - + Standard_Real ScaleFactor() const { return gpTrsf.ScaleFactor(); } //! Returns a non transient copy of . - Standard_EXPORT const gp_Trsf& Trsf() const; - + const gp_Trsf& Trsf() const { return gpTrsf; } - //! Returns the coefficients of the global matrix of tranformation. + //! Returns the coefficients of the global matrix of transformation. //! It is a 3 rows X 4 columns matrix. //! //! Raised if Row < 1 or Row > 3 or Col < 1 or Col > 4 - //! - //! Computes the reverse transformation. - Standard_EXPORT Standard_Real Value (const Standard_Integer Row, const Standard_Integer Col) const; - + Standard_Real Value (const Standard_Integer theRow, const Standard_Integer theCol) const { return gpTrsf.Value (theRow, theCol); } //! Raised if the the transformation is singular. This means that //! the ScaleFactor is lower or equal to Resolution from //! package gp. - Standard_EXPORT void Invert(); - + void Invert() { gpTrsf.Invert(); } //! Raised if the the transformation is singular. This means that //! the ScaleFactor is lower or equal to Resolution from //! package gp. Standard_EXPORT Handle(Geom_Transformation) Inverted() const; - //! Computes the transformation composed with Other and . //! * Other. //! Returns a new transformation Standard_EXPORT Handle(Geom_Transformation) Multiplied (const Handle(Geom_Transformation)& Other) const; - //! Computes the transformation composed with Other and . //! = * Other. - Standard_EXPORT void Multiply (const Handle(Geom_Transformation)& Other); - + void Multiply (const Handle(Geom_Transformation)& theOther) { gpTrsf.Multiply (theOther->Trsf()); } //! Computes the following composition of transformations //! if N > 0 * * .......* . @@ -208,46 +177,25 @@ public: //! if N < 0 .Invert() * .........* .Invert() //! //! Raised if N < 0 and if the transformation is not inversible - Standard_EXPORT void Power (const Standard_Integer N); - + void Power (const Standard_Integer N) { gpTrsf.Power (N); } //! Raised if N < 0 and if the transformation is not inversible Standard_EXPORT Handle(Geom_Transformation) Powered (const Standard_Integer N) const; - //! Computes the matrix of the transformation composed with //! and Other. = Other * Standard_EXPORT void PreMultiply (const Handle(Geom_Transformation)& Other); - //! Applies the transformation to the triplet {X, Y, Z}. - Standard_EXPORT void Transforms (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const; + void Transforms (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const { gpTrsf.Transforms (theX, theY, theZ); } //! Creates a new object which is a copy of this transformation. Standard_EXPORT Handle(Geom_Transformation) Copy() const; - - - - DEFINE_STANDARD_RTTIEXT(Geom_Transformation,MMgt_TShared) - -protected: - - - - private: - gp_Trsf gpTrsf; - }; - - - - - - #endif // _Geom_Transformation_HeaderFile diff --git a/src/Graphic3d/Graphic3d_CStructure.hxx b/src/Graphic3d/Graphic3d_CStructure.hxx index bbfeb655da..973705d200 100644 --- a/src/Graphic3d/Graphic3d_CStructure.hxx +++ b/src/Graphic3d/Graphic3d_CStructure.hxx @@ -24,6 +24,7 @@ #include #include #include +#include class Graphic3d_GraphicDriver; class Graphic3d_StructureManager; @@ -46,6 +47,12 @@ public: return myGroups; } + //! Return transformation. + const Handle(Geom_Transformation)& Transformation() const { return myTrsf; } + + //! Assign transformation. + virtual void SetTransformation (const Handle(Geom_Transformation)& theTrsf) { myTrsf = theTrsf; } + //! Return transformation persistence. const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTrsfPers; } @@ -105,9 +112,6 @@ public: //! Disconnect other structure to this one virtual void Disconnect (Graphic3d_CStructure& theStructure) = 0; - //! Synchronize structure transformation - virtual void UpdateTransformation() = 0; - //! Highlight entire structure with color virtual void HighlightWithColor (const Graphic3d_Vec3& theColor, const Standard_Boolean theToCreate) = 0; @@ -134,8 +138,6 @@ public: Quantity_Color HighlightColor; - Graphic3d_Mat4 Transformation; - int ContainsFacet; Handle(Graphic3d_ViewAffinity) ViewAffinity; //!< view affinity mask @@ -159,6 +161,7 @@ protected: Handle(Graphic3d_GraphicDriver) myGraphicDriver; Graphic3d_SequenceOfGroup myGroups; Graphic3d_BndBox4f myBndBox; + Handle(Geom_Transformation) myTrsf; Handle(Graphic3d_TransformPers) myTrsfPers; Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes; diff --git a/src/Graphic3d/Graphic3d_CView.cxx b/src/Graphic3d/Graphic3d_CView.cxx index 047d5bf3e8..062072ad2d 100644 --- a/src/Graphic3d/Graphic3d_CView.cxx +++ b/src/Graphic3d/Graphic3d_CView.cxx @@ -236,9 +236,7 @@ void Graphic3d_CView::SetComputedMode (const Standard_Boolean theMode) } else { - TColStd_Array2OfReal aTrsf (0, 3, 0, 3); - aStruct->Transform (aTrsf); - Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this); + Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aStruct->Transformation()) : aStruct->Compute (this); aCompStruct->SetHLRValidation (Standard_True); const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME @@ -314,22 +312,11 @@ void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct) } // compute + validation - TColStd_Array2OfReal anIdent (0, 3, 0, 3); - for (Standard_Integer aRow = 0; aRow <= 3; ++aRow) - { - for (Standard_Integer aCol = 0; aCol <= 3; ++aCol) - { - anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0); - } - } - TColStd_Array2OfReal aTrsf (0, 3, 0, 3); - theStruct->Transform (aTrsf); - Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex); Handle(Graphic3d_Structure) aCompStruct = aCompStructOld; - aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE); - theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct) - : theStruct->Compute (this, aCompStruct); + aCompStruct->SetTransformation (Handle(Geom_Transformation)()); + theStruct->IsTransformed() ? theStruct->Compute (this, theStruct->Transformation(), aCompStruct) + : theStruct->Compute (this, aCompStruct); aCompStruct->SetHLRValidation (Standard_True); // of which type will be the computed? @@ -811,24 +798,13 @@ void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure, // Compute + Validation Handle(Graphic3d_Structure) aStruct; - TColStd_Array2OfReal aTrsf (0, 3, 0, 3); - theStructure->Transform (aTrsf); if (anIndex != 0) { - TColStd_Array2OfReal anIdent (0, 3, 0, 3); - for (Standard_Integer ii = 0; ii <= 3; ++ii) - { - for (Standard_Integer jj = 0; jj <= 3; ++jj) - { - anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0); - } - } - aStruct = myStructsComputed.Value (anIndex); - aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE); + aStruct->SetTransformation (Handle(Geom_Transformation)()); if (theStructure->IsTransformed()) { - theStructure->Compute (this, aTrsf, aStruct); + theStructure->Compute (this, theStructure->Transformation(), aStruct); } else { @@ -838,7 +814,7 @@ void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure, else { aStruct = theStructure->IsTransformed() - ? theStructure->Compute (this, aTrsf) + ? theStructure->Compute (this, theStructure->Transformation()) : theStructure->Compute (this); } @@ -952,7 +928,7 @@ void Graphic3d_CView::Highlight (const Handle(Graphic3d_Structure)& theStructure // purpose : // ======================================================================= void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStructure, - const TColStd_Array2OfReal& theTrsf) + const Handle(Geom_Transformation)& theTrsf) { const Standard_Integer anIndex = IsComputed (theStructure); if (anIndex != 0) @@ -961,9 +937,10 @@ void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStruct // trsf is transferred only if it is : // a translation // a scale - if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0 - || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0 - || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0) + if (!theTrsf.IsNull() + && (theTrsf->Form() == gp_Translation + || theTrsf->Form() == gp_Scale + || theTrsf->Form() == gp_CompoundTrsf)) { ReCompute (theStructure); } diff --git a/src/Graphic3d/Graphic3d_CView.hxx b/src/Graphic3d/Graphic3d_CView.hxx index 01f9a7a776..2a539a1485 100644 --- a/src/Graphic3d/Graphic3d_CView.hxx +++ b/src/Graphic3d/Graphic3d_CView.hxx @@ -194,7 +194,7 @@ private: //! Transforms the structure in the view. Standard_EXPORT void SetTransform (const Handle(Graphic3d_Structure)& theStructure, - const TColStd_Array2OfReal& theTrsf); + const Handle(Geom_Transformation)& theTrsf); //! Suppress the highlighting on the structure //! in the view . diff --git a/src/Graphic3d/Graphic3d_Structure.cxx b/src/Graphic3d/Graphic3d_Structure.cxx index 1c51cef632..3d5a487005 100644 --- a/src/Graphic3d/Graphic3d_Structure.cxx +++ b/src/Graphic3d/Graphic3d_Structure.cxx @@ -29,7 +29,6 @@ #include #include #include -#include #include "Graphic3d_Structure.pxx" @@ -410,7 +409,8 @@ Standard_Boolean Graphic3d_Structure::IsVisible() const //============================================================================= Standard_Boolean Graphic3d_Structure::IsTransformed() const { - return !myCStructure->Transformation.IsIdentity(); + return !myCStructure->Transformation().IsNull() + && myCStructure->Transformation()->Form() != gp_Identity; } //============================================================================= @@ -511,7 +511,7 @@ Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d //purpose : //============================================================================= Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , - const TColStd_Array2OfReal& ) + const Handle(Geom_Transformation)& ) { // Implemented by Presentation return this; @@ -532,7 +532,7 @@ void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& //purpose : //============================================================================= void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , - const TColStd_Array2OfReal& , + const Handle(Geom_Transformation)& , Handle(Graphic3d_Structure)& ) { // Implemented by Presentation @@ -942,83 +942,20 @@ void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theTyp //function : SetTransform //purpose : //============================================================================= -void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMatrix, - const Graphic3d_TypeOfComposition theType) +void Graphic3d_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf) { if (IsDeleted()) return; - Standard_Real valuetrsf; - Standard_Real valueoldtrsf; - Standard_Real valuenewtrsf; - TColStd_Array2OfReal aNewTrsf (0, 3, 0, 3); - TColStd_Array2OfReal aMatrix44 (0, 3, 0, 3); - - // Assign the new transformation in an array [0..3][0..3] - // Avoid problems if the user has defined matrix [1..4][1..4] - // or [3..6][-1..2] !! - Standard_Integer lr = theMatrix.LowerRow(); - Standard_Integer ur = theMatrix.UpperRow(); - Standard_Integer lc = theMatrix.LowerCol(); - Standard_Integer uc = theMatrix.UpperCol(); - - if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4)) - { - Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix"); - } - const Standard_Boolean wasTransformed = IsTransformed(); - switch (theType) + + if (!theTrsf.IsNull() + && theTrsf->Trsf().Form() == gp_Identity) { - case Graphic3d_TOC_REPLACE: - { - // Update of CStructure - for (Standard_Integer i = 0; i <= 3; ++i) - { - for (Standard_Integer j = 0; j <= 3; ++j) - { - myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (lr + i, lc + j)); - aNewTrsf (i, j) = theMatrix (lr + i, lc + j); - } - } - break; - } - case Graphic3d_TOC_POSTCONCATENATE: - { - // To simplify management of indices - for (Standard_Integer i = 0; i <= 3; ++i) - { - for (Standard_Integer j = 0; j <= 3; ++j) - { - aMatrix44 (i, j) = theMatrix (lr + i, lc + j); - } - } - - // Calculation of the product of matrices - for (Standard_Integer i = 0; i <= 3; ++i) - { - for (Standard_Integer j = 0; j <= 3; ++j) - { - aNewTrsf (i, j) = 0.0; - for (Standard_Integer k = 0; k <= 3; ++k) - { - valueoldtrsf = myCStructure->Transformation.GetValue (i, k); - valuetrsf = aMatrix44 (k, j); - valuenewtrsf = aNewTrsf (i, j) + valueoldtrsf * valuetrsf; - aNewTrsf (i, j) = valuenewtrsf; - } - } - } - - // Update of CStructure - for (Standard_Integer i = 0; i <= 3; ++i) - { - for (Standard_Integer j = 0; j <= 3; ++j) - { - myCStructure->Transformation.ChangeValue (i, j) = float (aNewTrsf (i, j)); - } - } - break; - } + myCStructure->SetTransformation (Handle(Geom_Transformation)()); + } + else + { + myCStructure->SetTransformation (theTrsf); } // If transformation, no validation of hidden already calculated parts @@ -1027,37 +964,11 @@ void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMat ReCompute(); } - myCStructure->UpdateTransformation(); - myStructureManager->SetTransform (this, aNewTrsf); + myStructureManager->SetTransform (this, theTrsf); Update (true); } -//============================================================================= -//function : Transform -//purpose : -//============================================================================= -void Graphic3d_Structure::Transform (TColStd_Array2OfReal& theMatrix) const -{ - - Standard_Integer lr = theMatrix.LowerRow (); - Standard_Integer ur = theMatrix.UpperRow (); - Standard_Integer lc = theMatrix.LowerCol (); - Standard_Integer uc = theMatrix.UpperCol (); - - if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4)) - Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix"); - - for (Standard_Integer i = 0; i <= 3; ++i) - { - for (Standard_Integer j = 0; j <= 3; ++j) - { - theMatrix (lr + i, lc + j) = myCStructure->Transformation.GetValue (i, j); - } - } -} - - //============================================================================= //function : MinMaxValues //purpose : @@ -1235,10 +1146,12 @@ void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox, aBox = aCombinedBox; if (aBox.IsValid()) { - TColStd_Array2OfReal aTrsf (0, 3, 0, 3); - Transform (aTrsf); - TransformBoundaries (aTrsf, aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(), - aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z()); + if (!myCStructure->Transformation().IsNull()) + { + TransformBoundaries (myCStructure->Transformation()->Trsf(), + aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(), + aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z()); + } // if box is still valid after transformation if (aBox.IsValid()) @@ -1256,73 +1169,29 @@ void Graphic3d_Structure::addTransformed (Graphic3d_BndBox4d& theBox, //function : Transforms //purpose : //============================================================================= -void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf, +void Graphic3d_Structure::Transforms (const gp_Trsf& theTrsf, const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ) { const Standard_Real aRL = RealLast(); const Standard_Real aRF = RealFirst(); + theNewX = theX; + theNewY = theY; + theNewZ = theZ; if ((theX == aRF) || (theY == aRF) || (theZ == aRF) || (theX == aRL) || (theY == aRL) || (theZ == aRL)) { - theNewX = theX; - theNewY = theY; - theNewZ = theZ; - } - else - { - Standard_Real A, B, C, D; - A = theTrsf (0, 0); - B = theTrsf (0, 1); - C = theTrsf (0, 2); - D = theTrsf (0, 3); - theNewX = A * theX + B * theY + C * theZ + D; - A = theTrsf (1, 0); - B = theTrsf (1, 1); - C = theTrsf (1, 2); - D = theTrsf (1, 3); - theNewY = A * theX + B * theY + C * theZ + D; - A = theTrsf (2, 0); - B = theTrsf (2, 1); - C = theTrsf (2, 2); - D = theTrsf (2, 3); - theNewZ = A * theX + B * theY + C * theZ + D; + return; } + + theTrsf.Transforms (theNewX, theNewY, theNewZ); } //============================================================================= //function : Transforms //purpose : //============================================================================= -Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf, - const Graphic3d_Vector& theCoord) -{ - Standard_Real anXYZ[3]; - Graphic3d_Structure::Transforms (theTrsf, - theCoord.X(), theCoord.Y(), theCoord.Z(), - anXYZ[0], anXYZ[1], anXYZ[2]); - return Graphic3d_Vector (anXYZ[0], anXYZ[1], anXYZ[2]); -} - -//============================================================================= -//function : Transforms -//purpose : -//============================================================================= -Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& theTrsf, - const Graphic3d_Vertex& theCoord) -{ - Standard_Real anXYZ[3]; - Graphic3d_Structure::Transforms (theTrsf, - theCoord.X(), theCoord.Y(), theCoord.Z(), - anXYZ[0], anXYZ[1], anXYZ[2]); - return Graphic3d_Vertex (anXYZ[0], anXYZ[1], anXYZ[2]); -} - -//============================================================================= -//function : Transforms -//purpose : -//============================================================================= -void Graphic3d_Structure::TransformBoundaries (const TColStd_Array2OfReal& theTrsf, +void Graphic3d_Structure::TransformBoundaries (const gp_Trsf& theTrsf, Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin, @@ -1461,16 +1330,9 @@ void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod t //function : GraphicTransform //purpose : //============================================================================= -void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& theMatrix) +void Graphic3d_Structure::GraphicTransform (const Handle(Geom_Transformation)& theTrsf) { - for (Standard_Integer i = 0; i <= 3; ++i) - { - for (Standard_Integer j = 0; j <= 3; ++j) - { - myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (i, j)); - } - } - myCStructure->UpdateTransformation(); + myCStructure->SetTransformation (theTrsf); } //============================================================================= diff --git a/src/Graphic3d/Graphic3d_Structure.hxx b/src/Graphic3d/Graphic3d_Structure.hxx index e99a3f6882..655bf3d6ec 100644 --- a/src/Graphic3d/Graphic3d_Structure.hxx +++ b/src/Graphic3d/Graphic3d_Structure.hxx @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -200,14 +199,17 @@ public: Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& aProjector); //! Returns the new Structure defined for the new visualization - Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, const TColStd_Array2OfReal& AMatrix); + Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, + const Handle(Geom_Transformation)& theTrsf); //! Returns the new Structure defined for the new visualization Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, Handle(Graphic3d_Structure)& aStructure); //! Returns the new Structure defined for the new visualization - Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, const TColStd_Array2OfReal& AMatrix, Handle(Graphic3d_Structure)& aStructure); - + Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, + const Handle(Geom_Transformation)& theTrsf, + Handle(Graphic3d_Structure)& theStructure); + //! Forces a new construction of the structure //! if is displayed and TOS_COMPUTED. Standard_EXPORT void ReCompute(); @@ -330,53 +332,14 @@ public: Standard_EXPORT Standard_Boolean HLRValidation() const; - //! Modifies the current local modelling transformation - //! in the structure . - //! - //! It is defined as a 4*4 real matrix. - //! - //! ------------------- - //! | a11 a12 a13 t1 | - //! | a21 a22 a23 t2 | - //! | a31 a32 a33 t3 | - //! | 0 0 0 1 | - //! ------------------- - //! - //! TypeOfComposition : TOC_REPLACE - //! TOC_POSTCONCATENATE - //! - //! Then the modified Local Modelling Transformation is composed - //! with the current Global Modelling Transformation to create a - //! new Composite Modelling Transformation. - //! - //! The compose type specifies the role of the current local - //! modelling transformation (L) in composing the new value for - //! the current local modelling transformation (L'), which is - //! then combined with the current global modelling transforma- - //! tion (G) to calculate the new composite modelling transfor- - //! mation (C). - //! - //! TOC_REPLACE - //! The transformation matrix (T) replaces the value of - //! current local modelling transformation (L). - //! - //! L' <- T - //! C <- G x L' - //! - //! TOC_POSTCONCATENATE - //! The current local modelling transformation (L) is multiplied - //! by the transformation matrix (T): - //! - //! L' <- T x L - //! C <- G x L' - //! - //! Category: Methods to manage the structure transformation - //! Warning: Raises TransformError if the matrix is not a 4x4 matrix. - Standard_EXPORT void SetTransform (const TColStd_Array2OfReal& AMatrix, const Graphic3d_TypeOfComposition AType); - - //! Returns the transformation associated with - //! the structure . - Standard_EXPORT void Transform (TColStd_Array2OfReal& AMatrix) const; + //! Return local transformation. + const Handle(Geom_Transformation)& Transformation() const { return myCStructure->Transformation(); } + + //! Modifies the current local transformation + Standard_EXPORT void SetTransformation (const Handle(Geom_Transformation)& theTrsf); + + Standard_DEPRECATED("This method is deprecated - SetTransformation() should be called instead") + void Transform (const Handle(Geom_Transformation)& theTrsf) { SetTransformation (theTrsf); } //! Modifies the current transform persistence (pan, zoom or rotate) Standard_EXPORT void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers); @@ -403,7 +366,8 @@ public: //! Highlights the structure . Standard_EXPORT void GraphicHighlight (const Aspect_TypeOfHighlightMethod Method); - Standard_EXPORT void GraphicTransform (const TColStd_Array2OfReal& AMatrix); + //! Internal method which sets new transformation without calling graphic manager callbacks. + Standard_EXPORT void GraphicTransform (const Handle(Geom_Transformation)& theTrsf); //! Suppress the highlight for the structure . Standard_EXPORT void GraphicUnHighlight(); @@ -421,15 +385,11 @@ public: Standard_EXPORT void SetComputeVisual (const Graphic3d_TypeOfStructure AVisual); - //! Transforms , , with the transformation . - Standard_EXPORT static void Transforms (const TColStd_Array2OfReal& ATrsf, const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real& NewX, Standard_Real& NewY, Standard_Real& NewZ); - - //! Transforms with the transformation . - Standard_EXPORT static Graphic3d_Vector Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vector& Coord); - - //! Transforms with the transformation . - Standard_EXPORT static Graphic3d_Vertex Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vertex& Coord); - + //! Transforms theX, theY, theZ with the transformation theTrsf. + Standard_EXPORT static void Transforms (const gp_Trsf& theTrsf, + const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, + Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ); + //! Returns the low-level structure const Handle(Graphic3d_CStructure)& CStructure() const { return myCStructure; } @@ -441,8 +401,10 @@ friend class Graphic3d_Group; protected: //! Transforms boundaries with transformation. - Standard_EXPORT static void TransformBoundaries (const TColStd_Array2OfReal& theTrsf, Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin, Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax); - + Standard_EXPORT static void TransformBoundaries (const gp_Trsf& theTrsf, + Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin, + Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax); + //! Appends new descendant structure. Standard_EXPORT Standard_Boolean AppendDescendant (const Standard_Address theDescendant); diff --git a/src/Graphic3d/Graphic3d_StructureManager.cxx b/src/Graphic3d/Graphic3d_StructureManager.cxx index 72e0584665..8e7373f769 100644 --- a/src/Graphic3d/Graphic3d_StructureManager.cxx +++ b/src/Graphic3d/Graphic3d_StructureManager.cxx @@ -399,7 +399,7 @@ void Graphic3d_StructureManager::UnHighlight() // purpose : // ======================================================================== void Graphic3d_StructureManager::SetTransform (const Handle(Graphic3d_Structure)& theStructure, - const TColStd_Array2OfReal& theTrsf) + const Handle(Geom_Transformation)& theTrsf) { for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) { diff --git a/src/Graphic3d/Graphic3d_StructureManager.hxx b/src/Graphic3d/Graphic3d_StructureManager.hxx index 5253e86ed4..35fd6a7f6a 100644 --- a/src/Graphic3d/Graphic3d_StructureManager.hxx +++ b/src/Graphic3d/Graphic3d_StructureManager.hxx @@ -133,7 +133,7 @@ public: Standard_EXPORT virtual void Highlight (const Handle(Graphic3d_Structure)& theStructure, const Aspect_TypeOfHighlightMethod theMethod); //! Transforms the structure. - Standard_EXPORT virtual void SetTransform (const Handle(Graphic3d_Structure)& theStructure, const TColStd_Array2OfReal& theTrsf); + Standard_EXPORT virtual void SetTransform (const Handle(Graphic3d_Structure)& theStructure, const Handle(Geom_Transformation)& theTrsf); //! Changes the display priority of the structure . Standard_EXPORT virtual void ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure, const Standard_Integer theOldPriority, const Standard_Integer theNewPriority); diff --git a/src/OpenGl/OpenGl_MatrixState.hxx b/src/OpenGl/OpenGl_MatrixState.hxx index 9e67144a92..00f16d0d09 100644 --- a/src/OpenGl/OpenGl_MatrixState.hxx +++ b/src/OpenGl/OpenGl_MatrixState.hxx @@ -65,6 +65,12 @@ public: myCurrent = theNewCurrent; } + //! Change current matrix. + typename OpenGl::MatrixType::Mat4& ChangeCurrent() + { + return myCurrent; + } + //! Sets given matrix as current. template void SetCurrent (const typename OpenGl::MatrixType::Mat4& theNewCurrent) diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index 0921824a92..75a0ac29e1 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -139,19 +139,21 @@ OpenGl_Structure::~OpenGl_Structure() } // ======================================================================= -// function : UpdateTransformation +// function : SetTransformation // purpose : // ======================================================================= -void OpenGl_Structure::UpdateTransformation() +void OpenGl_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf) { - const OpenGl_Mat4& aMat = Graphic3d_CStructure::Transformation; - Standard_ShortReal aDet = - aMat.GetValue(0, 0) * (aMat.GetValue(1, 1) * aMat.GetValue(2, 2) - aMat.GetValue(2, 1) * aMat.GetValue(1, 2)) - - aMat.GetValue(0, 1) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 2) - aMat.GetValue(2, 0) * aMat.GetValue(1, 2)) + - aMat.GetValue(0, 2) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 1) - aMat.GetValue(2, 0) * aMat.GetValue(1, 1)); - - // Determinant of transform matrix less then 0 means that mirror transform applied. - myIsMirrored = aDet < 0.0f; + myTrsf = theTrsf; + myIsMirrored = Standard_False; + if (!myTrsf.IsNull()) + { + // Determinant of transform matrix less then 0 means that mirror transform applied. + const Standard_Real aDet = myTrsf->Value(1, 1) * (myTrsf->Value (2, 2) * myTrsf->Value (3, 3) - myTrsf->Value (3, 2) * myTrsf->Value (2, 3)) + - myTrsf->Value(1, 2) * (myTrsf->Value (2, 1) * myTrsf->Value (3, 3) - myTrsf->Value (3, 1) * myTrsf->Value (2, 3)) + + myTrsf->Value(1, 3) * (myTrsf->Value (2, 1) * myTrsf->Value (3, 2) - myTrsf->Value (3, 1) * myTrsf->Value (2, 2)); + myIsMirrored = aDet < 0.0; + } if (IsRaytracable()) { @@ -455,16 +457,25 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con // Apply local transformation aCtx->ModelWorldState.Push(); - aCtx->ModelWorldState.SetCurrent (Transformation); + OpenGl_Mat4& aModelWorld = aCtx->ModelWorldState.ChangeCurrent(); + if (!myTrsf.IsNull()) + { + myTrsf->Trsf().GetMat4 (aModelWorld); + } + else + { + aModelWorld.InitIdentity(); + } const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled(); #if !defined(GL_ES_VERSION_2_0) // detect scale transform - if (aCtx->core11 != NULL) + if (aCtx->core11 != NULL + && !myTrsf.IsNull()) { - const Standard_ShortReal aScaleX = Transformation.GetRow (0).xyz().SquareModulus(); - if (Abs (aScaleX - 1.f) > Precision::Confusion()) + const Standard_Real aScale = myTrsf->ScaleFactor(); + if (Abs (aScale - 1.0) > Precision::Confusion()) { aCtx->SetGlNormalizeEnabled (Standard_True); } diff --git a/src/OpenGl/OpenGl_Structure.hxx b/src/OpenGl/OpenGl_Structure.hxx index ed82a470c5..6d30b8c6b7 100644 --- a/src/OpenGl/OpenGl_Structure.hxx +++ b/src/OpenGl/OpenGl_Structure.hxx @@ -78,7 +78,7 @@ public: Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE; //! Synchronize structure transformation - Standard_EXPORT virtual void UpdateTransformation() Standard_OVERRIDE; + Standard_EXPORT virtual void SetTransformation (const Handle(Geom_Transformation)& theTrsf) Standard_OVERRIDE; //! Highlight entire structure with color Standard_EXPORT virtual void HighlightWithColor (const Graphic3d_Vec3& theColor, diff --git a/src/OpenGl/OpenGl_StructureShadow.cxx b/src/OpenGl/OpenGl_StructureShadow.cxx index b17b4442a6..b89d0cca90 100644 --- a/src/OpenGl/OpenGl_StructureShadow.cxx +++ b/src/OpenGl/OpenGl_StructureShadow.cxx @@ -33,10 +33,9 @@ OpenGl_StructureShadow::OpenGl_StructureShadow (const Handle(Graphic3d_Structure ContainsFacet = myParent->ContainsFacet; IsInfinite = myParent->IsInfinite; - Transformation = myParent->Transformation; - myBndBox = myParent->BoundingBox(); + myBndBox = myParent->BoundingBox(); - UpdateTransformation(); + OpenGl_Structure::SetTransformation (myParent->Transformation()); myInstancedStructure = const_cast (myParent->InstancedStructure()); myTrsfPers = myParent->TransformPersistence(); diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index 49f4d32144..514ae9313f 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -760,7 +760,7 @@ protected: //! @name methods related to ray-tracing //! Adds OpenGL groups to ray-traced scene geometry. Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure, const OpenGl_RaytraceMaterial& theStructMat, - const Graphic3d_Mat4* theTransform, + const Handle(Geom_Transformation)& theTrsf, const Handle(OpenGl_Context)& theGlContext); //! Creates ray-tracing material properties. diff --git a/src/OpenGl/OpenGl_View_Raytrace.cxx b/src/OpenGl/OpenGl_View_Raytrace.cxx index 551a0035d7..03f6f8de67 100644 --- a/src/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/OpenGl/OpenGl_View_Raytrace.cxx @@ -433,14 +433,14 @@ Standard_Boolean OpenGl_View::addRaytraceStructure (const OpenGl_Structure* // Get structure material OpenGl_RaytraceMaterial aDefaultMaterial; - Standard_Boolean aResult = addRaytraceGroups (theStructure, aDefaultMaterial, &theStructure->Transformation, theGlContext); + Standard_Boolean aResult = addRaytraceGroups (theStructure, aDefaultMaterial, theStructure->Transformation(), theGlContext); // Process all connected OpenGL structures const OpenGl_Structure* anInstanced = theStructure->InstancedStructure(); if (anInstanced != NULL && anInstanced->IsRaytracable()) { - aResult &= addRaytraceGroups (anInstanced, aDefaultMaterial, &theStructure->Transformation, theGlContext); + aResult &= addRaytraceGroups (anInstanced, aDefaultMaterial, theStructure->Transformation(), theGlContext); } myStructureStates[theStructure] = StructState (theStructure); @@ -454,9 +454,10 @@ Standard_Boolean OpenGl_View::addRaytraceStructure (const OpenGl_Structure* // ======================================================================= Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* theStructure, const OpenGl_RaytraceMaterial& theStructMat, - const Graphic3d_Mat4* theTransform, + const Handle(Geom_Transformation)& theTrsf, const Handle(OpenGl_Context)& theGlContext) { + OpenGl_Mat4 aMat4; for (OpenGl_Structure::GroupIterator aGroupIter (theStructure->Groups()); aGroupIter.More(); aGroupIter.Next()) { // Get group material @@ -500,9 +501,10 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* BVH_Transform* aTransform = new BVH_Transform(); - if (theTransform != NULL) + if (!theTrsf.IsNull()) { - aTransform->SetTransform (*theTransform); + theTrsf->Trsf().GetMat4 (aMat4); + aTransform->SetTransform (aMat4); } aSet->SetProperties (aTransform); @@ -521,9 +523,10 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* { BVH_Transform* aTransform = new BVH_Transform; - if (theTransform != NULL) + if (!theTrsf.IsNull()) { - aTransform->SetTransform (*theTransform); + theTrsf->Trsf().GetMat4 (aMat4); + aTransform->SetTransform (aMat4); } aSet->SetProperties (aTransform); diff --git a/src/Prs3d/Prs3d_Presentation.cxx b/src/Prs3d/Prs3d_Presentation.cxx index b9f79fd7c4..f3796a5387 100644 --- a/src/Prs3d/Prs3d_Presentation.cxx +++ b/src/Prs3d/Prs3d_Presentation.cxx @@ -28,25 +28,9 @@ #include #include #include -#include IMPLEMENT_STANDARD_RTTIEXT(Prs3d_Presentation,Graphic3d_Structure) -// OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets -// OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets -static void MakeGraphicTrsf (const Handle(Geom_Transformation)& aGeomTrsf, - TColStd_Array2OfReal& Array){ - for (Standard_Integer i=1; i<=3; i++){ - for (Standard_Integer j=1; j<=4; j++){ - Array.SetValue(i,j,aGeomTrsf->Value(i,j)); - } - } - Array.SetValue(4,1,0.); - Array.SetValue(4,2,0.); - Array.SetValue(4,3,0.); - Array.SetValue(4,4,1.); -} - //======================================================================= //function : Prs3d_Presentation //purpose : @@ -72,78 +56,6 @@ Prs3d_Presentation::Prs3d_Presentation (const Handle(Graphic3d_StructureManager) // } -//======================================================================= -//function : Transform -//purpose : -//======================================================================= - -void Prs3d_Presentation::Transform(const Handle(Geom_Transformation)& aTransformation) -{ - TColStd_Array2OfReal Array (1,4,1,4); - MakeGraphicTrsf(aTransformation, Array); - SetTransform(Array, Graphic3d_TOC_REPLACE); -} - -//======================================================================= -//function : Transformation -//purpose : -//======================================================================= - -Handle(Geom_Transformation) Prs3d_Presentation::Transformation() const { -TColStd_Array2OfReal matrix(1,4,1,4); - - Graphic3d_Structure::Transform(matrix); - - gp_Trsf trsf; - trsf.SetValues( - matrix.Value(1,1),matrix.Value(1,2),matrix.Value(1,3),matrix.Value(1,4), - matrix.Value(2,1),matrix.Value(2,2),matrix.Value(2,3),matrix.Value(2,4), - matrix.Value(3,1),matrix.Value(3,2),matrix.Value(3,3),matrix.Value(3,4)); - Handle(Geom_Transformation) gtrsf = new Geom_Transformation(trsf); - - return gtrsf; -} - -//======================================================================= -//function : Place -//purpose : -//======================================================================= -void Prs3d_Presentation::Place (const Quantity_Length X, - const Quantity_Length Y, - const Quantity_Length Z) -{ - Handle(Geom_Transformation) aTransformation = new Geom_Transformation; - aTransformation->SetTranslation(gp_Vec(X,Y,Z)); - TColStd_Array2OfReal Array (1,4,1,4); - MakeGraphicTrsf(aTransformation, Array); - SetTransform(Array, Graphic3d_TOC_REPLACE); -} - -//======================================================================= -//function : Multiply -//purpose : -//======================================================================= -void Prs3d_Presentation::Multiply(const Handle(Geom_Transformation)& aTransformation) -{ - TColStd_Array2OfReal Array (1,4,1,4); - MakeGraphicTrsf(aTransformation, Array); - SetTransform(Array, Graphic3d_TOC_POSTCONCATENATE); -} - -//======================================================================= -//function : Move -//purpose : -//======================================================================= -void Prs3d_Presentation::Move (const Quantity_Length X, - const Quantity_Length Y, - const Quantity_Length Z) -{ - Handle(Geom_Transformation) aTransformation = new Geom_Transformation; - aTransformation->SetTranslation(gp_Vec(X,Y,Z)); - TColStd_Array2OfReal Array (1,4,1,4); - MakeGraphicTrsf(aTransformation, Array); - SetTransform(Array, Graphic3d_TOC_POSTCONCATENATE); -} //======================================================================= //function : Connect @@ -212,23 +124,23 @@ void Prs3d_Presentation::Compute(const Handle(Graphic3d_DataStructureManager)& a //======================================================================= //function : Compute -//purpose : +//purpose : //======================================================================= -Handle(Graphic3d_Structure) Prs3d_Presentation::Compute(const Handle(Graphic3d_DataStructureManager)& aDataStruc, - const TColStd_Array2OfReal& anArray) +Handle(Graphic3d_Structure) Prs3d_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theDataStruc, + const Handle(Geom_Transformation)& theTrsf) { - return Graphic3d_Structure::Compute(aDataStruc,anArray); + return Graphic3d_Structure::Compute (theDataStruc, theTrsf); } //======================================================================= //function : Compute -//purpose : +//purpose : //======================================================================= -void Prs3d_Presentation::Compute(const Handle(Graphic3d_DataStructureManager)& aDataStruc, - const TColStd_Array2OfReal& anArray, - Handle(Graphic3d_Structure)& aStruc) +void Prs3d_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theDataStruc, + const Handle(Geom_Transformation)& theTrsf, + Handle(Graphic3d_Structure)& theStruc) { - Graphic3d_Structure::Compute(aDataStruc,anArray,aStruc); + Graphic3d_Structure::Compute (theDataStruc, theTrsf, theStruc); } diff --git a/src/Prs3d/Prs3d_Presentation.hxx b/src/Prs3d/Prs3d_Presentation.hxx index ba12c7a59d..a09ea2d6a2 100644 --- a/src/Prs3d/Prs3d_Presentation.hxx +++ b/src/Prs3d/Prs3d_Presentation.hxx @@ -22,7 +22,6 @@ #include #include -#include #include class Prs3d_Root; class Graphic3d_StructureManager; @@ -49,7 +48,6 @@ class Prs3d_Presentation : public Graphic3d_Structure public: - //! Constructs a presentation object //! if is false, no color initialization is done. Standard_EXPORT Prs3d_Presentation(const Handle(Graphic3d_StructureManager)& theStructManager, const Standard_Boolean theToInit = Standard_True); @@ -60,54 +58,31 @@ public: Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& aProjector) Standard_OVERRIDE; //! Returns the new Structure defined for the new visualization - Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, const TColStd_Array2OfReal& AMatrix) Standard_OVERRIDE; - + Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, + const Handle(Geom_Transformation)& theTrsf) Standard_OVERRIDE; + //! Returns the new Structure defined for the new visualization Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, Handle(Graphic3d_Structure)& aStructure) Standard_OVERRIDE; //! Returns the new Structure defined for the new visualization - Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, const TColStd_Array2OfReal& AMatrix, Handle(Graphic3d_Structure)& aStructure) Standard_OVERRIDE; + Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, + const Handle(Geom_Transformation)& theTrsf, + Handle(Graphic3d_Structure)& theStructure) Standard_OVERRIDE; - Standard_EXPORT void Transform (const Handle(Geom_Transformation)& aTransformation); - - Standard_EXPORT void Place (const Quantity_Length X, const Quantity_Length Y, const Quantity_Length Z); - - Standard_EXPORT void Multiply (const Handle(Geom_Transformation)& aTransformation); - - Standard_EXPORT void Move (const Quantity_Length X, const Quantity_Length Y, const Quantity_Length Z); - - Standard_EXPORT Handle(Geom_Transformation) Transformation() const; - Standard_EXPORT void Connect (const Handle(Prs3d_Presentation)& aPresentation); Standard_EXPORT void Remove (const Handle(Prs3d_Presentation)& aPresentation); Standard_EXPORT void RemoveAll(); - friend class Prs3d_Root; - DEFINE_STANDARD_RTTIEXT(Prs3d_Presentation,Graphic3d_Structure) -protected: - - - - private: - Standard_EXPORT Handle(Graphic3d_Group) CurrentGroup() const; - - }; - - - - - - #endif // _Prs3d_Presentation_HeaderFile diff --git a/src/PrsMgr/PrsMgr_ListOfPresentableObjects.hxx b/src/PrsMgr/PrsMgr_ListOfPresentableObjects.hxx index 873aec42e2..13d2ca5638 100644 --- a/src/PrsMgr/PrsMgr_ListOfPresentableObjects.hxx +++ b/src/PrsMgr/PrsMgr_ListOfPresentableObjects.hxx @@ -16,11 +16,11 @@ #ifndef _PrsMgr_ListOfPresentableObjects_HeaderFile #define _PrsMgr_ListOfPresentableObjects_HeaderFile -#include #include +#include +class PrsMgr_PresentableObject; // use forward declaration since PrsMgr_PresentableObject.hxx uses PrsMgr_ListOfPresentableObjects typedef NCollection_List PrsMgr_ListOfPresentableObjects; typedef NCollection_List::Iterator PrsMgr_ListOfPresentableObjectsIter; - #endif // _PrsMgr_ListOfPresentableObjects_HeaderFile diff --git a/src/PrsMgr/PrsMgr_PresentableObject.cxx b/src/PrsMgr/PrsMgr_PresentableObject.cxx index ca7a5ec7fc..bb2ee098ee 100644 --- a/src/PrsMgr/PrsMgr_PresentableObject.cxx +++ b/src/PrsMgr/PrsMgr_PresentableObject.cxx @@ -16,24 +16,29 @@ #include -#include -#include -#include -#include -#include -#include #include #include #include -#include -#include #include -#include #include #include IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentableObject,MMgt_TShared) +namespace +{ + static const gp_Trsf THE_IDENTITY_TRSF; +} + +//======================================================================= +//function : getIdentityTrsf +//purpose : +//======================================================================= +const gp_Trsf& PrsMgr_PresentableObject::getIdentityTrsf() +{ + return THE_IDENTITY_TRSF; +} + //======================================================================= //function : PrsMgr_PresentableObject //purpose : @@ -54,10 +59,9 @@ PrsMgr_PresentableObject::PrsMgr_PresentableObject (const PrsMgr_TypeOfPresentat //======================================================================= PrsMgr_PresentableObject::~PrsMgr_PresentableObject() { - gp_Trsf anIdentity; for (PrsMgr_ListOfPresentableObjectsIter anIter (myChildren); anIter.More(); anIter.Next()) { - anIter.Value()->SetCombinedParentTransform (anIdentity); + anIter.Value()->SetCombinedParentTransform (Handle(Geom_Transformation)()); anIter.Value()->myParent = NULL; } } @@ -164,23 +168,6 @@ void PrsMgr_PresentableObject::Update (const Standard_Integer aMode, const Stand } -//======================================================================= -//function : Presentations -//purpose : -//======================================================================= -PrsMgr_Presentations& PrsMgr_PresentableObject::Presentations() { - return myPresentations; -} - -//======================================================================= -//function : HasTransformation -//purpose : -//======================================================================= -Standard_Boolean PrsMgr_PresentableObject::HasTransformation() const -{ - return myTransformation.Form() != gp_Identity; -} - //======================================================================= //function : SetToUpdate //purpose : @@ -241,10 +228,10 @@ void PrsMgr_PresentableObject::SetTypeOfPresentation (const PrsMgr_TypeOfPresent } //======================================================================= -//function : SetLocalTransformation -//purpose : WARNING : use with only 3D objects... +//function : setLocalTransformation +//purpose : //======================================================================= -void PrsMgr_PresentableObject::SetLocalTransformation (const gp_Trsf& theTransformation) +void PrsMgr_PresentableObject::setLocalTransformation (const Handle(Geom_Transformation)& theTransformation) { myLocalTransformation = theTransformation; UpdateTransformation(); @@ -256,16 +243,16 @@ void PrsMgr_PresentableObject::SetLocalTransformation (const gp_Trsf& theTransfo //======================================================================= void PrsMgr_PresentableObject::ResetTransformation() { - SetLocalTransformation (gp_Trsf()); + setLocalTransformation (Handle(Geom_Transformation)()); } //======================================================================= //function : SetCombinedParentTransform //purpose : //======================================================================= -void PrsMgr_PresentableObject::SetCombinedParentTransform (const gp_Trsf& theTransformation) +void PrsMgr_PresentableObject::SetCombinedParentTransform (const Handle(Geom_Transformation)& theTrsf) { - myCombinedParentTransform = theTransformation; + myCombinedParentTransform = theTrsf; UpdateTransformation(); } @@ -275,20 +262,36 @@ void PrsMgr_PresentableObject::SetCombinedParentTransform (const gp_Trsf& theTra //======================================================================= void PrsMgr_PresentableObject::UpdateTransformation() { - myTransformation = myCombinedParentTransform * myLocalTransformation; - myInvTransformation = myTransformation.Inverted(); - Handle(Geom_Transformation) aTrsf = new Geom_Transformation (myTransformation); + myTransformation.Nullify(); + myInvTransformation = gp_Trsf(); + if (!myCombinedParentTransform.IsNull() && myCombinedParentTransform->Form() != gp_Identity) + { + if (!myLocalTransformation.IsNull() && myLocalTransformation->Form() != gp_Identity) + { + const gp_Trsf aTrsf = myCombinedParentTransform->Trsf() * myLocalTransformation->Trsf(); + myTransformation = new Geom_Transformation (aTrsf); + myInvTransformation = aTrsf.Inverted(); + } + else + { + myTransformation = myCombinedParentTransform; + myInvTransformation = myCombinedParentTransform->Trsf().Inverted(); + } + } + else if (!myLocalTransformation.IsNull() && myLocalTransformation->Form() != gp_Identity) + { + myTransformation = myLocalTransformation; + myInvTransformation = myLocalTransformation->Trsf().Inverted(); + } for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter) { - myPresentations (aPrsIter).Presentation()->Transform (aTrsf); + myPresentations (aPrsIter).Presentation()->SetTransformation (myTransformation); } - - PrsMgr_ListOfPresentableObjectsIter anIter (myChildren); - for (; anIter.More(); anIter.Next()) + for (PrsMgr_ListOfPresentableObjectsIter aChildIter (myChildren); aChildIter.More(); aChildIter.Next()) { - anIter.Value()->SetCombinedParentTransform (myTransformation); + aChildIter.Value()->SetCombinedParentTransform (myTransformation); } } @@ -298,8 +301,7 @@ void PrsMgr_PresentableObject::UpdateTransformation() //======================================================================= void PrsMgr_PresentableObject::UpdateTransformation(const Handle(Prs3d_Presentation)& P) { - Handle(Geom_Transformation) aTrsf = new Geom_Transformation (myTransformation); - P->Transform (aTrsf); + P->SetTransformation (myTransformation); } //======================================================================= @@ -392,7 +394,7 @@ void PrsMgr_PresentableObject::RemoveChild (const Handle(PrsMgr_PresentableObjec if (anIter.Value() == theObject) { theObject->myParent = NULL; - theObject->SetCombinedParentTransform (gp_Trsf()); + theObject->SetCombinedParentTransform (Handle(Geom_Transformation)()); myChildren.Remove (anIter); break; } diff --git a/src/PrsMgr/PrsMgr_PresentableObject.hxx b/src/PrsMgr/PrsMgr_PresentableObject.hxx index da8466f223..71d3fad6e8 100644 --- a/src/PrsMgr/PrsMgr_PresentableObject.hxx +++ b/src/PrsMgr/PrsMgr_PresentableObject.hxx @@ -17,40 +17,19 @@ #ifndef _PrsMgr_PresentableObject_HeaderFile #define _PrsMgr_PresentableObject_HeaderFile -#include -#include - -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include +#include +#include #include #include +#include +#include +#include +#include +#include +#include +#include #include -#include -class Standard_NotImplemented; -class PrsMgr_Presentation; -class PrsMgr_PresentationManager; -class Graphic3d_Structure; -class Graphic3d_DataStructureManager; -class Geom_Transformation; -class Prs3d_Presentation; -class Prs3d_Projector; -class gp_Pnt; -class gp_Trsf; - - -class PrsMgr_PresentableObject; -DEFINE_STANDARD_HANDLE(PrsMgr_PresentableObject, MMgt_TShared) //! A framework to supply the Graphic3d //! structure of the object to be presented. On the first @@ -69,11 +48,10 @@ DEFINE_STANDARD_HANDLE(PrsMgr_PresentableObject, MMgt_TShared) //! creation of new interactive objects. class PrsMgr_PresentableObject : public MMgt_TShared { - + DEFINE_STANDARD_RTTIEXT(PrsMgr_PresentableObject, MMgt_TShared) public: - - Standard_EXPORT PrsMgr_Presentations& Presentations(); + PrsMgr_Presentations& Presentations() { return myPresentations; } //! Returns information on whether the object accepts display in HLR mode or not. PrsMgr_TypeOfPresentation3d TypeOfPresentation3d() const { return myTypeOfPresentation3d; } @@ -132,15 +110,30 @@ public: //! gives the list of modes which are flagged "to be updated". Standard_EXPORT void ToBeUpdated (TColStd_ListOfInteger& ListOfMode) const; + //! Return the local transformation. + const Handle(Geom_Transformation)& LocalTransformationGeom() const { return myLocalTransformation; } + //! Sets local transformation to theTransformation. - Standard_EXPORT virtual void SetLocalTransformation (const gp_Trsf& theTransformation); - + void SetLocalTransformation (const gp_Trsf& theTrsf) { setLocalTransformation (new Geom_Transformation (theTrsf)); } + + //! Sets local transformation to theTransformation. + void SetLocalTransformation (const Handle(Geom_Transformation)& theTrsf) { setLocalTransformation (theTrsf); } + //! Returns true if object has a transformation that is different from the identity. - Standard_EXPORT Standard_Boolean HasTransformation() const; + Standard_Boolean HasTransformation() const { return !myTransformation.IsNull() && myTransformation->Form() != gp_Identity; } - const gp_Trsf& LocalTransformation() const { return myLocalTransformation; } + //! Return the transformation taking into account transformation of parent object(s). + const Handle(Geom_Transformation)& TransformationGeom() const { return myTransformation; } - const gp_Trsf& Transformation() const { return myTransformation; } + //! Return the local transformation. + const gp_Trsf& LocalTransformation() const { return !myLocalTransformation.IsNull() + ? myLocalTransformation->Trsf() + : getIdentityTrsf(); } + + //! Return the transformation taking into account transformation of parent object(s). + const gp_Trsf& Transformation() const { return !myTransformation.IsNull() + ? myTransformation->Trsf() + : getIdentityTrsf(); } const gp_GTrsf& InversedTransformation() const { return myInvTransformation; } @@ -227,9 +220,6 @@ friend friend Standard_EXPORT void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, const Handle(Geom_Transformation)& theTrsf, const Handle(Graphic3d_Structure)& theGivenStruct); - - DEFINE_STANDARD_RTTIEXT(PrsMgr_PresentableObject,MMgt_TShared) - protected: @@ -282,13 +272,21 @@ Standard_EXPORT virtual ~PrsMgr_PresentableObject(); //! Sets myCombinedParentTransform to theTransformation. Thus object receives transformation //! from parent node and able to derive its own. - Standard_EXPORT virtual void SetCombinedParentTransform (const gp_Trsf& theTransformation); + Standard_EXPORT virtual void SetCombinedParentTransform (const Handle(Geom_Transformation)& theTrsf); //! General virtual method for internal update of presentation state //! when some modifications on list of clip planes occurs. Base //! implementation propagate clip planes to every presentation. Standard_EXPORT virtual void UpdateClipping(); + //! Sets local transformation to theTransformation. + Standard_EXPORT virtual void setLocalTransformation (const Handle(Geom_Transformation)& theTransformation); + +private: + + //! Return the identity transformation. + Standard_EXPORT static const gp_Trsf& getIdentityTrsf(); + protected: PrsMgr_Presentations myPresentations; @@ -302,12 +300,14 @@ private: Handle(Graphic3d_TransformPers) myTransformPersistence; PrsMgr_PresentableObjectPointer myParent; - gp_Trsf myLocalTransformation; - gp_Trsf myTransformation; + Handle(Geom_Transformation) myLocalTransformation; + Handle(Geom_Transformation) myTransformation; + Handle(Geom_Transformation) myCombinedParentTransform; gp_GTrsf myInvTransformation; - gp_Trsf myCombinedParentTransform; PrsMgr_ListOfPresentableObjects myChildren; }; +DEFINE_STANDARD_HANDLE(PrsMgr_PresentableObject, MMgt_TShared) + #endif // _PrsMgr_PresentableObject_HeaderFile diff --git a/src/PrsMgr/PrsMgr_Presentation.cxx b/src/PrsMgr/PrsMgr_Presentation.cxx index bef70f2268..d6ca61cb18 100644 --- a/src/PrsMgr/PrsMgr_Presentation.cxx +++ b/src/PrsMgr/PrsMgr_Presentation.cxx @@ -226,43 +226,12 @@ void PrsMgr_Presentation::Connect (const Handle(PrsMgr_Presentation)& theOther) } //======================================================================= -//function : Transform +//function : SetTransformation //purpose : //======================================================================= -void PrsMgr_Presentation::Transform (const Handle(Geom_Transformation)& theTrsf) const +void PrsMgr_Presentation::SetTransformation (const Handle(Geom_Transformation)& theTrsf) const { - myStructure->Transform (theTrsf); -} - -//======================================================================= -//function : Place -//purpose : -//======================================================================= -void PrsMgr_Presentation::Place (const Quantity_Length theX, - const Quantity_Length theY, - const Quantity_Length theZ) const -{ - myStructure->Place (theX, theY, theZ); -} - -//======================================================================= -//function : Multiply -//purpose : -//======================================================================= -void PrsMgr_Presentation::Multiply (const Handle(Geom_Transformation)& theTrsf) const -{ - myStructure->Multiply (theTrsf); -} - -//======================================================================= -//function : Move -//purpose : -//======================================================================= -void PrsMgr_Presentation::Move (const Quantity_Length theX, - const Quantity_Length theY, - const Quantity_Length theZ) const -{ - myStructure->Move (theX, theY, theZ); + myStructure->SetTransformation (theTrsf); } //======================================================================= @@ -321,7 +290,7 @@ Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d if (theTrsf->Form() == gp_Translation) { myPresentableObject->Compute (Projector (theProjector), aPrs3d); - aPrs3d->Transform (theTrsf); + aPrs3d->SetTransformation (theTrsf); return aPrs3d; } @@ -342,7 +311,7 @@ Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d } myPresentableObject->Compute (Projector (theProjector), aPrs3d); - aPrs3d->Transform (theTrsf); + aPrs3d->SetTransformation (theTrsf); return aPrs3d; } diff --git a/src/PrsMgr/PrsMgr_Presentation.hxx b/src/PrsMgr/PrsMgr_Presentation.hxx index 7977ea7382..3db0230d61 100644 --- a/src/PrsMgr/PrsMgr_Presentation.hxx +++ b/src/PrsMgr/PrsMgr_Presentation.hxx @@ -109,13 +109,7 @@ private: Standard_EXPORT void Connect (const Handle(PrsMgr_Presentation)& theOther) const; - Standard_EXPORT void Transform (const Handle(Geom_Transformation)& theTrsf) const; - - Standard_EXPORT void Place (const Quantity_Length theX, const Quantity_Length theY, const Quantity_Length theZ) const; - - Standard_EXPORT void Multiply (const Handle(Geom_Transformation)& theTrsf) const; - - Standard_EXPORT void Move (const Quantity_Length theX, const Quantity_Length theY, const Quantity_Length theZ) const; + Standard_EXPORT void SetTransformation (const Handle(Geom_Transformation)& theTrsf) const; Standard_EXPORT void Compute (const Handle(Graphic3d_Structure)& theStructure); diff --git a/src/PrsMgr/PrsMgr_PresentationManager.cxx b/src/PrsMgr/PrsMgr_PresentationManager.cxx index aa05bec3a6..ce0a0fdd54 100644 --- a/src/PrsMgr/PrsMgr_PresentationManager.cxx +++ b/src/PrsMgr/PrsMgr_PresentationManager.cxx @@ -593,7 +593,7 @@ void PrsMgr_PresentationManager::Transform (const Handle(PrsMgr_PresentableObjec const Handle(Geom_Transformation)& theTransformation, const Standard_Integer theMode) { - Presentation (thePrsObj, theMode)->Transform (theTransformation); + Presentation (thePrsObj, theMode)->SetTransformation (theTransformation); } @@ -656,13 +656,13 @@ namespace { // ======================================================================= // function : updatePrsTransformation - // purpose : Internal funtion that scans thePrsList for shadow presentations + // purpose : Internal function that scans thePrsList for shadow presentations // and applies transformation theTrsf to them in case if parent ID // of shadow presentation is equal to theRefId // ======================================================================= void updatePrsTransformation (const PrsMgr_ListOfPresentations& thePrsList, const Standard_Integer theRefId, - const Graphic3d_Mat4& theTrsf) + const Handle(Geom_Transformation)& theTrsf) { for (PrsMgr_ListOfPresentations::Iterator anIter (thePrsList); anIter.More(); anIter.Next()) { @@ -674,7 +674,7 @@ namespace if (aShadowPrs.IsNull() || aShadowPrs->ParentId() != theRefId) continue; - aShadowPrs->CStructure()->Transformation = theTrsf; + aShadowPrs->CStructure()->SetTransformation (theTrsf); } } } @@ -696,7 +696,7 @@ void PrsMgr_PresentationManager::UpdateHighlightTrsf (const Handle(V3d_Viewer)& aBasePrs : Presentation (theSelObj, theMode, Standard_False)->Presentation(); const Standard_Integer aParentId = aParentPrs->CStructure()->Id; - updatePrsTransformation (myImmediateList, aParentId, aBasePrs->CStructure()->Transformation); + updatePrsTransformation (myImmediateList, aParentId, aBasePrs->CStructure()->Transformation()); if (!myViewDependentImmediateList.IsEmpty()) { @@ -708,7 +708,7 @@ void PrsMgr_PresentationManager::UpdateHighlightTrsf (const Handle(V3d_Viewer)& { updatePrsTransformation (myViewDependentImmediateList, aViewDepParentPrs->CStructure()->Id, - aBasePrs->CStructure()->Transformation); + aBasePrs->CStructure()->Transformation()); } } } diff --git a/src/PrsMgr/PrsMgr_Prs.cxx b/src/PrsMgr/PrsMgr_Prs.cxx index c226af0e89..4172febb93 100644 --- a/src/PrsMgr/PrsMgr_Prs.cxx +++ b/src/PrsMgr/PrsMgr_Prs.cxx @@ -12,6 +12,7 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_Prs,Prs3d_Presentation) @@ -55,20 +55,13 @@ Handle(Graphic3d_Structure) PrsMgr_Prs::Compute(const Handle(Graphic3d_DataStruc } //======================================================================= //function : Compute -//purpose : +//purpose : //======================================================================= -Handle(Graphic3d_Structure) PrsMgr_Prs::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector, - const TColStd_Array2OfReal& AMatrix) +Handle(Graphic3d_Structure) PrsMgr_Prs::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, + const Handle(Geom_Transformation)& theTrsf) { - gp_Trsf TheTrsf; - Standard_Integer LC(AMatrix.LowerCol()),LR(AMatrix.LowerRow()); - TheTrsf.SetValues(AMatrix(LR,LC),AMatrix(LR,LC+1),AMatrix(LR,LC+2),AMatrix(LR,LC+3), - AMatrix(LR+1,LC),AMatrix(LR+1,LC+1),AMatrix(LR+1,LC+2),AMatrix(LR+1,LC+3), - AMatrix(LR+2,LC),AMatrix(LR+2,LC+1),AMatrix(LR+2,LC+2),AMatrix(LR+2,LC+3)); - Handle(Geom_Transformation) G = new Geom_Transformation(TheTrsf); - - return myPresentation3d->Compute(aProjector,G); + return myPresentation3d->Compute (theProjector, theTrsf); } //======================================================================= @@ -85,20 +78,12 @@ void PrsMgr_Prs::Compute(const Handle(Graphic3d_DataStructureManager)& aProjecto //======================================================================= //function : Compute -//purpose : +//purpose : //======================================================================= -void PrsMgr_Prs::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector, - const TColStd_Array2OfReal& AMatrix, - Handle(Graphic3d_Structure)& aGivenStruct) +void PrsMgr_Prs::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, + const Handle(Geom_Transformation)& theTrsf, + Handle(Graphic3d_Structure)& theGivenStruct) { - gp_Trsf TheTrsf; - Standard_Integer LC(AMatrix.LowerCol()),LR(AMatrix.LowerRow()); - TheTrsf.SetValues(AMatrix(LR,LC),AMatrix(LR,LC+1),AMatrix(LR,LC+2),AMatrix(LR,LC+3), - AMatrix(LR+1,LC),AMatrix(LR+1,LC+1),AMatrix(LR+1,LC+2),AMatrix(LR+1,LC+3), - AMatrix(LR+2,LC),AMatrix(LR+2,LC+1),AMatrix(LR+2,LC+2),AMatrix(LR+2,LC+3)); - Handle(Geom_Transformation) G = new Geom_Transformation(TheTrsf); - - - myPresentation3d->Compute(aProjector,G,aGivenStruct); + myPresentation3d->Compute (theProjector, theTrsf, theGivenStruct); } diff --git a/src/PrsMgr/PrsMgr_Prs.hxx b/src/PrsMgr/PrsMgr_Prs.hxx index 10a96a1384..6cc296737e 100644 --- a/src/PrsMgr/PrsMgr_Prs.hxx +++ b/src/PrsMgr/PrsMgr_Prs.hxx @@ -28,16 +28,13 @@ class Graphic3d_StructureManager; class Graphic3d_Structure; class Graphic3d_DataStructureManager; - class PrsMgr_Prs; DEFINE_STANDARD_HANDLE(PrsMgr_Prs, Prs3d_Presentation) - class PrsMgr_Prs : public Prs3d_Presentation { public: - Standard_EXPORT PrsMgr_Prs(const Handle(Graphic3d_StructureManager)& theStructManager, const PrsMgr_PresentationPointer& thePresentation, const PrsMgr_TypeOfPresentation3d theTypeOfPresentation3d); @@ -51,8 +48,9 @@ public: //! We have to take in account this Transformation //! in the computation of hidden line removal... //! returns a filled Graphic Structure. - Standard_EXPORT Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, const TColStd_Array2OfReal& AMatrix) Standard_OVERRIDE; - + Standard_EXPORT Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, + const Handle(Geom_Transformation)& theTrsf) Standard_OVERRIDE; + //! No need to return a structure, just to fill //! .... Standard_EXPORT void Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, Handle(Graphic3d_Structure)& ComputedStruct) Standard_OVERRIDE; @@ -60,30 +58,16 @@ public: //! No Need to return a Structure, just to //! Fill . The Trsf has to be taken in account //! in the computation (Rotation Part....) - Standard_EXPORT void Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, const TColStd_Array2OfReal& AMatrix, Handle(Graphic3d_Structure)& aStructure) Standard_OVERRIDE; - - - + Standard_EXPORT void Compute (const Handle(Graphic3d_DataStructureManager)& theProjector, + const Handle(Geom_Transformation)& theTrsf, + Handle(Graphic3d_Structure)& theStructure) Standard_OVERRIDE; DEFINE_STANDARD_RTTIEXT(PrsMgr_Prs,Prs3d_Presentation) -protected: - - - - private: - PrsMgr_PresentationPointer myPresentation3d; - }; - - - - - - #endif // _PrsMgr_Prs_HeaderFile diff --git a/src/V3d/V3d_CircularGrid.cxx b/src/V3d/V3d_CircularGrid.cxx index b556636f25..23a55ab0aa 100644 --- a/src/V3d/V3d_CircularGrid.cxx +++ b/src/V3d/V3d_CircularGrid.cxx @@ -122,40 +122,22 @@ void V3d_CircularGrid::UpdateDisplay () { const Standard_Real CosAlpha = Cos (RotationAngle ()); const Standard_Real SinAlpha = Sin (RotationAngle ()); - TColStd_Array2OfReal Trsf (1, 4, 1, 4); - Trsf (4, 4) = 1.0; - Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0; + + gp_Trsf aTrsf; // Translation - Trsf (1, 4) = xl, - Trsf (2, 4) = yl, - Trsf (3, 4) = zl; - // Transformation change of marker - Trsf (1, 1) = xdx, - Trsf (2, 1) = xdy, - Trsf (3, 1) = xdz, - Trsf (1, 2) = ydx, - Trsf (2, 2) = ydy, - Trsf (3, 2) = ydz, - Trsf (1, 3) = dx, - Trsf (2, 3) = dy, - Trsf (3, 3) = dz; - myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE); + // Transformation of change of marker + aTrsf.SetValues (xdx, ydx, dx, xl, + xdy, ydy, dy, yl, + xdz, ydz, dz, zl); // Translation of the origin - Trsf (1, 4) = -XOrigin (), - Trsf (2, 4) = -YOrigin (), - Trsf (3, 4) = 0.0; // Rotation Alpha around axis -Z - Trsf (1, 1) = CosAlpha, - Trsf (2, 1) = -SinAlpha, - Trsf (3, 1) = 0.0, - Trsf (1, 2) = SinAlpha, - Trsf (2, 2) = CosAlpha, - Trsf (3, 2) = 0.0, - Trsf (1, 3) = 0.0, - Trsf (2, 3) = 0.0, - Trsf (3, 3) = 1.0; - myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE); + gp_Trsf aTrsf2; + aTrsf2.SetValues ( CosAlpha, SinAlpha, 0.0, -XOrigin(), + -SinAlpha, CosAlpha, 0.0, -YOrigin(), + 0.0, 0.0, 1.0, 0.0); + aTrsf.Multiply (aTrsf2); + myStructure->SetTransformation (new Geom_Transformation (aTrsf)); myCurAngle = RotationAngle (); myCurXo = XOrigin (), myCurYo = YOrigin (); diff --git a/src/V3d/V3d_Plane.cxx b/src/V3d/V3d_Plane.cxx index 09b71c1e96..71b88ca68a 100755 --- a/src/V3d/V3d_Plane.cxx +++ b/src/V3d/V3d_Plane.cxx @@ -134,27 +134,14 @@ Standard_Boolean V3d_Plane::IsDisplayed() const // ======================================================================= void V3d_Plane::Update() { - if(!myGraphicStructure.IsNull()) + if (myGraphicStructure.IsNull()) { - TColStd_Array2OfReal aMatrix (1, 4, 1, 4); - Standard_Real theA, theB, theC, theD; - this->Plane(theA, theB, theC, theD); - gp_Pln aGeomPln (theA, theB, theC, theD); - gp_Trsf aTransform; - aTransform.SetTransformation (aGeomPln.Position()); - aTransform.Invert(); - for (Standard_Integer i = 1; i <= 3; i++) - { - for (Standard_Integer j = 1; j <= 4; j++) - { - aMatrix.SetValue (i, j, aTransform.Value (i,j)); - } - } - - aMatrix.SetValue (4,1,0.); - aMatrix.SetValue (4,2,0.); - aMatrix.SetValue (4,3,0.); - aMatrix.SetValue (4,4,1.); - myGraphicStructure->SetTransform (aMatrix, Graphic3d_TOC_REPLACE); + return; } + + const gp_Pln aGeomPln = myPlane->ToPlane(); + gp_Trsf aTransform; + aTransform.SetTransformation (aGeomPln.Position()); + aTransform.Invert(); + myGraphicStructure->SetTransformation (new Geom_Transformation (aTransform)); } diff --git a/src/V3d/V3d_RectangularGrid.cxx b/src/V3d/V3d_RectangularGrid.cxx index 7870bb1d0e..3395f336a9 100644 --- a/src/V3d/V3d_RectangularGrid.cxx +++ b/src/V3d/V3d_RectangularGrid.cxx @@ -136,40 +136,22 @@ void V3d_RectangularGrid::UpdateDisplay () if (MakeTransform) { const Standard_Real CosAlpha = Cos (RotationAngle ()); const Standard_Real SinAlpha = Sin (RotationAngle ()); - TColStd_Array2OfReal Trsf (1, 4, 1, 4); - Trsf (4, 4) = 1.0; - Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0; + + gp_Trsf aTrsf; // Translation - Trsf (1, 4) = xl, - Trsf (2, 4) = yl, - Trsf (3, 4) = zl; // Transformation of change of marker - Trsf (1, 1) = xdx, - Trsf (2, 1) = xdy, - Trsf (3, 1) = xdz, - Trsf (1, 2) = ydx, - Trsf (2, 2) = ydy, - Trsf (3, 2) = ydz, - Trsf (1, 3) = dx, - Trsf (2, 3) = dy, - Trsf (3, 3) = dz; - myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE); + aTrsf.SetValues (xdx, ydx, dx, xl, + xdy, ydy, dy, yl, + xdz, ydz, dz, zl); // Translation of the origin - Trsf (1, 4) = -XOrigin (), - Trsf (2, 4) = -YOrigin (), - Trsf (3, 4) = 0.0; // Rotation Alpha around axis -Z - Trsf (1, 1) = CosAlpha, - Trsf (2, 1) = -SinAlpha, - Trsf (3, 1) = 0.0, - Trsf (1, 2) = SinAlpha, - Trsf (2, 2) = CosAlpha, - Trsf (3, 2) = 0.0, - Trsf (1, 3) = 0.0, - Trsf (2, 3) = 0.0, - Trsf (3, 3) = 1.0; - myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE); + gp_Trsf aTrsf2; + aTrsf2.SetValues ( CosAlpha, SinAlpha, 0.0, -XOrigin(), + -SinAlpha, CosAlpha, 0.0, -YOrigin(), + 0.0, 0.0, 1.0, 0.0); + aTrsf.Multiply (aTrsf2); + myStructure->SetTransformation (new Geom_Transformation (aTrsf)); myCurAngle = RotationAngle (); myCurXo = XOrigin (), myCurYo = YOrigin (); diff --git a/src/gp/gp_Trsf.hxx b/src/gp/gp_Trsf.hxx index dce0985006..2825e8af64 100644 --- a/src/gp/gp_Trsf.hxx +++ b/src/gp/gp_Trsf.hxx @@ -15,29 +15,25 @@ #ifndef _gp_Trsf_HeaderFile #define _gp_Trsf_HeaderFile -#include -#include -#include - -#include #include #include #include +#include +#include #include +#include #include +#include +#include + class Standard_ConstructionError; class Standard_OutOfRange; -class gp_GTrsf; -class gp_Trsf2d; class gp_Pnt; class gp_Ax1; class gp_Ax2; class gp_Quaternion; class gp_Ax3; class gp_Vec; -class gp_XYZ; -class gp_Mat; - //! Defines a non-persistent transformation in 3D space. //! The following transformations are implemented : @@ -320,36 +316,50 @@ void operator *= (const gp_Trsf& T) //! Transformation of a triplet XYZ with a Trsf void Transforms (gp_XYZ& Coord) const; + //! Convert transformation to 4x4 matrix. + template + void GetMat4 (NCollection_Mat4& theMat) const + { + if (shape == gp_Identity) + { + theMat.InitIdentity(); + return; + } + + theMat.SetValue (0, 0, static_cast (Value (1, 1))); + theMat.SetValue (0, 1, static_cast (Value (1, 2))); + theMat.SetValue (0, 2, static_cast (Value (1, 3))); + theMat.SetValue (0, 3, static_cast (Value (1, 4))); + theMat.SetValue (1, 0, static_cast (Value (2, 1))); + theMat.SetValue (1, 1, static_cast (Value (2, 2))); + theMat.SetValue (1, 2, static_cast (Value (2, 3))); + theMat.SetValue (1, 3, static_cast (Value (2, 4))); + theMat.SetValue (2, 0, static_cast (Value (3, 1))); + theMat.SetValue (2, 1, static_cast (Value (3, 2))); + theMat.SetValue (2, 2, static_cast (Value (3, 3))); + theMat.SetValue (2, 3, static_cast (Value (3, 4))); + theMat.SetValue (3, 0, static_cast (0)); + theMat.SetValue (3, 1, static_cast (0)); + theMat.SetValue (3, 2, static_cast (0)); + theMat.SetValue (3, 3, static_cast (1)); + } friend class gp_GTrsf; - protected: - //! Makes orthogonalization of "matrix" Standard_EXPORT void Orthogonalize(); - - - private: - - Standard_Real scale; gp_TrsfForm shape; gp_Mat matrix; gp_XYZ loc; - }; - #include - - - - #endif // _gp_Trsf_HeaderFile