diff --git a/src/AIS/AIS_Manipulator.cxx b/src/AIS/AIS_Manipulator.cxx index 0d4afa7152..ff0746caf3 100644 --- a/src/AIS/AIS_Manipulator.cxx +++ b/src/AIS/AIS_Manipulator.cxx @@ -24,16 +24,17 @@ #include #include #include +#include #include #include +#include +#include #include #include #include #include +#include #include -#include -#include -#include #include #include @@ -925,7 +926,7 @@ void AIS_Manipulator::ComputeSelection (const Handle(SelectMgr_Selection)& theSe { anOwner = new SelectMgr_EntityOwner (this, 5); } - Handle(Select3D_SensitiveTriangulation) aTri; + if (aMode == AIS_MM_Translation || aMode == AIS_MM_None) { for (Standard_Integer anIt = 0; anIt < 3; ++anIt) @@ -939,12 +940,10 @@ void AIS_Manipulator::ComputeSelection (const Handle(SelectMgr_Selection)& theSe Handle(Select3D_SensitiveSegment) aLine = new Select3D_SensitiveSegment (anOwner, gp::Origin(), anAxis.TranslatorTipPosition()); aLine->SetSensitivityFactor (15); theSelection->Add (aLine); + // enlarge sensitivity by triangulation - aTri = new Select3D_SensitiveTriangulation (anOwner, anAxis.TranslatorCylinder().Triangulation(), TopLoc_Location(), Standard_True); - theSelection->Add (aTri); - aTri = new Select3D_SensitiveTriangulation (anOwner, anAxis.TranslatorArrow().Triangulation(), TopLoc_Location(), Standard_True); - theSelection->Add (aTri); - aTri = new Select3D_SensitiveTriangulation (anOwner, anAxis.TranslatorArrowBottom().Triangulation(), TopLoc_Location(), Standard_True); + Handle(Select3D_SensitivePrimitiveArray) aTri = new Select3D_SensitivePrimitiveArray (anOwner); + aTri->InitTriangulation (anAxis.TriangleArray()->Attributes(), anAxis.TriangleArray()->Indices(), TopLoc_Location()); theSelection->Add (aTri); } } @@ -964,7 +963,7 @@ void AIS_Manipulator::ComputeSelection (const Handle(SelectMgr_Selection)& theSe aCircle->SetSensitivityFactor (15); theSelection->Add (aCircle); // enlarge sensitivity by triangulation - aTri = new Select3D_SensitiveTriangulation (anOwner, myAxes[anIt].RotatorDisk().Triangulation(), TopLoc_Location(), Standard_True); + Handle(Select3D_SensitiveTriangulation) aTri = new Select3D_SensitiveTriangulation (anOwner, myAxes[anIt].RotatorDisk().Triangulation(), TopLoc_Location(), Standard_True); theSelection->Add (aTri); } } @@ -982,35 +981,12 @@ void AIS_Manipulator::ComputeSelection (const Handle(SelectMgr_Selection)& theSe aPnt->SetSensitivityFactor (15); theSelection->Add (aPnt); // enlarge sensitivity by triangulation - aTri = new Select3D_SensitiveTriangulation (anOwner, myAxes[anIt].ScalerCube().Triangulation(), TopLoc_Location(), Standard_True); + Handle(Select3D_SensitiveTriangulation) aTri = new Select3D_SensitiveTriangulation (anOwner, myAxes[anIt].ScalerCube().Triangulation(), TopLoc_Location(), Standard_True); theSelection->Add (aTri); } } } -//======================================================================= -//class : Cylinder -//function : Init -//purpose : -//======================================================================= -void AIS_Manipulator::Cylinder::Init (const Standard_ShortReal theBotRad, const Standard_ShortReal theTopRad, - const Standard_ShortReal theHeight, - const Standard_Integer theSlicesNb, const Standard_Integer theStacksNb, - const gp_Ax1& thePosition) -{ - myPosition = thePosition; - myBottomRad = theBotRad; - myTopRad = theTopRad; - myHeight = theHeight; - - StdPrs_ToolCylinder aTool (myBottomRad, myTopRad, myHeight, theSlicesNb, theStacksNb); - gp_Ax3 aSystem (myPosition.Location(), myPosition.Direction()); - gp_Trsf aTrsf; - aTrsf.SetTransformation (aSystem, gp_Ax3()); - - aTool.FillArray (myArray, myTriangulation, aTrsf); -} - //======================================================================= //class : Disk //function : Init @@ -1026,7 +1002,7 @@ void AIS_Manipulator::Disk::Init (const Standard_ShortReal theInnerRadius, myInnerRad = theInnerRadius; myOuterRad = theOuterRadius; - StdPrs_ToolDisk aTool (theInnerRadius, theOuterRadius, theSlicesNb, theStacksNb); + Prs3d_ToolDisk aTool (theInnerRadius, theOuterRadius, theSlicesNb, theStacksNb); gp_Ax3 aSystem (myPosition.Location(), myPosition.Direction()); gp_Trsf aTrsf; aTrsf.SetTransformation (aSystem, gp_Ax3()); @@ -1046,7 +1022,7 @@ void AIS_Manipulator::Sphere::Init (const Standard_ShortReal theRadius, myPosition = thePosition; myRadius = theRadius; - StdPrs_ToolSphere aTool (theRadius, theSlicesNb, theStacksNb); + Prs3d_ToolSphere aTool (theRadius, theSlicesNb, theStacksNb); gp_Trsf aTrsf; aTrsf.SetTranslation (gp_Vec(gp::Origin(), thePosition)); aTool.FillArray (myArray, myTriangulation, aTrsf); @@ -1153,44 +1129,39 @@ AIS_Manipulator::Axis::Axis (const gp_Ax1& theAxis, //======================================================================= //class : Axis //function : Compute -//purpose : +//purpose : //======================================================================= -void AIS_Manipulator::Axis::Compute (const Handle_PrsMgr_PresentationManager3d& thePrsMgr, + +void AIS_Manipulator::Axis::Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr, const Handle(Prs3d_Presentation)& thePrs, const Handle(Prs3d_ShadingAspect)& theAspect) { - Handle(Graphic3d_Group) aGroup; - if (myHasTranslation) { - const Standard_ShortReal anArrowLength = 0.25f * myLength; - const Standard_ShortReal aCylinderLength = myLength - anArrowLength; - - myCylinder.Init (myAxisRadius, myAxisRadius, aCylinderLength, myFacettesNumber, 2, gp_Ax1 (gp::Origin(), myReferenceAxis.Direction())); - - gp_Pnt anArrowBottom (0.0, 0.0, 0.0); - anArrowBottom.Translate (myReferenceAxis.Direction().XYZ() * aCylinderLength); - - myArrow.Init (myAxisRadius * 1.5f, 0.0f, anArrowLength, myFacettesNumber, 2, gp_Ax1 (anArrowBottom, myReferenceAxis.Direction())); - myArrowBottom.Init (myAxisRadius, myAxisRadius * 1.5f, gp_Ax1 (anArrowBottom, myReferenceAxis.Direction()), myFacettesNumber); - myArrowTipPos = anArrowBottom; + const Standard_Real anArrowLength = 0.25 * myLength; + const Standard_Real aCylinderLength = myLength - anArrowLength; + myArrowTipPos = gp_Pnt (0.0, 0.0, 0.0).Translated (myReferenceAxis.Direction().XYZ() * aCylinderLength); + myTriangleArray = Prs3d_Arrow::DrawShaded (gp_Ax1(gp::Origin(), myReferenceAxis.Direction()), + myAxisRadius, + myLength, + myAxisRadius * 1.5, + anArrowLength, + myFacettesNumber); myTranslatorGroup = Prs3d_Root::NewGroup (thePrs); myTranslatorGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); - myTranslatorGroup->AddPrimitiveArray (myCylinder.Array()); - myTranslatorGroup->AddPrimitiveArray (myArrow.Array()); - myTranslatorGroup->AddPrimitiveArray (myArrowBottom.Array()); + myTranslatorGroup->AddPrimitiveArray (myTriangleArray); if (myHighlightTranslator.IsNull()) { myHighlightTranslator = new Prs3d_Presentation (thePrsMgr->StructureManager()); } - - myHighlightTranslator->Clear(); - aGroup = Prs3d_Root::CurrentGroup (myHighlightTranslator); - aGroup->AddPrimitiveArray (myCylinder.Array()); - aGroup->AddPrimitiveArray (myArrow.Array()); - aGroup->AddPrimitiveArray (myArrowBottom.Array()); + else + { + myHighlightTranslator->Clear(); + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (myHighlightTranslator); + aGroup->AddPrimitiveArray (myTriangleArray); } if (myHasScaling) @@ -1206,9 +1177,11 @@ void AIS_Manipulator::Axis::Compute (const Handle_PrsMgr_PresentationManager3d& { myHighlightScaler = new Prs3d_Presentation (thePrsMgr->StructureManager()); } - - myHighlightScaler->Clear(); - aGroup = Prs3d_Root::CurrentGroup (myHighlightScaler); + else + { + myHighlightScaler->Clear(); + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (myHighlightScaler); aGroup->AddPrimitiveArray (myCube.Array()); } @@ -1224,9 +1197,11 @@ void AIS_Manipulator::Axis::Compute (const Handle_PrsMgr_PresentationManager3d& { myHighlightRotator = new Prs3d_Presentation (thePrsMgr->StructureManager()); } - - myHighlightRotator->Clear(); - aGroup = Prs3d_Root::CurrentGroup (myHighlightRotator); + else + { + myHighlightRotator->Clear(); + } + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (myHighlightRotator); Prs3d_Root::CurrentGroup (myHighlightRotator)->AddPrimitiveArray (myCircle.Array()); } } diff --git a/src/AIS/AIS_Manipulator.hxx b/src/AIS/AIS_Manipulator.hxx index 13588bafc0..6700c401c6 100644 --- a/src/AIS/AIS_Manipulator.hxx +++ b/src/AIS/AIS_Manipulator.hxx @@ -375,32 +375,6 @@ protected: //! @name Auxilliary classes to fill presentation with proper primiti Handle(Graphic3d_ArrayOfTriangles) myArray; }; - class Cylinder : public Quadric - { - public: - - Cylinder() - : Quadric(), - myBottomRad(1.0f), - myTopRad(1.0f), - myHeight(1.0f) - { } - - virtual ~Cylinder() {} - - void Init (const Standard_ShortReal theBotRad, const Standard_ShortReal theTopRad, - const Standard_ShortReal theHeight, - const Standard_Integer theSlicesNb, const Standard_Integer theStacksNb, - const gp_Ax1& thePosition); - - protected: - - gp_Ax1 myPosition; - Standard_ShortReal myBottomRad; - Standard_ShortReal myTopRad; - Standard_ShortReal myHeight; - }; - class Disk : public Quadric { public: @@ -482,7 +456,7 @@ protected: //! @name Auxilliary classes to fill presentation with proper primiti const Quantity_Color& theColor = Quantity_Color(), const Standard_ShortReal theLength = 10.0f); - void Compute (const Handle_PrsMgr_PresentationManager3d& thePrsMgr, + void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr, const Handle(Prs3d_Presentation)& thePrs, const Handle(Prs3d_ShadingAspect)& theAspect); @@ -560,6 +534,8 @@ protected: //! @name Auxilliary classes to fill presentation with proper primiti const Handle(Graphic3d_Group)& ScalerGroup() const { return myScalerGroup; } + const Handle(Graphic3d_ArrayOfTriangles)& TriangleArray() const { return myTriangleArray; } + void SetIndent (const Standard_ShortReal theValue) { myIndent = theValue; } Standard_ShortReal Size() const { return myLength + myBoxSize + myDiskThickness + myIndent * 2.0f; } @@ -590,10 +566,7 @@ protected: //! @name Auxilliary classes to fill presentation with proper primiti public: - const Cylinder& TranslatorCylinder() const { return myCylinder; } - const Cylinder& TranslatorArrow() const { return myArrow; } const gp_Pnt& TranslatorTipPosition() const { return myArrowTipPos; } - const Disk& TranslatorArrowBottom() const { return myArrowBottom; } const Disk& RotatorDisk() const { return myCircle; } float RotatorDiskRadius() const { return myCircleRadius; } const Cube& ScalerCube() const { return myCube; } @@ -621,10 +594,7 @@ protected: //! @name Auxilliary classes to fill presentation with proper primiti Standard_Integer myFacettesNumber; - Cylinder myCylinder; - Cylinder myArrow; gp_Pnt myArrowTipPos; - Disk myArrowBottom; Disk myCircle; float myCircleRadius; Cube myCube; @@ -637,6 +607,9 @@ protected: //! @name Auxilliary classes to fill presentation with proper primiti Handle(Prs3d_Presentation) myHighlightTranslator; Handle(Prs3d_Presentation) myHighlightScaler; Handle(Prs3d_Presentation) myHighlightRotator; + + Handle(Graphic3d_ArrayOfTriangles) myTriangleArray; + }; protected: diff --git a/src/Prs3d/FILES b/src/Prs3d/FILES index 4bd4270717..a982836f3d 100755 --- a/src/Prs3d/FILES +++ b/src/Prs3d/FILES @@ -46,6 +46,14 @@ Prs3d_Text.cxx Prs3d_Text.hxx Prs3d_TextAspect.cxx Prs3d_TextAspect.hxx +Prs3d_ToolDisk.hxx +Prs3d_ToolDisk.cxx +Prs3d_ToolCylinder.hxx +Prs3d_ToolCylinder.cxx +Prs3d_ToolQuadric.hxx +Prs3d_ToolQuadric.cxx +Prs3d_ToolSphere.hxx +Prs3d_ToolSphere.cxx Prs3d_TypeOfHLR.hxx Prs3d_TypeOfLinePicking.hxx Prs3d_VertexDrawMode.hxx diff --git a/src/Prs3d/Prs3d_Arrow.cxx b/src/Prs3d/Prs3d_Arrow.cxx index 619d6aa712..3c9d12bbc3 100644 --- a/src/Prs3d/Prs3d_Arrow.cxx +++ b/src/Prs3d/Prs3d_Arrow.cxx @@ -14,12 +14,17 @@ #include +#include #include #include +#include #include #include #include #include +#include +#include +#include //======================================================================= //function : Draw @@ -85,3 +90,61 @@ void Prs3d_Arrow::Draw(const Handle(Graphic3d_Group)& theGroup, theGroup->AddPrimitiveArray (aPrims1); theGroup->AddPrimitiveArray (aPrims2); } + +// ============================================================================ +// function : DrawShaded +// purpose : +// ============================================================================ +Handle(Graphic3d_ArrayOfTriangles) Prs3d_Arrow::DrawShaded (const gp_Ax1& theAxis, + const Standard_Real theTubeRadius, + const Standard_Real theAxisLength, + const Standard_Real theConeRadius, + const Standard_Real theConeLength, + const Standard_Integer theNbFacettes) +{ + const Standard_Real aTubeLength = Max (0.0, theAxisLength - theConeLength); + const Standard_Integer aNbTrisTube = (theTubeRadius > 0.0 && aTubeLength > 0.0) + ? Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1) + : 0; + const Standard_Integer aNbTrisCone = (theConeRadius > 0.0 && theConeLength > 0.0) + ? (Prs3d_ToolDisk ::TrianglesNb (theNbFacettes, 1) + + Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1)) + : 0; + + const Standard_Integer aNbTris = aNbTrisTube + aNbTrisCone; + if (aNbTris == 0) + { + return Handle(Graphic3d_ArrayOfTriangles)(); + } + + Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbTris * 3, 0, Standard_True); + if (aNbTrisTube != 0) + { + gp_Ax3 aSystem (theAxis.Location(), theAxis.Direction()); + gp_Trsf aTrsf; + aTrsf.SetTransformation (aSystem, gp_Ax3()); + + Prs3d_ToolCylinder aTool (theTubeRadius, theTubeRadius, aTubeLength, theNbFacettes, 1); + aTool.FillArray (anArray, aTrsf); + } + + if (aNbTrisCone != 0) + { + gp_Pnt aConeOrigin = theAxis.Location().Translated (gp_Vec (theAxis.Direction().X() * aTubeLength, + theAxis.Direction().Y() * aTubeLength, + theAxis.Direction().Z() * aTubeLength)); + gp_Ax3 aSystem (aConeOrigin, theAxis.Direction()); + gp_Trsf aTrsf; + aTrsf.SetTransformation (aSystem, gp_Ax3()); + { + Prs3d_ToolDisk aTool (0.0, theConeRadius, theNbFacettes, 1); + aTool.FillArray (anArray, aTrsf); + } + { + Prs3d_ToolCylinder aTool (theConeRadius, 0.0, theConeLength, theNbFacettes, 1); + aTool.FillArray (anArray, aTrsf); + } + } + + return anArray; +} diff --git a/src/Prs3d/Prs3d_Arrow.hxx b/src/Prs3d/Prs3d_Arrow.hxx index 6e813620c8..21917b7203 100644 --- a/src/Prs3d/Prs3d_Arrow.hxx +++ b/src/Prs3d/Prs3d_Arrow.hxx @@ -18,9 +18,12 @@ #define _Prs3d_Arrow_HeaderFile #include + +#include #include #include +class gp_Ax1; class gp_Pnt; class gp_Dir; @@ -29,7 +32,19 @@ class Prs3d_Arrow : public Prs3d_Root { public: - DEFINE_STANDARD_ALLOC + //! Defines the representation of the arrow as shaded triangulation. + //! @param theAxis axis definition (arrow origin and direction) + //! @param theTubeRadius tube (cylinder) radius + //! @param theAxisLength overall arrow length (cylinder + cone) + //! @param theConeRadius cone radius (arrow tip) + //! @param theConeLength cone length (arrow tip) + //! @param theNbFacettes tessellation quality for each part + Standard_EXPORT static Handle(Graphic3d_ArrayOfTriangles) DrawShaded (const gp_Ax1& theAxis, + const Standard_Real theTubeRadius, + const Standard_Real theAxisLength, + const Standard_Real theConeRadius, + const Standard_Real theConeLength, + const Standard_Integer theNbFacettes); //! Defines the representation of the arrow. //! Note that this method does NOT assign any presentation aspects to the primitives group! diff --git a/src/StdPrs/StdPrs_ToolCylinder.cxx b/src/Prs3d/Prs3d_ToolCylinder.cxx similarity index 62% rename from src/StdPrs/StdPrs_ToolCylinder.cxx rename to src/Prs3d/Prs3d_ToolCylinder.cxx index cbfec9318d..a570e5fde0 100644 --- a/src/StdPrs/StdPrs_ToolCylinder.cxx +++ b/src/Prs3d/Prs3d_ToolCylinder.cxx @@ -14,21 +14,21 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include #include -#include +#include //======================================================================= //function : Constructor //purpose : //======================================================================= -StdPrs_ToolCylinder::StdPrs_ToolCylinder (const Standard_Real theBottomRad, - const Standard_Real theTopRad, - const Standard_Real theHeight, - const Standard_Integer theNbSlices, - const Standard_Integer theNbStacks) +Prs3d_ToolCylinder::Prs3d_ToolCylinder (const Standard_Real theBottomRad, + const Standard_Real theTopRad, + const Standard_Real theHeight, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks) : myBottomRadius (theBottomRad), myTopRadius (theTopRad), myHeight (theHeight) @@ -41,7 +41,7 @@ StdPrs_ToolCylinder::StdPrs_ToolCylinder (const Standard_Real theBottomRad, //function : Vertex //purpose : //======================================================================= -gp_Pnt StdPrs_ToolCylinder::Vertex (const Standard_Real theU, const Standard_Real theV) +gp_Pnt Prs3d_ToolCylinder::Vertex (const Standard_Real theU, const Standard_Real theV) { const Standard_Real aU = theU * M_PI * 2.0; const Standard_Real aRadius = myBottomRadius + (myTopRadius - myBottomRadius) * theV; @@ -54,7 +54,7 @@ gp_Pnt StdPrs_ToolCylinder::Vertex (const Standard_Real theU, const Standard_Rea //function : Add //purpose : //======================================================================= -gp_Dir StdPrs_ToolCylinder::Normal (const Standard_Real theU, const Standard_Real /*theV*/) +gp_Dir Prs3d_ToolCylinder::Normal (const Standard_Real theU, const Standard_Real /*theV*/) { const Standard_Real aU = theU * M_PI * 2.0; return gp_Dir (Cos (aU) * myHeight, @@ -66,15 +66,15 @@ gp_Dir StdPrs_ToolCylinder::Normal (const Standard_Real theU, const Standard_Rea //function : Perform //purpose : //======================================================================= -Handle(Graphic3d_ArrayOfTriangles) StdPrs_ToolCylinder::Create (const Standard_Real theBottomRad, - const Standard_Real theTopRad, - const Standard_Real theHeight, - const Standard_Integer theNbSlices, - const Standard_Integer theNbStacks, - const gp_Trsf& theTrsf) +Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolCylinder::Create (const Standard_Real theBottomRad, + const Standard_Real theTopRad, + const Standard_Real theHeight, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks, + const gp_Trsf& theTrsf) { Handle(Graphic3d_ArrayOfTriangles) anArray; - StdPrs_ToolCylinder aTool (theBottomRad, theTopRad, theHeight, theNbSlices, theNbStacks); + Prs3d_ToolCylinder aTool (theBottomRad, theTopRad, theHeight, theNbSlices, theNbStacks); aTool.FillArray (anArray, theTrsf); return anArray; } diff --git a/src/StdPrs/StdPrs_ToolCylinder.hxx b/src/Prs3d/Prs3d_ToolCylinder.hxx similarity index 77% rename from src/StdPrs/StdPrs_ToolCylinder.hxx rename to src/Prs3d/Prs3d_ToolCylinder.hxx index eaff0db54c..681778b544 100644 --- a/src/StdPrs/StdPrs_ToolCylinder.hxx +++ b/src/Prs3d/Prs3d_ToolCylinder.hxx @@ -13,14 +13,14 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _StdPrs_ToolCylinder_HeaderFile -#define _StdPrs_ToolCylinder_HeaderFile +#ifndef _Prs3d_ToolCylinder_HeaderFile +#define _Prs3d_ToolCylinder_HeaderFile #include -#include +#include //! Standard presentation algorithm that outputs graphical primitives for cylindrical surface. -class StdPrs_ToolCylinder : public StdPrs_ToolQuadric +class Prs3d_ToolCylinder : public Prs3d_ToolQuadric { public: @@ -33,14 +33,12 @@ public: const gp_Trsf& theTrsf); public: - DEFINE_STANDARD_ALLOC - //! Initializes the algorithm. - Standard_EXPORT StdPrs_ToolCylinder (const Standard_Real theBottomRad, - const Standard_Real theTopRad, - const Standard_Real theHeight, - const Standard_Integer theNbSlices, - const Standard_Integer theNbStacks); + Standard_EXPORT Prs3d_ToolCylinder (const Standard_Real theBottomRad, + const Standard_Real theTopRad, + const Standard_Real theHeight, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks); protected: @@ -58,4 +56,4 @@ protected: }; -#endif // _StdPrs_ToolCylinder_HeaderFile +#endif // _Prs3d_ToolCylinder_HeaderFile diff --git a/src/StdPrs/StdPrs_ToolDisk.cxx b/src/Prs3d/Prs3d_ToolDisk.cxx similarity index 64% rename from src/StdPrs/StdPrs_ToolDisk.cxx rename to src/Prs3d/Prs3d_ToolDisk.cxx index 8eff59754f..3857d15c81 100644 --- a/src/StdPrs/StdPrs_ToolDisk.cxx +++ b/src/Prs3d/Prs3d_ToolDisk.cxx @@ -13,20 +13,20 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include #include -#include +#include //======================================================================= //function : Constructor //purpose : //======================================================================= -StdPrs_ToolDisk::StdPrs_ToolDisk (const Standard_Real theInnerRadius, - const Standard_Real theOuterRadius, - const Standard_Integer theNbSlices, - const Standard_Integer theNbStacks) +Prs3d_ToolDisk::Prs3d_ToolDisk (const Standard_Real theInnerRadius, + const Standard_Real theOuterRadius, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks) : myInnerRadius (theInnerRadius), myOuterRadius (theOuterRadius) { @@ -38,7 +38,7 @@ StdPrs_ToolDisk::StdPrs_ToolDisk (const Standard_Real theInnerRadius, //function : Vertex //purpose : //======================================================================= -gp_Pnt StdPrs_ToolDisk::Vertex (const Standard_Real theU, const Standard_Real theV) +gp_Pnt Prs3d_ToolDisk::Vertex (const Standard_Real theU, const Standard_Real theV) { const Standard_Real aU = theU * M_PI * 2.0; const Standard_Real aRadius = myInnerRadius + (myOuterRadius - myInnerRadius) * theV; @@ -51,7 +51,7 @@ gp_Pnt StdPrs_ToolDisk::Vertex (const Standard_Real theU, const Standard_Real th //function : Add //purpose : //======================================================================= -gp_Dir StdPrs_ToolDisk::Normal (const Standard_Real /*theU*/, const Standard_Real /*theV*/) +gp_Dir Prs3d_ToolDisk::Normal (const Standard_Real /*theU*/, const Standard_Real /*theV*/) { return gp_Dir (0.0, 0.0, -1.0); } @@ -60,14 +60,14 @@ gp_Dir StdPrs_ToolDisk::Normal (const Standard_Real /*theU*/, const Standard_Rea //function : Perform //purpose : //======================================================================= -Handle(Graphic3d_ArrayOfTriangles) StdPrs_ToolDisk::Create (const Standard_Real theInnerRadius, - const Standard_Real theOuterRadius, - const Standard_Integer theNbSlices, - const Standard_Integer theNbStacks, - const gp_Trsf& theTrsf) +Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolDisk::Create (const Standard_Real theInnerRadius, + const Standard_Real theOuterRadius, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks, + const gp_Trsf& theTrsf) { Handle(Graphic3d_ArrayOfTriangles) anArray; - StdPrs_ToolDisk aTool (theInnerRadius, theOuterRadius, theNbSlices, theNbStacks); + Prs3d_ToolDisk aTool (theInnerRadius, theOuterRadius, theNbSlices, theNbStacks); aTool.FillArray (anArray, theTrsf); return anArray; } diff --git a/src/StdPrs/StdPrs_ToolDisk.hxx b/src/Prs3d/Prs3d_ToolDisk.hxx similarity index 80% rename from src/StdPrs/StdPrs_ToolDisk.hxx rename to src/Prs3d/Prs3d_ToolDisk.hxx index fae2d9f4ab..1e66093e1f 100644 --- a/src/StdPrs/StdPrs_ToolDisk.hxx +++ b/src/Prs3d/Prs3d_ToolDisk.hxx @@ -13,14 +13,14 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _StdPrs_ToolDisk_HeaderFile -#define _StdPrs_ToolDisk_HeaderFile +#ifndef _Prs3d_ToolDisk_HeaderFile +#define _Prs3d_ToolDisk_HeaderFile #include -#include +#include //! Standard presentation algorithm that outputs graphical primitives for disk surface. -class StdPrs_ToolDisk : public StdPrs_ToolQuadric +class Prs3d_ToolDisk : public Prs3d_ToolQuadric { public: @@ -32,13 +32,11 @@ public: const gp_Trsf& theTrsf); public: - DEFINE_STANDARD_ALLOC - //! Initializes the algorithm. - Standard_EXPORT StdPrs_ToolDisk (const Standard_Real theInnerRadius, - const Standard_Real theOuterRadius, - const Standard_Integer theNbSlices, - const Standard_Integer theNbStacks); + Standard_EXPORT Prs3d_ToolDisk (const Standard_Real theInnerRadius, + const Standard_Real theOuterRadius, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks); protected: //! Computes vertex at given parameter location of the surface. diff --git a/src/StdPrs/StdPrs_ToolQuadric.cxx b/src/Prs3d/Prs3d_ToolQuadric.cxx similarity index 89% rename from src/StdPrs/StdPrs_ToolQuadric.cxx rename to src/Prs3d/Prs3d_ToolQuadric.cxx index f06b1fcbc2..5af6cfda37 100644 --- a/src/StdPrs/StdPrs_ToolQuadric.cxx +++ b/src/Prs3d/Prs3d_ToolQuadric.cxx @@ -13,7 +13,7 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include #include @@ -24,7 +24,7 @@ //function : fillArrays //purpose : //======================================================================= -void StdPrs_ToolQuadric::fillArrays (const gp_Trsf& theTrsf, TColgp_Array1OfPnt& theArray, NCollection_Array1& theNormals) +void Prs3d_ToolQuadric::fillArrays (const gp_Trsf& theTrsf, TColgp_Array1OfPnt& theArray, NCollection_Array1& theNormals) { Standard_ShortReal aStepU = 1.0f / mySlicesNb; Standard_ShortReal aStepV = 1.0f / myStacksNb; @@ -52,10 +52,13 @@ void StdPrs_ToolQuadric::fillArrays (const gp_Trsf& theTrsf, TColgp_Array1OfPnt& //function : FIllArray //purpose : //======================================================================= -void StdPrs_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, const gp_Trsf& theTrsf) +void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, const gp_Trsf& theTrsf) { const Standard_Integer aTrianglesNb = TrianglesNb(); - theArray = new Graphic3d_ArrayOfTriangles (aTrianglesNb * 3, 0, Standard_True); + if (theArray.IsNull()) + { + theArray = new Graphic3d_ArrayOfTriangles (aTrianglesNb * 3, 0, Standard_True); + } Poly_Array1OfTriangle aPolyTriangles (1, aTrianglesNb); TColgp_Array1OfPnt anArray (1, aTrianglesNb * 3); @@ -81,9 +84,9 @@ void StdPrs_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray //function : FillTriangulation //purpose : //======================================================================= -void StdPrs_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, - Handle(Poly_Triangulation)& theTriangulation, - const gp_Trsf& theTrsf) +void Prs3d_ToolQuadric::FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, + Handle(Poly_Triangulation)& theTriangulation, + const gp_Trsf& theTrsf) { const Standard_Integer aTrianglesNb = TrianglesNb(); theArray = new Graphic3d_ArrayOfTriangles(aTrianglesNb * 3, 0, Standard_True); diff --git a/src/StdPrs/StdPrs_ToolQuadric.hxx b/src/Prs3d/Prs3d_ToolQuadric.hxx similarity index 85% rename from src/StdPrs/StdPrs_ToolQuadric.hxx rename to src/Prs3d/Prs3d_ToolQuadric.hxx index 264f7bf585..8b6befa1ae 100644 --- a/src/StdPrs/StdPrs_ToolQuadric.hxx +++ b/src/Prs3d/Prs3d_ToolQuadric.hxx @@ -13,8 +13,8 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _StdPrs_ToolQuadric_HeaderFile -#define _StdPrs_ToolQuadric_HeaderFile +#ifndef _Prs3d_ToolQuadric_HeaderFile +#define _Prs3d_ToolQuadric_HeaderFile #include #include @@ -26,7 +26,7 @@ #include //! Base class to build 3D surfaces presentation of quadric surfaces. -class StdPrs_ToolQuadric +class Prs3d_ToolQuadric { public: @@ -38,6 +38,13 @@ public: //! Generate primitives for 3D quadric surface presentation and fill the given array and poly triangulation structure. Optional transformation is applied. Standard_EXPORT void FillArray (Handle(Graphic3d_ArrayOfTriangles)& theArray, Handle(Poly_Triangulation)& theTriangulation, const gp_Trsf& theTrsf); + //! Number of triangles for presentation with the given params. + static Standard_Integer TrianglesNb (const Standard_Integer theSlicesNb, + const Standard_Integer theStacksNb) + { + return theSlicesNb * theStacksNb * 2; + } + protected: //! Method implements an algorithm to generate arrays of vertices and normals for 3D surface. @@ -61,4 +68,4 @@ protected: Standard_Integer myStacksNb; }; -#endif // _StdPrs_ShadedSurface_HeaderFile +#endif // _Prs3d_ToolQuadric_HeaderFile diff --git a/src/StdPrs/StdPrs_ToolSphere.cxx b/src/Prs3d/Prs3d_ToolSphere.cxx similarity index 69% rename from src/StdPrs/StdPrs_ToolSphere.cxx rename to src/Prs3d/Prs3d_ToolSphere.cxx index 62e51b2f62..973a71b8c6 100644 --- a/src/StdPrs/StdPrs_ToolSphere.cxx +++ b/src/Prs3d/Prs3d_ToolSphere.cxx @@ -13,19 +13,19 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include #include #include -#include +#include //======================================================================= //function : Constructor //purpose : //======================================================================= -StdPrs_ToolSphere::StdPrs_ToolSphere (const Standard_Real theRadius, - const Standard_Integer theNbSlices, - const Standard_Integer theNbStacks) +Prs3d_ToolSphere::Prs3d_ToolSphere (const Standard_Real theRadius, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks) : myRadius (theRadius) { mySlicesNb = theNbSlices; @@ -36,7 +36,7 @@ StdPrs_ToolSphere::StdPrs_ToolSphere (const Standard_Real theRadius, //function : Vertex //purpose : //======================================================================= -gp_Pnt StdPrs_ToolSphere::Vertex (const Standard_Real theU, const Standard_Real theV) +gp_Pnt Prs3d_ToolSphere::Vertex (const Standard_Real theU, const Standard_Real theV) { const Standard_Real aU = theU * M_PI * 2.0; const Standard_Real aV = theV * M_PI; @@ -49,7 +49,7 @@ gp_Pnt StdPrs_ToolSphere::Vertex (const Standard_Real theU, const Standard_Real //function : Add //purpose : //======================================================================= -gp_Dir StdPrs_ToolSphere::Normal (const Standard_Real theU, const Standard_Real theV) +gp_Dir Prs3d_ToolSphere::Normal (const Standard_Real theU, const Standard_Real theV) { const Standard_Real aU = theU * M_PI * 2.0; const Standard_Real aV = theV * M_PI; @@ -62,13 +62,13 @@ gp_Dir StdPrs_ToolSphere::Normal (const Standard_Real theU, const Standard_Real //function : Perform //purpose : //======================================================================= -Handle(Graphic3d_ArrayOfTriangles) StdPrs_ToolSphere::Create (const Standard_Real theRadius, - const Standard_Integer theNbSlices, - const Standard_Integer theNbStacks, - const gp_Trsf& theTrsf) +Handle(Graphic3d_ArrayOfTriangles) Prs3d_ToolSphere::Create (const Standard_Real theRadius, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks, + const gp_Trsf& theTrsf) { Handle(Graphic3d_ArrayOfTriangles) anArray; - StdPrs_ToolSphere aTool (theRadius, theNbSlices, theNbStacks); + Prs3d_ToolSphere aTool (theRadius, theNbSlices, theNbStacks); aTool.FillArray (anArray, theTrsf); return anArray; } diff --git a/src/StdPrs/StdPrs_ToolSphere.hxx b/src/Prs3d/Prs3d_ToolSphere.hxx similarity index 83% rename from src/StdPrs/StdPrs_ToolSphere.hxx rename to src/Prs3d/Prs3d_ToolSphere.hxx index 1347a955a4..671262c5b3 100644 --- a/src/StdPrs/StdPrs_ToolSphere.hxx +++ b/src/Prs3d/Prs3d_ToolSphere.hxx @@ -13,8 +13,8 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _StdPrs_ToolSphere_HeaderFile -#define _StdPrs_ToolSphere_HeaderFile +#ifndef _Prs3d_ToolSphere_HeaderFile +#define _Prs3d_ToolSphere_HeaderFile #include #include @@ -24,10 +24,10 @@ #include #include #include -#include +#include //! Standard presentation algorithm that outputs graphical primitives for spherical surface. -class StdPrs_ToolSphere : public StdPrs_ToolQuadric +class Prs3d_ToolSphere : public Prs3d_ToolQuadric { public: @@ -38,12 +38,10 @@ public: const gp_Trsf& theTrsf); public: - DEFINE_STANDARD_ALLOC - //! Initializes the algorithm. - Standard_EXPORT StdPrs_ToolSphere (const Standard_Real theRadius, - const Standard_Integer theNbSlices, - const Standard_Integer theNbStacks); + Standard_EXPORT Prs3d_ToolSphere (const Standard_Real theRadius, + const Standard_Integer theNbSlices, + const Standard_Integer theNbStacks); protected: diff --git a/src/StdPrs/FILES b/src/StdPrs/FILES index 31829a8951..94ffef116e 100644 --- a/src/StdPrs/FILES +++ b/src/StdPrs/FILES @@ -21,16 +21,8 @@ StdPrs_ShadedShape.cxx StdPrs_ShadedShape.hxx StdPrs_ShadedSurface.cxx StdPrs_ShadedSurface.hxx -StdPrs_ToolDisk.hxx -StdPrs_ToolDisk.cxx -StdPrs_ToolCylinder.hxx -StdPrs_ToolCylinder.cxx StdPrs_ToolPoint.cxx StdPrs_ToolPoint.hxx -StdPrs_ToolQuadric.hxx -StdPrs_ToolQuadric.cxx -StdPrs_ToolSphere.hxx -StdPrs_ToolSphere.cxx StdPrs_ToolRFace.cxx StdPrs_ToolRFace.hxx StdPrs_ToolTriangulatedShape.cxx diff --git a/src/V3d/V3d_Trihedron.cxx b/src/V3d/V3d_Trihedron.cxx index 77ad2e8b3c..ca6e2ada0f 100644 --- a/src/V3d/V3d_Trihedron.cxx +++ b/src/V3d/V3d_Trihedron.cxx @@ -22,13 +22,12 @@ #include #include #include +#include #include #include #include #include -#include -#include -#include +#include #include IMPLEMENT_STANDARD_RTTIEXT (V3d_Trihedron, Standard_Transient) @@ -255,13 +254,13 @@ void V3d_Trihedron::compute() myStructure->GraphicClear (Standard_False); // Create trihedron. - const Standard_Real aScale = myScale * myRatio * THE_INTERNAL_SCALE_FACTOR; - const Standard_Real aCylinderLength = aScale * THE_CYLINDER_LENGTH; - const Standard_Real aCylinderDiametr = aScale * myDiameter; - const Standard_Real aConeDiametr = myIsWireframe ? aCylinderDiametr : (aCylinderDiametr * 2.0); - const Standard_Real aConeLength = aScale * (1.0 - THE_CYLINDER_LENGTH); - const Standard_Real aSphereRadius = aCylinderDiametr * 2.0; - const Standard_Real aRayon = aScale / 30.0; + const Standard_Real aScale = myScale * myRatio * THE_INTERNAL_SCALE_FACTOR; + const Standard_Real aCylinderLength = aScale * THE_CYLINDER_LENGTH; + const Standard_Real aCylinderRadius = aScale * myDiameter; + const Standard_Real aConeRadius = myIsWireframe ? aCylinderRadius : (aCylinderRadius * 2.0); + const Standard_Real aConeLength = aScale * (1.0 - THE_CYLINDER_LENGTH); + const Standard_Real aSphereRadius = aCylinderRadius * 2.0; + const Standard_Real aRayon = aScale / 30.0; { Handle(Graphic3d_Group) aSphereGroup = myStructure->NewGroup(); @@ -284,7 +283,7 @@ void V3d_Trihedron::compute() { gp_Trsf aSphereTransform; aSphereGroup->SetGroupPrimitivesAspect (mySphereShadingAspect->Aspect()); - aSphereGroup->AddPrimitiveArray (StdPrs_ToolSphere::Create (aSphereRadius, myNbFacettes, myNbFacettes, aSphereTransform)); + aSphereGroup->AddPrimitiveArray (Prs3d_ToolSphere::Create (aSphereRadius, myNbFacettes, myNbFacettes, aSphereTransform)); } } @@ -294,13 +293,9 @@ void V3d_Trihedron::compute() for (Standard_Integer anIter = 0; anIter < 3; ++anIter) { Handle(Graphic3d_Group) anAxisGroup = myStructure->NewGroup(); - anAxisGroup->SetGroupPrimitivesAspect (myArrowShadingAspects[anIter]->Aspect()); - - gp_Ax1 aPosition (anAxes[anIter]); - - // Create a tube. if (myIsWireframe) { + // create a tube Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfSegments (2); anArray->AddVertex (0.0f, 0.0f, 0.0f); anArray->AddVertex (anAxes[anIter].Direction().XYZ() * aCylinderLength); @@ -308,35 +303,15 @@ void V3d_Trihedron::compute() anAxisGroup->SetGroupPrimitivesAspect (myArrowLineAspects[anIter]->Aspect()); anAxisGroup->AddPrimitiveArray (anArray); } - else - { - gp_Ax3 aSystem (aPosition.Location(), aPosition.Direction()); - gp_Trsf aTrsf; - aTrsf.SetTransformation (aSystem, gp_Ax3()); - anAxisGroup->AddPrimitiveArray (StdPrs_ToolCylinder::Create (aCylinderDiametr, aCylinderDiametr, aCylinderLength, myNbFacettes, 1, aTrsf)); - } - - aPosition.Translate (gp_Vec (aPosition.Direction().X() * aCylinderLength, - aPosition.Direction().Y() * aCylinderLength, - aPosition.Direction().Z() * aCylinderLength)); - // Create a disk. - { - gp_Ax3 aSystem (aPosition.Location(), aPosition.Direction()); - gp_Trsf aTrsf; - aTrsf.SetTransformation (aSystem, gp_Ax3()); - - anAxisGroup->AddPrimitiveArray (StdPrs_ToolDisk::Create (0.0, aConeDiametr, myNbFacettes, 1, aTrsf)); - } - - // Create a cone. - { - gp_Ax3 aSystem (aPosition.Location(), aPosition.Direction()); - gp_Trsf aTrsf; - aTrsf.SetTransformation (aSystem, gp_Ax3()); - - anAxisGroup->AddPrimitiveArray (StdPrs_ToolCylinder::Create (aConeDiametr, 0.0, aConeLength, myNbFacettes, 1, aTrsf)); - } + Handle(Graphic3d_ArrayOfTriangles) aTriangles = Prs3d_Arrow::DrawShaded (anAxes[anIter], + myIsWireframe ? 0.0 : aCylinderRadius, + aCylinderLength + aConeLength, + aConeRadius, + aConeLength, + myNbFacettes); + anAxisGroup->SetGroupPrimitivesAspect (myArrowShadingAspects[anIter]->Aspect()); + anAxisGroup->AddPrimitiveArray (aTriangles); } }