1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0031570: Samples - add Qt samples similar to standard MFC samples

Added Qt sample OCCTOverview providing examples of use of OCCT API with relevant code and demonstration of results in the viewer.

Off-topic: some unused images are removed from dox/introduction/images/
This commit is contained in:
asuraven
2020-05-26 14:16:46 +03:00
committed by bugmaster
parent 50ae6dad80
commit a2176e6524
142 changed files with 13409 additions and 24 deletions

View File

@@ -0,0 +1,147 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "AdaptorCurve2d_AIS.h"
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_PointAspect.hxx>
#include <StdPrs_PoleCurve.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <Graphic3d_ArrayOfPolylines.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Geom2dLProp_CLProps2d.hxx>
AdaptorCurve2d_AIS::AdaptorCurve2d_AIS (const Handle(Geom2d_Curve)& theGeom2dCurve,
const Aspect_TypeOfLine theTypeOfLine,
const Aspect_WidthOfLine theWidthOfLine)
: myGeom2dCurve (theGeom2dCurve),
myTypeOfLine (theTypeOfLine),
myWidthOfLine (theWidthOfLine),
myDisplayPole (Standard_True),
myDisplayCurbure (Standard_False),
myDiscretisation (20),
myradiusmax (10),
myradiusratio (1)
{
//
}
void AdaptorCurve2d_AIS::Compute (const Handle(PrsMgr_PresentationManager3d)&,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode)
{
if (theMode != 0)
{
return;
}
Geom2dAdaptor_Curve anAdaptor(myGeom2dCurve);
GCPnts_QuasiUniformDeflection anEdgeDistrib(anAdaptor, 1.e-2);
if (anEdgeDistrib.IsDone())
{
Handle(Graphic3d_ArrayOfPolylines) aCurve = new Graphic3d_ArrayOfPolylines(anEdgeDistrib.NbPoints());
for (Standard_Integer i = 1; i <= anEdgeDistrib.NbPoints(); ++i)
{
aCurve->AddVertex(anEdgeDistrib.Value(i));
}
Handle(Graphic3d_Group) aPrsGroup = thePrs->NewGroup();
aPrsGroup->SetGroupPrimitivesAspect(myDrawer->LineAspect()->Aspect());
aPrsGroup->AddPrimitiveArray(aCurve);
}
if (myDisplayPole)
{
if (anAdaptor.GetType() == GeomAbs_BezierCurve)
{
Handle(Geom2d_BezierCurve) aBezier = anAdaptor.Bezier();
Handle(Graphic3d_ArrayOfPolylines) anArrayOfVertex = new Graphic3d_ArrayOfPolylines(aBezier->NbPoles());
for (int i = 1; i <= aBezier->NbPoles(); i++)
{
gp_Pnt2d CurrentPoint = aBezier->Pole(i);
anArrayOfVertex->AddVertex(CurrentPoint.X(), CurrentPoint.Y(), 0.);
}
Handle(Graphic3d_Group) aPrsGroup = thePrs->NewGroup();
aPrsGroup->SetGroupPrimitivesAspect(myDrawer->LineAspect()->Aspect());
aPrsGroup->AddPrimitiveArray(anArrayOfVertex);
}
if (anAdaptor.GetType() == GeomAbs_BSplineCurve)
{
Handle(Geom2d_BSplineCurve) aBSpline = anAdaptor.BSpline();
Handle(Graphic3d_ArrayOfPolylines) anArrayOfVertex = new Graphic3d_ArrayOfPolylines(aBSpline->NbPoles());
for (int i = 1; i <= aBSpline->NbPoles(); i++)
{
gp_Pnt2d CurrentPoint = aBSpline->Pole(i);
anArrayOfVertex->AddVertex(CurrentPoint.X(), CurrentPoint.Y(), 0.);
}
Handle(Graphic3d_Group) aPrsGroup = thePrs->NewGroup();
aPrsGroup->SetGroupPrimitivesAspect(myDrawer->LineAspect()->Aspect());
aPrsGroup->AddPrimitiveArray(anArrayOfVertex);
}
}
if (myDisplayCurbure && (anAdaptor.GetType() != GeomAbs_Line))
{
const Standard_Integer nbintv = anAdaptor.NbIntervals(GeomAbs_CN);
TColStd_Array1OfReal TI(1, nbintv + 1);
anAdaptor.Intervals(TI, GeomAbs_CN);
Standard_Real Resolution = 1.0e-9, Curvature;
Geom2dLProp_CLProps2d LProp(myGeom2dCurve, 2, Resolution);
gp_Pnt2d P1, P2;
Handle(Graphic3d_Group) aPrsGroup = thePrs->NewGroup();
aPrsGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
for (Standard_Integer intrv = 1; intrv <= nbintv; intrv++)
{
Standard_Real t = TI(intrv);
Standard_Real step = (TI(intrv + 1) - t) / GetDiscretisation();
Standard_Real LRad, ratio;
for (Standard_Integer ii = 1; ii <= myDiscretisation; ii++)
{
LProp.SetParameter(t);
if (LProp.IsTangentDefined())
{
Curvature = Abs(LProp.Curvature());
if (Curvature > Resolution)
{
myGeom2dCurve->D0(t, P1);
LRad = 1. / Curvature;
ratio = ((LRad > myradiusmax) ? myradiusmax / LRad : 1);
ratio *= myradiusratio;
LProp.CentreOfCurvature(P2);
gp_Vec2d V(P1, P2);
gp_Pnt2d P3 = P1.Translated(ratio*V);
Handle(Graphic3d_ArrayOfPolylines) aSegment = new Graphic3d_ArrayOfPolylines(2);
aSegment->AddVertex(P1.X(), P1.Y(), 0.);
aSegment->AddVertex(P3.X(), P3.Y(), 0.);
aPrsGroup->AddPrimitiveArray(aSegment);
}
}
t += step;
}
}
}
}

View File

@@ -0,0 +1,77 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef ADAPTOR_CURVE2D_AIS_H
#define ADAPTOR_CURVE2D_AIS_H
#include <AIS_InteractiveObject.hxx>
#include <Geom2d_Curve.hxx>
#include <Aspect_TypeOfLine.hxx>
#include <Aspect_WidthOfLine.hxx>
//! AIS interactive Object for Geom2d_Curve
class AdaptorCurve2d_AIS : public AIS_InteractiveObject
{
DEFINE_STANDARD_RTTI_INLINE(AdaptorCurve2d_AIS, AIS_InteractiveObject)
public:
AdaptorCurve2d_AIS(const Handle(Geom2d_Curve)& theGeom2dCurve,
const Aspect_TypeOfLine theTypeOfline = Aspect_TOL_SOLID,
const Aspect_WidthOfLine theWidthOfLine = Aspect_WOL_MEDIUM);
Standard_Integer NbPossibleSelection() const { return 1; }
Aspect_TypeOfLine GetTypeOfLine() const { return myTypeOfLine; }
void SetTypeOfLine(const Aspect_TypeOfLine aNewTypeOfLine) { myTypeOfLine = aNewTypeOfLine; }
Aspect_WidthOfLine GetWidthOfLine() const { return myWidthOfLine; }
void SetWidthOfLine(const Aspect_WidthOfLine aNewWidthOfLine) { myWidthOfLine = aNewWidthOfLine; }
Standard_Boolean GetDisplayPole() const { return myDisplayPole; }
void SetDisplayPole(const Standard_Boolean aNewDisplayPole) { myDisplayPole = aNewDisplayPole; }
Standard_Boolean GetDisplayCurbure() const { return myDisplayCurbure; }
void SetDisplayCurbure(const Standard_Boolean aNewDisplayCurbure) { myDisplayCurbure = aNewDisplayCurbure; }
Standard_Real GetDiscretisation() const { return myDiscretisation; }
void SetDiscretisation(const Standard_Real aNewDiscretisation) { myDiscretisation = aNewDiscretisation; }
private:
//! Return TRUE for supported display modes (only 0 mode is supported).
virtual Standard_Boolean AcceptDisplayMode(const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
//! Compute presentation.
virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode) Standard_OVERRIDE;
//! Compute selection (not implemented).
virtual void ComputeSelection (const Handle(SelectMgr_Selection)&,
const Standard_Integer) Standard_OVERRIDE {}
private:
Handle(Geom2d_Curve) myGeom2dCurve;
Aspect_TypeOfLine myTypeOfLine;
Aspect_WidthOfLine myWidthOfLine;
Standard_Boolean myDisplayPole;
Standard_Boolean myDisplayCurbure;
Standard_Real myDiscretisation;
Standard_Real myradiusmax;
Standard_Real myradiusratio;
};
#endif

View File

@@ -0,0 +1,49 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "AdaptorCurve_AIS.h"
#include <GeomAdaptor_Curve.hxx>
#include <Prs3d_LineAspect.hxx>
#include <StdPrs_PoleCurve.hxx>
#include <StdPrs_Curve.hxx>
void AdaptorCurve_AIS::Compute (const Handle(PrsMgr_PresentationManager3d)&,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode)
{
GeomAdaptor_Curve anAdaptorCurve(myCurve);
switch (theMode)
{
case 1:
{
Handle(Prs3d_Drawer) aPoleDrawer = new Prs3d_Drawer();
aPoleDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0));
StdPrs_PoleCurve::Add(thePrs, anAdaptorCurve, aPoleDrawer);
}
Standard_FALLTHROUGH
case 0:
{
StdPrs_Curve::Add(thePrs, anAdaptorCurve, myDrawer);
break;
}
}
}

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef ADAPTOR_CURVE_AIS_H
#define ADAPTOR_CURVE_AIS_H
#include <AIS_InteractiveObject.hxx>
#include <Geom_Curve.hxx>
//! AIS interactive Object for Geom_Curve
class AdaptorCurve_AIS : public AIS_InteractiveObject
{
DEFINE_STANDARD_RTTI_INLINE(AdaptorCurve_AIS, AIS_InteractiveObject)
public:
AdaptorCurve_AIS (const Handle(Geom_Curve)& theCurve) : myCurve(theCurve) {}
private:
//! Return TRUE for supported display modes (modes 0 and 1 are supported).
virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0 || theMode == 1; }
//! Compute presentation.
Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode) Standard_OVERRIDE;
//! Compute selection (not implemented).
virtual void ComputeSelection (const Handle(SelectMgr_Selection)&,
const Standard_Integer) Standard_OVERRIDE {}
private:
Handle(Geom_Curve) myCurve;
};
#endif

View File

@@ -0,0 +1,38 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "AdaptorPnt2d_AIS.h"
#include <Geom_CartesianPoint.hxx>
#include <StdPrs_Point.hxx>
void AdaptorPnt2d_AIS::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode)
{
if (theMode != 0)
{
return;
}
Handle(Geom_CartesianPoint) aGeomPoint = new Geom_CartesianPoint(myPoint);
StdPrs_Point::Add (thePrs, aGeomPoint, myDrawer);
}

View File

@@ -0,0 +1,57 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef ADAPTOR_PNT2D_AIS_H
#define ADAPTOR_PNT2D_AIS_H
#include <Geom2d_Point.hxx>
#include <AIS_InteractiveObject.hxx>
//! AIS interactive Object for Geom2d_Point
class AdaptorPnt2d_AIS : public AIS_InteractiveObject
{
DEFINE_STANDARD_RTTI_INLINE(AdaptorPnt2d_AIS, AIS_InteractiveObject)
public:
AdaptorPnt2d_AIS (const Handle(Geom2d_Point)& thePoint,
Standard_Real theElevation = 0)
: myPoint(thePoint->X(), thePoint->Y(), theElevation) {}
private:
//! Return TRUE for supported display modes (only mode 0 is supported).
virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
//! Compute presentation.
virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode) Standard_OVERRIDE;
//! Compute selection (not implemented).
virtual void ComputeSelection (const Handle(SelectMgr_Selection)&,
const Standard_Integer) Standard_OVERRIDE {}
private:
gp_Pnt myPoint;
};
#endif // ADAPTOR_PNT2D_AIS_H

View File

@@ -0,0 +1,77 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "AdaptorVec_AIS.h"
#include <Graphic3d_ArrayOfSegments.hxx>
#include <Prs3d_ArrowAspect.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_Arrow.hxx>
#include <Prs3d_Text.hxx>
AdaptorVec_AIS::AdaptorVec_AIS (const gp_Pnt2d& thePnt1,
const gp_Pnt2d& thePnt2,
Standard_Real theArrowLength)
: myPnt (gp_Pnt (thePnt1.X(), thePnt1.Y(), 0.0)),
myLength (0.0),
myArrowLength (theArrowLength)
{
gp_Vec aVec (thePnt2.X() - thePnt1.X(), thePnt2.Y() - thePnt1.Y(), 0.0);
myDir = gp_Dir(aVec);
myLength = aVec.Magnitude();
}
void AdaptorVec_AIS::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode)
{
if (theMode != 0)
{
return;
}
// Set style for arrow
Handle(Prs3d_ArrowAspect) anArrowAspect = myDrawer->ArrowAspect();
anArrowAspect->SetLength(myArrowLength);
gp_Pnt aLastPoint = myPnt;
aLastPoint.Translate(myLength*gp_Vec(myDir));
// Draw Line
{
Handle(Graphic3d_Group) aLineGroup = thePrs->NewGroup();
aLineGroup->SetGroupPrimitivesAspect (myDrawer->LineAspect()->Aspect());
Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
aPrims->AddVertex(myPnt);
aPrims->AddVertex(aLastPoint);
aLineGroup->AddPrimitiveArray(aPrims);
// Draw arrow
Prs3d_Arrow::Draw (aLineGroup, aLastPoint, myDir, anArrowAspect->Angle(), anArrowAspect->Length());
}
// Draw text
if (!myText.IsEmpty())
{
gp_Pnt aTextPosition = aLastPoint;
Prs3d_Text::Draw (thePrs->NewGroup(), myDrawer->TextAspect(), myText, aTextPosition);
}
}

View File

@@ -0,0 +1,121 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef ADAPTOR_VEC_AIS_H
#define ADAPTOR_VEC_AIS_H
#include <AIS_InteractiveObject.hxx>
//! AIS interactive Object for vector with arrow and text
class AdaptorVec_AIS : public AIS_InteractiveObject
{
DEFINE_STANDARD_RTTI_INLINE(AdaptorVec_AIS, AIS_InteractiveObject)
public:
AdaptorVec_AIS()
: myLength (1.0),
myArrowLength (1.0)
{}
AdaptorVec_AIS (const gp_Pnt& thePnt,
const gp_Dir& theDir,
Standard_Real theLength = 1,
Standard_Real theArrowLength = 1)
: myPnt (thePnt),
myDir (theDir),
myLength (theLength),
myArrowLength (theArrowLength)
{
//
}
AdaptorVec_AIS (const gp_Pnt& thePnt,
const gp_Vec& theVec,
Standard_Real theArrowLength = 1)
: myPnt (thePnt),
myDir (theVec),
myLength (theVec.Magnitude()),
myArrowLength (theArrowLength)
{
//
}
AdaptorVec_AIS (const gp_Pnt2d& thePnt2d,
const gp_Dir2d& theDir2d,
Standard_Real theLength = 1,
Standard_Real theArrowLength = 1)
: myPnt (gp_Pnt(thePnt2d.X(), thePnt2d.Y(), 0.0)),
myDir (gp_Dir(theDir2d.X(), theDir2d.Y(), 0.0)),
myLength (theLength),
myArrowLength (theArrowLength)
{
//
}
AdaptorVec_AIS (const gp_Pnt2d& thePnt2d,
const gp_Vec2d& theVec2d,
Standard_Real theArrowLength = 1)
: myPnt (gp_Pnt(thePnt2d.X(), thePnt2d.Y(), 0.0)),
myDir (gp_Dir(theVec2d.X(), theVec2d.Y(), 0.0)),
myLength (theVec2d.Magnitude()),
myArrowLength (theArrowLength)
{
//
}
AdaptorVec_AIS (const gp_Pnt2d& thePnt1,
const gp_Pnt2d& thePnt2,
Standard_Real theArrowLength = 1);
void SetText (const TCollection_AsciiString& theText)
{
myText = theText;
}
void SetLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
{
myDrawer->SetLineAspect(theAspect);
}
private:
//! Return TRUE for supported display modes (only mode 0 is supported).
virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
//! Compute presentation.
virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode) Standard_OVERRIDE;
//! Compute selection (not implemented).
virtual void ComputeSelection (const Handle(SelectMgr_Selection)&,
const Standard_Integer) Standard_OVERRIDE {}
private:
gp_Pnt myPnt;
gp_Dir myDir;
Standard_Real myLength;
Standard_Real myArrowLength;
TCollection_AsciiString myText;
};
#endif // ADAPTOR_VEC2D_AIS_H

View File

@@ -0,0 +1,185 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "BaseSample.h"
#include <iostream>
#include <regex>
#include <exception>
#include <stack>
#include <AIS_ViewCube.hxx>
#include <Message.hxx>
#include <OSD_File.hxx>
#include <OSD_Path.hxx>
#include <OSD_Protection.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QDir>
#include <Standard_WarningsRestore.hxx>
const TCollection_AsciiString BaseSample::FILE_EXTENSION = "cxx";
void BaseSample::Clear()
{
myObject3d.Clear();
myObject2d.Clear();
myCode.Clear();
myResult.str("");
}
TCollection_AsciiString BaseSample::GetResult()
{
TCollection_AsciiString aResult(myResult.str().c_str());
myResult.str("");
return aResult;
}
void BaseSample::AppendCube()
{
Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube();
myObject3d.Append(aViewCube);
}
void BaseSample::Process (const TCollection_AsciiString& theSampleName)
{
myObject3d.Clear();
myObject2d.Clear();
myCode.Clear();
myIsProcessed = Standard_False;
try
{
ExecuteSample(theSampleName);
if (!myObject3d.IsEmpty())
{
Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube();
myObject3d.Append(aViewCube);
}
}
catch (...)
{
TraceError(TCollection_AsciiString("Error in sample: ") + theSampleName);
}
}
void BaseSample::TraceError (const TCollection_AsciiString& theErrorMessage)
{
Message::SendFail() << "\nERROR: " << theErrorMessage.ToCString() << std::endl;
myResult << "\nERROR: " << theErrorMessage << std::endl;
}
void BaseSample::FindSourceCode (const TCollection_AsciiString& theSampleName)
{
TCollection_AsciiString aClassName = DynamicType()->Name();
char aSeparator = QDir::separator().toLatin1();
TCollection_AsciiString aCxxFilePach = myCodePath + aSeparator + aClassName + '.' + FILE_EXTENSION;
OSD_File aCxxFile(aCxxFilePach);
try
{
const Standard_Integer aFileBufferSize = 100 * 1024;
TCollection_AsciiString aReadedText(aFileBufferSize);
aCxxFile.Open(OSD_ReadOnly, OSD_Protection());
aCxxFile.Read(aReadedText, aFileBufferSize);
TCollection_AsciiString aRegexpTemplate = aClassName + "::" + theSampleName + "[\\n\\s]*\\([\\n\\s]*\\)[\\n\\s]*\\{";
Standard_Integer aOpeningBracketPosition = findEndOfPhrase (aReadedText, aRegexpTemplate);
Standard_Integer aClosingBracketPosition = findClosingBracket (aReadedText, aOpeningBracketPosition, '}');
myCode = aReadedText.SubString(aOpeningBracketPosition + 1, aClosingBracketPosition - 1);
}
catch (...)
{
TraceError(TCollection_AsciiString("Cannot open file: ") + aCxxFilePach);
}
}
Standard_Integer BaseSample::findEndOfPhrase (const TCollection_AsciiString& theText,
const TCollection_AsciiString& theRegexpTemplate)
{
Standard_Integer aIndexOfLastFoundSymbol = -1;
std::string aStdText = theText.ToCString();
std::string aRegexpTemplate = theRegexpTemplate.ToCString();
try
{
std::regex aRegex(theRegexpTemplate.ToCString());
std::sregex_iterator aDetectIterator = std::sregex_iterator(aStdText.begin(), aStdText.end(), aRegex);
if (aDetectIterator != std::sregex_iterator())
{
std::smatch aMatch = *aDetectIterator;
std::string aFoundString = aMatch.str();
aIndexOfLastFoundSymbol = static_cast<Standard_Integer>(aStdText.find(aFoundString) + aFoundString.length());
}
else
{
TraceError(TCollection_AsciiString("No code found for template: ") + theRegexpTemplate);
}
}
catch (const std::regex_error& aRegError)
{
TraceError(TCollection_AsciiString("regex_error: ") + aRegError.what());
}
catch (const std::exception& aEx)
{
TraceError(TCollection_AsciiString("common error: ") + aEx.what());
}
catch (...)
{
TraceError("unknown error!");
}
return aIndexOfLastFoundSymbol;
}
Standard_Integer BaseSample::findClosingBracket (const TCollection_AsciiString& theText,
const Standard_Integer theOpeningBracketIndex,
Standard_Character theClosingBracketSymbol)
{
// TODO this function not implemented at least 2 cases:
// - brackets in strings & chars
// - brackets in comments
Standard_Integer aClosingBracketIndex = -1;
Standard_Character anOpeningBracketSymbol = theText.Value(theOpeningBracketIndex);
TCollection_AsciiString aBracketsSet(theClosingBracketSymbol);
aBracketsSet += anOpeningBracketSymbol;
Standard_Integer aBracketDepth = 1;
Standard_Integer aStartFindIndex = theOpeningBracketIndex + 1;
//Standard_Character aStartFindChar = theText.Value(aStartFindIndex-1);
while (aBracketDepth)
{
aStartFindIndex = theText.FirstLocationInSet(aBracketsSet, aStartFindIndex, theText.Length());
if (!aStartFindIndex)
{
TraceError("No closing bracket found!");
break;
}
TCollection_AsciiString aRSubstr = theText.SubString(aStartFindIndex, theText.Length());
if (theText.Value(aStartFindIndex) == anOpeningBracketSymbol)
aBracketDepth++;
else if (theText.Value(aStartFindIndex) == theClosingBracketSymbol)
aBracketDepth--;
if (!aBracketDepth)
{
aClosingBracketIndex = aStartFindIndex;
break;
}
aStartFindIndex++;
}
return aClosingBracketIndex;
}

View File

@@ -0,0 +1,87 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef BASESAMPLE_H
#define BASESAMPLE_H
#include <sstream>
#include <AIS_InteractiveObject.hxx>
#include <NCollection_Vector.hxx>
#include <TCollection_AsciiString.hxx>
//! Base class for specified category classes
class BaseSample: public Standard_Transient
{
DEFINE_STANDARD_RTTI_INLINE(BaseSample, Standard_Transient)
public:
BaseSample (const TCollection_AsciiString& theSampleSourcePath,
const Handle(AIS_InteractiveContext)& theContext)
: myCodePath (theSampleSourcePath),
myContext (theContext)
{
//
}
void Clear();
void AppendCube();
Standard_Boolean IsProcessed() const { return myIsProcessed; }
const NCollection_Vector<Handle(AIS_InteractiveObject)>& Get2dObjects() const { return myObject2d; }
const NCollection_Vector<Handle(AIS_InteractiveObject)>& Get3dObjects() const { return myObject3d; }
TCollection_AsciiString GetResult();
TCollection_AsciiString GetCode() const { return myCode; }
virtual void Process (const TCollection_AsciiString& theSampleName);
protected:
virtual void ExecuteSample (const TCollection_AsciiString& theSampleName) = 0;
void FindSourceCode (const TCollection_AsciiString& theSampleName);
void TraceError (const TCollection_AsciiString& theErrorMessage);
protected:
Standard_Boolean myIsProcessed;
NCollection_Vector<Handle(AIS_InteractiveObject)> myObject2d;
NCollection_Vector<Handle(AIS_InteractiveObject)> myObject3d;
std::ostringstream myResult;
TCollection_AsciiString myCode;
TCollection_AsciiString myCodePath;
Handle(AIS_InteractiveContext) myContext;
protected:
static const TCollection_AsciiString FILE_EXTENSION;
private:
Standard_Integer findEndOfPhrase (const TCollection_AsciiString& theText,
const TCollection_AsciiString& theRegexpTemplate);
Standard_Integer findClosingBracket (const TCollection_AsciiString& theText,
Standard_Integer theOpeningBracketIndex,
Standard_Character theClosingBracketSymbol);
};
#endif //BASESAMPLE_H

View File

@@ -0,0 +1,51 @@
{
"Data Exchange": {
"Export": [{
"text": "BREP",
"function": "BrepExportSample",
"description": ""
},
{
"text": "STEP",
"function": "StepExportSample",
"description": ""
},
{
"text": "IGES",
"function": "IgesExportSample",
"description": ""
},
{
"text": "STL",
"function": "StlExportSample",
"description": ""
},
{
"text": "VRML",
"function": "VrmlExportSample",
"description": ""
},
{
"text": "Image",
"function": "ImageExportSample",
"description": ""
}
],
"Import": [{
"text": "BREP",
"function": "BrepImportSample",
"description": ""
},
{
"text": "STEP",
"function": "StepImportSample",
"description": ""
},
{
"text": "IGES",
"function": "IgesImportSample",
"description": ""
}
]
}
}

View File

@@ -0,0 +1,410 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "DataExchangeSamples.h"
#include "MakeBottle.h"
#include <AIS_ViewCube.hxx>
#include <AIS_Shape.hxx>
#include <BRepTools.hxx>
#include <BRep_Tool.hxx>
#include <BRep_Builder.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Line.hxx>
#include <Graphic3d_TextureEnv.hxx>
#include <IFSelect_ReturnStatus.hxx>
#include <IGESControl_Controller.hxx>
#include <IGESControl_Reader.hxx>
#include <IGESControl_Writer.hxx>
#include <Interface_Static.hxx>
#include <STEPControl_Reader.hxx>
#include <STEPControl_Writer.hxx>
#include <StlAPI_Writer.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Compound.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <VrmlAPI_Writer.hxx>
void DataExchangeSamples::Process (const TCollection_AsciiString& theSampleName)
{
if (IsImportSample(theSampleName))
{
myObject3d.Clear();
}
myObject2d.Clear();
myCode.Clear();
myIsProcessed = Standard_False;
try
{
ExecuteSample(theSampleName);
}
catch (...)
{
TraceError(TCollection_AsciiString("Error in sample: ") + theSampleName);
}
}
void DataExchangeSamples::AppendBottle()
{
TopoDS_Shape aBottle = MakeBottle(50, 70, 30);
Handle(AIS_InteractiveObject) aShape = new AIS_Shape(aBottle);
myObject3d.Append(aShape);
Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube();
myObject3d.Append(aViewCube);
myResult << "A bottle shape was created." << std::endl;
}
void DataExchangeSamples::ExecuteSample (const TCollection_AsciiString& theSampleName)
{
Standard_Boolean anIsSamplePresent = Standard_True;
FindSourceCode(theSampleName);
if (theSampleName == "BrepExportSample")
{
BrepExportSample();
}
else if (theSampleName == "StepExportSample")
{
StepExportSample();
}
else if (theSampleName == "IgesExportSample")
{
IgesExportSample();
}
else if (theSampleName == "StlExportSample")
{
StlExportSample();
}
else if (theSampleName == "VrmlExportSample")
{
VrmlExportSample();
}
else if (theSampleName == "ImageExportSample")
{
ImageExportSample();
}
else if (theSampleName == "BrepImportSample")
{
BrepImportSample();
}
else if (theSampleName == "StepImportSample")
{
StepImportSample();
}
else if (theSampleName == "IgesImportSample")
{
IgesImportSample();
}
else
{
myResult << "No function found: " << theSampleName;
myCode += TCollection_AsciiString("No function found: ") + theSampleName;
anIsSamplePresent = Standard_False;
}
myIsProcessed = anIsSamplePresent;
}
void DataExchangeSamples::BrepExportSample()
{
Standard_Boolean anIsShapeExist = Standard_False;
for (Handle(AIS_InteractiveObject) anObject : myObject3d)
{
if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anObject))
{
anIsShapeExist = Standard_True;
if (BRepTools::Write(aShape->Shape(), myFileName.ToCString()))
{
myResult << "A shape was successfully written" << std::endl;
}
else
{
myResult << "A shape was not written" << std::endl;
}
break; // write only one shape
}
}
if (!anIsShapeExist)
{
myResult << "A shape does not exist" << std::endl;
}
}
void DataExchangeSamples::StepExportSample()
{
if (myStepType < 0)
{
myResult << "Unknown step type" << std::endl;
return;
}
IFSelect_ReturnStatus aStatus;
if (myStepType == STEPControl_FacetedBrep && !CheckFacetedBrep())
{
myResult << "At least one shape doesn't contain facets" << std::endl;
return;
}
STEPControl_Writer aStepWriter;
for (Handle(AIS_InteractiveObject) anObject : myObject3d)
{
if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anObject))
{
aStatus = aStepWriter.Transfer(aShape->Shape(), myStepType);
if (aStatus != IFSelect_RetDone)
{
myResult << "A shape was not transferred successfully" << std::endl;
return;
}
}
}
aStatus = aStepWriter.Write(myFileName.ToCString());
switch (aStatus)
{
case IFSelect_RetError:
myResult << "Incorrect Data." << std::endl;
break;
case IFSelect_RetFail:
myResult << "Writing error" << std::endl;
break;
case IFSelect_RetVoid:
myResult << "Nothing to transfer." << std::endl;
break;
case IFSelect_RetStop:
case IFSelect_RetDone:
myResult << "A STEP file was successfully written" << std::endl;
break;
}
}
void DataExchangeSamples::IgesExportSample()
{
IGESControl_Controller::Init();
IGESControl_Writer anIgesWriter(Interface_Static::CVal("XSTEP.iges.unit"),
Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
Standard_Boolean anIsShapeExist = Standard_False;
for (Handle(AIS_InteractiveObject) anObject : myObject3d)
{
if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anObject))
{
anIsShapeExist = Standard_True;
anIgesWriter.AddShape(aShape->Shape());
}
}
if (anIsShapeExist)
{
anIgesWriter.ComputeModel();
if (anIgesWriter.Write(myFileName.ToCString()))
{
myResult << "A STEP file was successfully written" << std::endl;
}
else
{
myResult << "A STEP file was not written" << std::endl;
}
}
else
{
myResult << "Shapes do not exist" << std::endl;
}
}
void DataExchangeSamples::StlExportSample()
{
TopoDS_Compound aTopoCompound;
BRep_Builder aBuilder;
aBuilder.MakeCompound(aTopoCompound);
Standard_Boolean anIsShapeExist = Standard_False;
for (Handle(AIS_InteractiveObject) anObject : myObject3d)
{
if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anObject))
{
anIsShapeExist = Standard_True;
aBuilder.Add(aTopoCompound, aShape->Shape());
}
}
if (anIsShapeExist)
{
StlAPI_Writer aStlWriter;
if (aStlWriter.Write(aTopoCompound, myFileName.ToCString()))
{
myResult << "A STL file was successfully written" << std::endl;
}
else
{
myResult << "A STL file was not written" << std::endl;
}
}
else
{
myResult << "Shapes do not exist" << std::endl;
}
}
void DataExchangeSamples::VrmlExportSample()
{
TopoDS_Compound aTopoCompound;
BRep_Builder aBrepBuilder;
aBrepBuilder.MakeCompound(aTopoCompound);
Standard_Boolean anIsShapeExist = Standard_False;
for (Handle(AIS_InteractiveObject) anObject : myObject3d)
{
if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anObject))
{
anIsShapeExist = Standard_True;
aBrepBuilder.Add(aTopoCompound, aShape->Shape());
}
}
if (anIsShapeExist)
{
VrmlAPI_Writer aVrmlWriter;
if (aVrmlWriter.Write(aTopoCompound, myFileName.ToCString()))
{
myResult << "A VRML file was successfully written" << std::endl;
}
else
{
myResult << "A VRML file was not written" << std::endl;
}
}
else
{
myResult << "Shapes do not exist" << std::endl;
}
}
void DataExchangeSamples::ImageExportSample()
{
if (myView)
{
Standard_Boolean aResult = myView->Dump(myFileName.ToCString());
if (aResult)
{
myResult << "An image file was successfully written" << std::endl;
}
else
{
myResult << "An image file was not written" << std::endl;
}
}
}
void DataExchangeSamples::BrepImportSample()
{
TopoDS_Shape aTopoShape;
BRep_Builder aBuilder;
Standard_Boolean aResult = BRepTools::Read(aTopoShape, myFileName.ToCString(), aBuilder);
if (aResult)
{
Handle(AIS_Shape) anAisShape = new AIS_Shape(aTopoShape);
myObject3d.Append(anAisShape);
myResult << "A BREP file was read successfully" << std::endl;
}
else
{
myResult << "A BREP file was not read successfully" << std::endl;
}
}
void DataExchangeSamples::StepImportSample()
{
Handle(TopTools_HSequenceOfShape) aSequence = new TopTools_HSequenceOfShape();
STEPControl_Reader aReader;
const IFSelect_ReturnStatus aStatus = aReader.ReadFile(myFileName.ToCString());
if (aStatus != IFSelect_RetDone)
{
myResult << "A BREP file was not read successfully" << std::endl;
return;
}
bool anIsFailsOnly = false;
aReader.PrintCheckLoad(anIsFailsOnly, IFSelect_ItemsByEntity);
int aRootsNumber = aReader.NbRootsForTransfer();
aReader.PrintCheckTransfer(anIsFailsOnly, IFSelect_ItemsByEntity);
for (Standard_Integer i = 1; i <= aRootsNumber; i++)
{
aReader.TransferRoot(i);
}
int aShapesNumber = aReader.NbShapes();
for (int i = 1; i <= aShapesNumber; i++)
{
TopoDS_Shape aTopoShape = aReader.Shape(i);
Handle(AIS_Shape) anAisShape = new AIS_Shape(aTopoShape);
myObject3d.Append(anAisShape);
}
myResult << "A STEP file was read successfully" << std::endl;
}
void DataExchangeSamples::IgesImportSample()
{
IGESControl_Reader aReader;
int status = aReader.ReadFile (myFileName.ToCString());
if (status != IFSelect_RetDone)
{
myResult << "A IGES file was not read successfully" << std::endl;
return;
}
aReader.TransferRoots();
TopoDS_Shape aTopoShape = aReader.OneShape();
Handle(AIS_Shape) anAisShape = new AIS_Shape (aTopoShape);
myObject3d.Append(anAisShape);
myResult << "A IGES file was read successfully" << std::endl;
}
Standard_Boolean DataExchangeSamples::CheckFacetedBrep()
{
Standard_Boolean anError = Standard_False;
for (Handle(AIS_InteractiveObject) anObject : myObject3d)
{
if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anObject))
{
const TopoDS_Shape aTopoShape = aShape->Shape();
for (TopExp_Explorer aFaceExplorer(aTopoShape, TopAbs_FACE); aFaceExplorer.More() && !anError; aFaceExplorer.Next())
{
Handle(Geom_Surface) aSurface = BRep_Tool::Surface(TopoDS::Face(aFaceExplorer.Current()));
if (!aSurface->IsKind(STANDARD_TYPE(Geom_Plane)))
{
anError = Standard_True;
}
}
for (TopExp_Explorer anEdgeExplorer(aTopoShape, TopAbs_EDGE); anEdgeExplorer.More() && !anError; anEdgeExplorer.Next())
{
Standard_Real fd, ld;
Handle(Geom_Curve) curve = BRep_Tool::Curve(TopoDS::Edge(anEdgeExplorer.Current()), fd, ld);
if (!curve->IsKind(STANDARD_TYPE(Geom_Line)))
{
anError = Standard_True;
}
}
}
}
return !anError;
}

View File

@@ -0,0 +1,90 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef DATAEXCHANGESAMPLES_H
#define DATAEXCHANGESAMPLES_H
#include "BaseSample.h"
#include <STEPControl_StepModelType.hxx>
#include <V3d_View.hxx>
//! Implements Data Exchange samples
class DataExchangeSamples : public BaseSample
{
DEFINE_STANDARD_RTTI_INLINE(DataExchangeSamples, BaseSample)
public:
DataExchangeSamples (const TCollection_AsciiString& theSampleSourcePath,
const Handle(V3d_View)& theView,
const Handle(AIS_InteractiveContext)& theContext)
: BaseSample (theSampleSourcePath, theContext),
myStepType (STEPControl_StepModelType::STEPControl_AsIs),
myView (theView)
{
//
}
virtual void Process (const TCollection_AsciiString& theSampleName) Standard_OVERRIDE;
void AppendBottle();
void SetFileName(TCollection_AsciiString theFileName) { myFileName = theFileName; };
void SetStepType(STEPControl_StepModelType theStepType) { myStepType = theStepType; };
static Standard_Boolean IsExportSample(const TCollection_AsciiString& theSampleName) { return theSampleName == "BrepExportSample"
|| theSampleName == "StepExportSample"
|| theSampleName == "IgesExportSample"
|| theSampleName == "StlExportSample"
|| theSampleName == "VrmlExportSample"
|| theSampleName == "ImageExportSample"; }
static Standard_Boolean IsImportSample(const TCollection_AsciiString& theSampleName) { return theSampleName == "BrepImportSample"
|| theSampleName == "StepImportSample"
|| theSampleName == "IgesImportSample"; }
static Standard_Boolean IsBrepSample (const TCollection_AsciiString& theSampleName) { return theSampleName == "BrepExportSample" || theSampleName == "BrepImportSample"; }
static Standard_Boolean IsStepSample (const TCollection_AsciiString& theSampleName) { return theSampleName == "StepExportSample" || theSampleName == "StepImportSample"; }
static Standard_Boolean IsIgesSample (const TCollection_AsciiString& theSampleName) { return theSampleName == "IgesExportSample" || theSampleName == "IgesImportSample"; }
static Standard_Boolean IsStlSample (const TCollection_AsciiString& theSampleName) { return theSampleName == "StlExportSample"; }
static Standard_Boolean IsVrmlSample (const TCollection_AsciiString& theSampleName) { return theSampleName == "VrmlExportSample"; }
static Standard_Boolean IsImageSample (const TCollection_AsciiString& theSampleName) { return theSampleName == "ImageExportSample"; }
protected:
virtual void ExecuteSample (const TCollection_AsciiString& theSampleName) Standard_OVERRIDE;
private:
TCollection_AsciiString myFileName;
STEPControl_StepModelType myStepType;
Handle(V3d_View) myView;
private:
Standard_Boolean CheckFacetedBrep();
// One function for every sample
void BrepExportSample();
void StepExportSample();
void IgesExportSample();
void StlExportSample();
void VrmlExportSample();
void ImageExportSample();
void BrepImportSample();
void StepImportSample();
void IgesImportSample();
};
#endif //DATAEXCHANGESAMPLES_H

View File

@@ -0,0 +1,48 @@
AdaptorCurve2d_AIS.cxx
AdaptorCurve2d_AIS.h
AdaptorCurve_AIS.cxx
AdaptorCurve_AIS.h
AdaptorPnt2d_AIS.cxx
AdaptorPnt2d_AIS.h
AdaptorVec_AIS.cxx
AdaptorVec_AIS.h
BaseSample.cxx
BaseSample.h
DataExchange.json
DataExchangeSamples.cxx
DataExchangeSamples.h
Geometry.json
GeometrySamples.cxx
GeometrySamples.h
MakeBottle.cxx
MakeBottle.h
Ocaf.json
OcafSamples.cxx
OcafSamples.h
Sample2D_Face.cxx
Sample2D_Face.h
Sample2D_Image.cxx
Sample2D_Image.h
Sample2D_Markers.cxx
Sample2D_Markers.h
Samples.qrc
TOcafFunction_BoxDriver.cxx
TOcafFunction_BoxDriver.h
TOcafFunction_CutDriver.cxx
TOcafFunction_CutDriver.h
TOcafFunction_CylDriver.cxx
TOcafFunction_CylDriver.h
TOcaf_Application.cxx
TOcaf_Application.h
Topology.json
TopologySamples.cxx
TopologySamples.h
Triangulation.json
TriangulationSamples.cxx
TriangulationSamples.h
Viewer2d.json
Viewer2dSamples.cxx
Viewer2dSamples.h
Viewer3d.json
Viewer3dSamples.cxx
Viewer3dSamples.h

View File

@@ -0,0 +1,287 @@
{
"Non Parametric": {
"Free creating": {
"3D": [{
"text": "Zero Dimension objects",
"function": "ZeroDimensionObjects3dSample",
"description": ""
},
{
"text": "Vectors",
"function": "Vectors3dSample",
"description": ""
},
{
"text": "Infinity lines",
"function": "InfinityLines3dSample",
"description": ""
},
{
"text": "Second order curves",
"function": "SecondOrderCurves3dSample",
"description": ""
},
{
"text": "Plane surfaces",
"function": "PlaneSurfaces3dSample",
"description": ""
},
{
"text": "Second order surfaces",
"function": "SecondOrderSurfaces3dSample",
"description": ""
}
],
"2D": [{
"text": "Zero Dimension objects",
"function": "ZeroDimensionObjects2dSample",
"description": ""
},
{
"text": "Vectors",
"function": "Vectors2dSample",
"description": ""
},
{
"text": "Infinity lines",
"function": "InfinityLines2dSample",
"description": ""
},
{
"text": "Second order curves",
"function": "SecondOrderCurves2dSample",
"description": ""
}
]
}
,
"Creating based on criteria": {
"3D": [{
"text": "Barycenter point",
"function": "BarycenterPoint3dSample",
"description": ""
},
{
"text": "Rotated vector",
"function": "RotatedVector3dSample",
"description": ""
},
{
"text": "Mirrored line",
"function": "MirroredLine3dSample",
"description": ""
},
{
"text": "Scaled Ellipse",
"function": "ScaledEllipse3dSample",
"description": ""
},
{
"text": "Transformed cylinder",
"function": "TransformedCylinder3dSample",
"description": ""
},
{
"text": "Translated torus",
"function": "TranslatedTorus3dSample",
"description": ""
},
{
"text": "Conjugate objects ",
"function": "ConjugateObjects3dSample",
"description": ""
},
{
"text": "Projection of point",
"function": "ProjectionOfPoint3dSample",
"description": ""
},
{
"text": "Minimal distance",
"function": "MinimalDistance3dSample",
"description": ""
},
{
"text": "Intersection",
"function": "Intersection3dSample",
"description": ""
}
],
"2D": [{
"text": "Translated point",
"function": "TranslatedPoint2dSample",
"description": ""
},
{
"text": "Rotated direction",
"function": "RotatedDirection2dSample",
"description": ""
},
{
"text": "Mirrored axis",
"function": "MirroredAxis2dSample",
"description": ""
},
{
"text": "Transformed ellipse",
"function": "TransformedEllipse2dSample",
"description": ""
},
{
"text": "Conjugate objects",
"function": "ConjugateObjects2dSample",
"description": ""
},
{
"text": "Tangent to 2 cilcles",
"function": "Tangent2dSample",
"description": ""
},
{
"text": "Projection of point",
"function": "ProjectionOfPoint2dSample",
"description": ""
},
{
"text": "Minimal distance",
"function": "MinimalDistance2dSample",
"description": ""
},
{
"text": "Intersection",
"function": "Intersection2dSample",
"description": ""
}
]
},
"Data extraction": {
"3D": [{
"text": "Point info",
"function": "PointInfo3dSample",
"description": ""
},
{
"text": "Ellipse info",
"function": "EllipseInfo3dSample",
"description": ""
}
],
"2D": [{
"text": "Point info",
"function": "PointInfo2dSample",
"description": ""
},
{
"text": "Circle info",
"function": "CircleInfo2dSample",
"description": ""
}
]
}
},
"Parametric": {
"Free creating": {
"3D": [{
"text": "Free style curves",
"function": "FreeStyleCurves3dSample",
"description": ""
},
{
"text": "Analytical surfaces",
"function": "AnalyticalSurfaces3dSample",
"description": ""
},
{
"text": "Free style surfaces",
"function": "FreeStyleSurfaces3dSample",
"description": ""
}
],
"2D": [{
"text": "Free style curves",
"function": "FreeStyleCurves2dSample",
"description": ""
}
]
},
"Creating based on geometry": {
"3D": [{
"text": "Trimmed curve",
"function": "TrimmedCurve3dSample",
"description": ""
},
{
"text": "Offset curve",
"function": "OffsetCurve3dSample",
"description": ""
},
{
"text": "BSpline from circle",
"function": "BSplineFromCircle3dSample",
"description": ""
},
{
"text": "Trimmed surface",
"function": "TrimmedSurface3dSample",
"description": ""
},
{
"text": "Offset surface",
"function": "OffsetSurface3dSample",
"description": ""
},
{
"text": "Extrusion surface",
"function": "ExtrusionSurface3dSample",
"description": ""
},
{
"text": "Revolution surface",
"function": "RevolutionSurface3dSample",
"description": ""
}
],
"2D": [{
"text": "Trimmed curve",
"function": "TrimmedCurve2dSample",
"description": ""
},
{
"text": "Offset curve",
"function": "OffsetCurve2dSample",
"description": ""
}
]
},
"Extract geometry": [{
"text": "Bounding box of surface (3D)",
"function": "BoundingBoxOfSurface3dSample",
"description": ""
},
{
"text": "Bounding box of curves (3D)",
"function": "BoundingBoxOfCurves3dSample",
"description": ""
},
{
"text": "Bounding box of curves (2D)",
"function": "BoundingBoxOfCurves2dSample",
"description": ""
}
],
"Data extraction": [{
"text": "Dump circle info",
"function": "DumpCircleInfoSample",
"description": ""
},
{
"text": "Dump BSpline curve info",
"function": "DumpBSplineCurveInfoSample",
"description": ""
}
]
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,102 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef GEOMETRYSAMPLES_H
#define GEOMETRYSAMPLES_H
#include "BaseSample.h"
//! Implements Geometry samples
class GeometrySamples : public BaseSample
{
DEFINE_STANDARD_RTTI_INLINE(GeometrySamples, BaseSample)
public:
GeometrySamples (const TCollection_AsciiString& theSampleSourcePath,
const Handle(AIS_InteractiveContext)& theContext)
: BaseSample(theSampleSourcePath, theContext) {}
protected:
virtual void ExecuteSample (const TCollection_AsciiString& theSampleName) Standard_OVERRIDE;
private:
void DisplayPnt (const gp_Pnt& thePnt, const TCollection_AsciiString& theText,
Aspect_TypeOfMarker theMarker = Aspect_TOM_PLUS,
Standard_Real theDistance = 5.0);
void DisplayPnt (const gp_Pnt2d& thePnt2d, const TCollection_AsciiString& theText,
Aspect_TypeOfMarker theMarker = Aspect_TOM_PLUS,
Standard_Real theDistance = 5.0);
// One function for every sample
void ZeroDimensionObjects3dSample();
void Vectors3dSample();
void InfinityLines3dSample();
void SecondOrderCurves3dSample();
void PlaneSurfaces3dSample();
void SecondOrderSurfaces3dSample();
void ZeroDimensionObjects2dSample();
void Vectors2dSample();
void InfinityLines2dSample();
void SecondOrderCurves2dSample();
void BarycenterPoint3dSample();
void RotatedVector3dSample();
void MirroredLine3dSample();
void ScaledEllipse3dSample();
void TransformedCylinder3dSample();
void TranslatedTorus3dSample();
void ConjugateObjects3dSample();
void ProjectionOfPoint3dSample();
void MinimalDistance3dSample();
void Intersection3dSample();
void TranslatedPoint2dSample();
void RotatedDirection2dSample();
void MirroredAxis2dSample();
void TransformedEllipse2dSample();
void ConjugateObjects2dSample();
void Tangent2dSample();
void ProjectionOfPoint2dSample();
void MinimalDistance2dSample();
void Intersection2dSample();
void PointInfo3dSample();
void EllipseInfo3dSample();
void PointInfo2dSample();
void CircleInfo2dSample();
void FreeStyleCurves3dSample();
void AnalyticalSurfaces3dSample();
void FreeStyleSurfaces3dSample();
void FreeStyleCurves2dSample();
void TrimmedCurve3dSample();
void OffsetCurve3dSample();
void BSplineFromCircle3dSample();
void TrimmedSurface3dSample();
void OffsetSurface3dSample();
void ExtrusionSurface3dSample();
void RevolutionSurface3dSample();
void TrimmedCurve2dSample();
void OffsetCurve2dSample();
void BoundingBoxOfSurface3dSample();
void BoundingBoxOfCurves3dSample();
void BoundingBoxOfCurves2dSample();
void DumpCircleInfoSample();
void DumpBSplineCurveInfoSample();
};
#endif //GEOMETRYSAMPLES_H

View File

@@ -0,0 +1,218 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "MakeBottle.h"
#include <BRep_Tool.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <BRepLib.hxx>
#include <BRepOffsetAPI_MakeThickSolid.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <GC_MakeSegment.hxx>
#include <GCE2d_MakeSegment.hxx>
#include <gp.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax2d.hxx>
#include <gp_Dir.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Trsf.hxx>
#include <gp_Vec.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom2d_Ellipse.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Compound.hxx>
#include <TopTools_ListOfShape.hxx>
TopoDS_Shape MakeBottle (const Standard_Real theWidth,
const Standard_Real theHeight,
const Standard_Real theThickness)
{
// Profile : Define Support Points
gp_Pnt aPnt1(-theWidth / 2., 0, 0);
gp_Pnt aPnt2(-theWidth / 2., -theThickness / 4., 0);
gp_Pnt aPnt3(0, -theThickness / 2., 0);
gp_Pnt aPnt4(theWidth / 2., -theThickness / 4., 0);
gp_Pnt aPnt5(theWidth / 2., 0, 0);
// Profile : Define the Geometry
Handle(Geom_TrimmedCurve) anArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4);
Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(aPnt1, aPnt2);
Handle(Geom_TrimmedCurve) aSegment2 = GC_MakeSegment(aPnt4, aPnt5);
// Profile : Define the Topology
TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aSegment1);
TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(anArcOfCircle);
TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aSegment2);
TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge1, anEdge2, anEdge3);
// Complete Profile
gp_Ax1 xAxis = gp::OX();
gp_Trsf aTrsf;
aTrsf.SetMirror(xAxis);
BRepBuilderAPI_Transform aBRepTrsf(aWire, aTrsf);
TopoDS_Shape aMirroredShape = aBRepTrsf.Shape();
TopoDS_Wire aMirroredWire = TopoDS::Wire(aMirroredShape);
BRepBuilderAPI_MakeWire mkWire;
mkWire.Add(aWire);
mkWire.Add(aMirroredWire);
TopoDS_Wire myWireProfile = mkWire.Wire();
// Body : Prism the Profile
TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile);
gp_Vec aPrismVec(0, 0, theHeight);
TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec);
// Body : Apply Fillets
BRepFilletAPI_MakeFillet mkFillet(myBody);
TopExp_Explorer anEdgeExplorer(myBody, TopAbs_EDGE);
while (anEdgeExplorer.More())
{
TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExplorer.Current());
//Add edge to fillet algorithm
mkFillet.Add(theThickness / 12., anEdge);
anEdgeExplorer.Next();
}
myBody = mkFillet.Shape();
// Body : Add the Neck
gp_Pnt neckLocation(0, 0, theHeight);
gp_Dir neckAxis = gp::DZ();
gp_Ax2 neckAx2(neckLocation, neckAxis);
Standard_Real myNeckRadius = theThickness / 4.;
Standard_Real myNeckHeight = theHeight / 10.;
BRepPrimAPI_MakeCylinder MKCylinder(neckAx2, myNeckRadius, myNeckHeight);
TopoDS_Shape myNeck = MKCylinder.Shape();
myBody = BRepAlgoAPI_Fuse(myBody, myNeck);
// Body : Create a Hollowed Solid
TopoDS_Face faceToRemove;
Standard_Real zMax = -1;
for (TopExp_Explorer aFaceExplorer(myBody, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next())
{
TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current());
// Check if <aFace> is the top face of the bottle<6C>s neck
Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
if (aSurface->DynamicType() == STANDARD_TYPE(Geom_Plane))
{
Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurface);
gp_Pnt aPnt = aPlane->Location();
Standard_Real aZ = aPnt.Z();
if (aZ > zMax)
{
zMax = aZ;
faceToRemove = aFace;
}
}
}
TopTools_ListOfShape facesToRemove;
facesToRemove.Append(faceToRemove);
BRepOffsetAPI_MakeThickSolid aSolidMaker;
aSolidMaker.MakeThickSolidByJoin(myBody, facesToRemove, -theThickness / 50, 1.e-3);
myBody = aSolidMaker.Shape();
// Threading : Create Surfaces
Handle(Geom_CylindricalSurface) aCyl1 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 0.99);
Handle(Geom_CylindricalSurface) aCyl2 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 1.05);
// Threading : Define 2D Curves
gp_Pnt2d aPnt(2. * M_PI, myNeckHeight / 2.);
gp_Dir2d aDir(2. * M_PI, myNeckHeight / 4.);
gp_Ax2d anAx2d(aPnt, aDir);
Standard_Real aMajor = 2. * M_PI;
Standard_Real aMinor = myNeckHeight / 10;
Handle(Geom2d_Ellipse) anEllipse1 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor);
Handle(Geom2d_Ellipse) anEllipse2 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4);
Handle(Geom2d_TrimmedCurve) anArc1 = new Geom2d_TrimmedCurve(anEllipse1, 0, M_PI);
Handle(Geom2d_TrimmedCurve) anArc2 = new Geom2d_TrimmedCurve(anEllipse2, 0, M_PI);
gp_Pnt2d anEllipsePnt1 = anEllipse1->Value(0);
gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(M_PI);
Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2);
// Threading : Build Edges and Wires
TopoDS_Edge anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1);
TopoDS_Edge anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment, aCyl1);
TopoDS_Edge anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2);
TopoDS_Edge anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment, aCyl2);
TopoDS_Wire threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1, anEdge2OnSurf1);
TopoDS_Wire threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2, anEdge2OnSurf2);
BRepLib::BuildCurves3d(threadingWire1);
BRepLib::BuildCurves3d(threadingWire2);
// Create Threading
BRepOffsetAPI_ThruSections aTool(Standard_True);
aTool.AddWire(threadingWire1);
aTool.AddWire(threadingWire2);
aTool.CheckCompatibility(Standard_False);
TopoDS_Shape myThreading = aTool.Shape();
// Building the Resulting Compound
TopoDS_Compound aRes;
BRep_Builder aBuilder;
aBuilder.MakeCompound(aRes);
aBuilder.Add(aRes, myBody);
aBuilder.Add(aRes, myThreading);
return aRes;
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef MAKEBOTTLE_H
#define MAKEBOTTLE_H
#include <Standard_Macro.hxx>
#include <TopoDS_Shape.hxx>
//! Returns sample bottle TopoDS_Shape
TopoDS_Shape MakeBottle(const Standard_Real theWidth,
const Standard_Real theyHeight,
const Standard_Real theThickness);
#endif // MAKEBOTTLE_H

View File

@@ -0,0 +1,53 @@
{
"OCAF": {
"1 Create": [{
"text": "Create Box",
"function": "CreateBoxOcafSample",
"description": ""
},
{
"text": "Create Cylinder",
"function": "CreateCylinderOcafSample",
"description": ""
}
],
"2 Modify": [{
"text": "Modify Box",
"function": "ModifyBoxOcafSample",
"description": ""
},
{
"text": "Modify Cylinder",
"function": "ModifyCylinderOcafSample",
"description": ""
}
],
"3 Action": [{
"text": "Undo",
"function": "UndoOcafSample",
"description": ""
},
{
"text": "Redo",
"function": "RedoOcafSample",
"description": ""
}
],
"4 Data storage": [{
"text": "Open OCAF",
"function": "DialogOpenOcafSample",
"description": ""
},
{
"text": "Save binary OCAF",
"function": "DialogSaveBinOcafSample",
"description": ""
},
{
"text": "Save XML OCAF",
"function": "DialogSaveXmlOcafSample",
"description": ""
}
]
}
}

View File

@@ -0,0 +1,624 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "OcafSamples.h"
#include "TOcaf_Application.h"
#include "TOcafFunction_BoxDriver.h"
#include "TOcafFunction_CylDriver.h"
#include <TPrsStd_AISViewer.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_DisplayMode.hxx>
#include <TPrsStd_AISPresentation.hxx>
#include <TNaming_NamedShape.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_Name.hxx>
#include <TFunction_Function.hxx>
#include <TFunction_DriverTable.hxx>
#include <TDF_ChildIterator.hxx>
#include <PCDM_StoreStatus.hxx>
#include <BinDrivers.hxx>
#include <XmlDrivers.hxx>
void OcafSamples::Process (const TCollection_AsciiString& theSampleName)
{
if (IsImportSample(theSampleName))
{
myObject3d.Clear();
}
myObject2d.Clear();
myCode.Clear();
myIsProcessed = Standard_False;
try
{
ExecuteSample(theSampleName);
}
catch (...)
{
TraceError(TCollection_AsciiString("Error in sample: ") + theSampleName);
}
}
void OcafSamples::ClearExtra()
{
myOcafDoc = nullptr;
myContext->RemoveAll(Standard_True);
}
void OcafSamples::ExecuteSample (const TCollection_AsciiString& theSampleName)
{
Standard_Boolean anIsSamplePresent = Standard_True;
FindSourceCode(theSampleName);
if (theSampleName == "CreateOcafDocument")
CreateOcafDocument();
else if (theSampleName == "CreateBoxOcafSample")
CreateBoxOcafSample();
else if (theSampleName == "CreateCylinderOcafSample")
CreateCylinderOcafSample();
else if (theSampleName == "ModifyBoxOcafSample")
ModifyBoxOcafSample();
else if (theSampleName == "ModifyCylinderOcafSample")
ModifyCylinderOcafSample();
else if (theSampleName == "UndoOcafSample")
UndoOcafSample();
else if (theSampleName == "RedoOcafSample")
RedoOcafSample();
else if (theSampleName == "DialogOpenOcafSample")
DialogOpenOcafSample();
else if (theSampleName == "DialogSaveBinOcafSample")
DialogSaveBinOcafSample();
else if (theSampleName == "DialogSaveXmlOcafSample")
DialogSaveXmlOcafSample();
else
{
myResult << "No function found: " << theSampleName;
myCode += TCollection_AsciiString("No function found: ") + theSampleName;
anIsSamplePresent = Standard_False;
}
myIsProcessed = anIsSamplePresent;
}
Standard_Boolean OcafSamples::IsExportSample (const TCollection_AsciiString& theSampleName)
{
if (theSampleName == "DialogSaveBinOcafSample" || theSampleName == "DialogSaveXmlOcafSample")
{
return Standard_True;
}
else
{
return Standard_False;
}
}
Standard_Boolean OcafSamples::IsImportSample (const TCollection_AsciiString& theSampleName)
{
if (theSampleName == "DialogOpenOcafSample")
{
return Standard_True;
}
else
{
return Standard_False;
}
}
Standard_Boolean OcafSamples::IsBinarySample (const TCollection_AsciiString& theSampleName)
{
if (theSampleName == "DialogOpenOcafSample" || theSampleName == "DialogSaveBinOcafSample")
{
return Standard_True;
}
else
{
return Standard_False;
}
}
Standard_Boolean OcafSamples::IsXmlSample (const TCollection_AsciiString& theSampleName)
{
if (theSampleName == "DialogOpenOcafSample" || theSampleName == "DialogSaveXmlOcafSample")
{
return Standard_True;
}
else
{
return Standard_False;
}
}
void OcafSamples::CreateOcafDocument()
{
Handle(TOcaf_Application) anOcaf_Application = new TOcaf_Application;
anOcaf_Application->NewDocument("BinOcaf", myOcafDoc);
TPrsStd_AISViewer::New(myOcafDoc->Main(), myViewer);
Handle(AIS_InteractiveContext) anAisContext;
TPrsStd_AISViewer::Find(myOcafDoc->Main(), anAisContext);
anAisContext->SetDisplayMode(AIS_Shaded, Standard_True);
myContext = anAisContext;
// Set the maximum number of available "undo" actions
myOcafDoc->SetUndoLimit(10);
}
void OcafSamples::CreateBoxOcafSample()
{
// Open a new command (for undo)
myOcafDoc->NewCommand();
// A data structure for our box:
// the box itself is attached to the BoxLabel label (as his name and his function attribute)
// its arguments (dimensions: width, length and height; and position: x, y, z)
// are attached to the child labels of the box:
// 0:1 Box Label ---> Name ---> Named shape ---> Function
// 0:1:1 -- Width Label
// 0:1:2 -- Length Label
// 0:1:3 -- Height Label
// 0:1:4 -- X Label
// 0:1:5 -- Y Label
// 0:1:6 -- Z Label
// Create a new label in the data structure for the box
TDF_Label aLabel = TDF_TagSource::NewChild(myOcafDoc->Main());
Standard_Real aBoxWidth(30.0), aBoxLength(20.0), aBoxHeight(10.0);
Standard_Real aBoxX(0.0), aBoxY(0.0), aBoxZ(0.0);
Standard_CString aBoxName("OcafBox");
// Create the data structure : Set the dimensions, position and name attributes
TDataStd_Real::Set(aLabel.FindChild(1), aBoxWidth);
TDataStd_Real::Set(aLabel.FindChild(2), aBoxLength);
TDataStd_Real::Set(aLabel.FindChild(3), aBoxHeight);
TDataStd_Real::Set(aLabel.FindChild(4), aBoxX);
TDataStd_Real::Set(aLabel.FindChild(5), aBoxY);
TDataStd_Real::Set(aLabel.FindChild(6), aBoxZ);
TDataStd_Name::Set(aLabel, aBoxName); // Name
// Instantiate a TFunction_Function attribute connected to the current box driver
// and attach it to the data structure as an attribute of the Box Label
Handle(TFunction_Function) myFunction = TFunction_Function::Set(aLabel, TOcafFunction_BoxDriver::GetID());
// Initialize and execute the box driver (look at the "Execute()" code)
Handle(TFunction_Logbook) aLogBook = TFunction_Logbook::Set(aLabel);
Handle(TFunction_Driver) myBoxDriver;
// Find the TOcafFunction_BoxDriver in the TFunction_DriverTable using its GUID
if (!TFunction_DriverTable::Get()->FindDriver(TOcafFunction_BoxDriver::GetID(), myBoxDriver))
{
myResult << "Ocaf Box driver not found" << std::endl;
}
myBoxDriver->Init(aLabel);
if (myBoxDriver->Execute(aLogBook))
{
myResult << "Create Box function execute failed" << std::endl;
}
// Get the TPrsStd_AISPresentation of the new box TNaming_NamedShape
Handle(TPrsStd_AISPresentation) anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
// Display it
anAisPresentation->Display(1);
// Attach an integer attribute to aLabel to memorize it's displayed
TDataStd_Integer::Set(aLabel, 1);
myContext->UpdateCurrentViewer();
// Close the command (for undo)
myOcafDoc->CommitCommand();
myResult << "Created a box with name: " << aBoxName << std::endl;
myResult << "base coord X: " << aBoxX << " Y: " << aBoxY << " Z: " << aBoxZ << std::endl;
myResult << "width: " << aBoxWidth << " length: " << aBoxLength << " height: " << aBoxHeight << std::endl;
}
void OcafSamples::CreateCylinderOcafSample()
{
// Open a new command (for undo)
myOcafDoc->NewCommand();
// A data structure for our cylinder:
// the cylinder itself is attached to the CylinderLabel label (as his name and his function attribute)
// its arguments (dimensions: radius and height; and position: x, y, z)
// are attached to the child labels of the cylinder:
// 0:1 Cylinder Label ---> Name ---> Named shape ---> Function
// 0:1:1 -- Radius Label
// 0:1:2 -- Height Label
// 0:1:3 -- X Label
// 0:1:4 -- Y Label
// 0:1:5 -- Z Label
// Create a new label in the data structure for the cylinder
TDF_Label aLabel = TDF_TagSource::NewChild(myOcafDoc->Main());
Standard_Real aCylRadius(10.0), aCylHeight(20.0);
Standard_Real aCylX(60.0), aCylY(40.0), aCylZ(0.0);
Standard_CString aCylName("OcafCylinder");
// Create the data structure : Set the dimensions, position and name attributes
TDataStd_Real::Set(aLabel.FindChild(1), aCylRadius);
TDataStd_Real::Set(aLabel.FindChild(2), aCylHeight);
TDataStd_Real::Set(aLabel.FindChild(3), aCylX);
TDataStd_Real::Set(aLabel.FindChild(4), aCylY);
TDataStd_Real::Set(aLabel.FindChild(5), aCylZ);
TDataStd_Name::Set(aLabel, aCylName);
// Instantiate a TFunction_Function attribute connected to the current cylinder driver
// and attach it to the data structure as an attribute of the Cylinder Label
Handle(TFunction_Function) myFunction = TFunction_Function::Set(aLabel, TOcafFunction_CylDriver::GetID());
// Initialize and execute the cylinder driver (look at the "Execute()" code)
Handle(TFunction_Logbook) aLogBook = TFunction_Logbook::Set(aLabel);
Handle(TFunction_Driver) myCylDriver;
// Find the TOcafFunction_CylDriver in the TFunction_DriverTable using its GUID
if (!TFunction_DriverTable::Get()->FindDriver(TOcafFunction_CylDriver::GetID(), myCylDriver))
{
myResult << "Ocaf Cylinder driver not found";
}
myCylDriver->Init(aLabel);
if (myCylDriver->Execute(aLogBook))
{
myResult << "Create Cylinder function execute failed";
}
// Get the TPrsStd_AISPresentation of the new box TNaming_NamedShape
Handle(TPrsStd_AISPresentation) anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
// Display it
anAisPresentation->Display(1);
// Attach an integer attribute to aLabel to memorize it's displayed
TDataStd_Integer::Set(aLabel, 1);
myContext->UpdateCurrentViewer();
// Close the command (for undo)
myOcafDoc->CommitCommand();
myResult << "Created a cylinder with name: " << aCylName << std::endl;
myResult << "radius: " << aCylRadius << " height: " << aCylHeight << std::endl;
myResult << "base coord X: " << aCylX << " Y: " << aCylY << " Z: " << aCylZ << std::endl;
}
void OcafSamples::ModifyBoxOcafSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
Standard_Integer aBoxCount(0);
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
// Get the main label of the selected object
Handle(TPrsStd_AISPresentation) anAisPresentation = Handle(TPrsStd_AISPresentation)::DownCast(anAisObject->GetOwner());
TDF_Label aLabel = anAisPresentation->Label();
// Get the TFunction_Function attribute of the selected object
Handle(TFunction_Function) aFunction;
if (!aLabel.FindAttribute(TFunction_Function::GetID(), aFunction))
{
myResult << "Object cannot be modify.";
return;
}
// Get the Standard_GUID of the TFunction_FunctionDriver of the selected object TFunction_Function attribute
Standard_GUID aDriverID = aFunction->GetDriverGUID();
// Case of a box created with the box function driver
if (aDriverID == TOcafFunction_BoxDriver::GetID())
{
aBoxCount++;
Standard_Real aBoxX, aBoxY, aBoxZ, aBoxWidth, aBoxLength, aBoxHeight;
// Get the attributes values of the current box
Handle(TDataStd_Real) aCurrentReal;
aLabel.FindChild(1).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aBoxWidth = aCurrentReal->Get();
aLabel.FindChild(2).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aBoxLength = aCurrentReal->Get();
aLabel.FindChild(3).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aBoxHeight = aCurrentReal->Get();
aLabel.FindChild(4).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aBoxX = aCurrentReal->Get();
aLabel.FindChild(5).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aBoxY = aCurrentReal->Get();
aLabel.FindChild(6).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aBoxZ = aCurrentReal->Get();
Handle(TDataStd_Name) aBoxName;
aLabel.FindAttribute(TDataStd_Name::GetID(), aBoxName);
myResult << "Current parameters of box with name: " << aBoxName->Get() << std::endl;
myResult << "width: " << aBoxWidth << " length: " << aBoxLength << " height: " << aBoxHeight << std::endl;
myResult << "base coord X: " << aBoxX << " Y: " << aBoxY << " Z: " << aBoxZ << std::endl;
// Open a new command (for undo)
myOcafDoc->NewCommand();
// Modify the box - 1.5 times increase
aBoxWidth *= 1.5; aBoxLength *= 1.5; aBoxHeight *= 1.5;
TDataStd_Real::Set(aLabel.FindChild(1), aBoxWidth);
TDataStd_Real::Set(aLabel.FindChild(2), aBoxLength);
TDataStd_Real::Set(aLabel.FindChild(3), aBoxHeight);
TDataStd_Real::Set(aLabel.FindChild(4), aBoxX);
TDataStd_Real::Set(aLabel.FindChild(5), aBoxY);
TDataStd_Real::Set(aLabel.FindChild(6), aBoxZ);
// Get the TFunction_FunctionDriver GUID used with the TFunction_Function
aDriverID = aFunction->GetDriverGUID();
Handle(TFunction_Logbook) aLogBook = TFunction_Logbook::Set(aLabel);
Handle(TFunction_Driver) aBoxDriver;
// Find the TOcafFunction_BoxDriver in the TFunction_DriverTable using its GUID
TFunction_DriverTable::Get()->FindDriver(aDriverID, aBoxDriver);
// Execute the cut if it must be (if an attribute changes)
aBoxDriver->Init(aLabel);
// Set the box touched, it will be useful to recompute an object which used this box as attribute
aLogBook->SetTouched(aLabel);
if (aBoxDriver->Execute(aLogBook))
{
myResult << "Recompute failed" << std::endl;
}
// Get the presentation of the box, display it and set it selected
anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
TDataStd_Integer::Set(aLabel, 1);
anAisPresentation->Display(1);
myContext->UpdateCurrentViewer();
// Close the command (for undo)
myOcafDoc->CommitCommand();
myResult << std::endl;
myResult << "New box parameters: " << std::endl;
myResult << "base coord X: " << aBoxX << " Y: " << aBoxY << " Z: " << aBoxZ << std::endl;
myResult << "width: " << aBoxWidth << " length: " << aBoxLength << " height: " << aBoxHeight << std::endl;
}
}
if (aBoxCount)
{
myResult << "Number of modified boxes: " << aBoxCount << std::endl;
}
else
{
myResult << "No boxes to modify" << std::endl;
}
}
void OcafSamples::ModifyCylinderOcafSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
Standard_Integer aCylCount(0);
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
// Get the main label of the selected object
Handle(TPrsStd_AISPresentation) anAisPresentation = Handle(TPrsStd_AISPresentation)::DownCast(anAisObject->GetOwner());
TDF_Label aLabel = anAisPresentation->Label();
// Get the TFunction_Function attribute of the selected object
Handle(TFunction_Function) aFunction;
if (!aLabel.FindAttribute(TFunction_Function::GetID(), aFunction))
{
myResult << "Object cannot be modify.";
return;
}
// Get the Standard_GUID of the TFunction_FunctionDriver of the selected object TFunction_Function attribute
Standard_GUID aDriverID = aFunction->GetDriverGUID();
// Case of a box created with the box function driver
if (aDriverID == TOcafFunction_CylDriver::GetID())
{
aCylCount++;
Standard_Real aCylRadius, aCylHeight, aCylX, aCylY, aCylZ;
// Get the attributes values of the current box
Handle(TDataStd_Real) aCurrentReal;
aLabel.FindChild(1).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aCylRadius = aCurrentReal->Get();
aLabel.FindChild(2).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aCylHeight = aCurrentReal->Get();
aLabel.FindChild(3).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aCylX = aCurrentReal->Get();
aLabel.FindChild(4).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aCylY = aCurrentReal->Get();
aLabel.FindChild(5).FindAttribute(TDataStd_Real::GetID(), aCurrentReal);
aCylZ = aCurrentReal->Get();
Handle(TDataStd_Name) aCylName;
aLabel.FindAttribute(TDataStd_Name::GetID(), aCylName);
myResult << "Current parameters of box with name: " << aCylName->Get() << std::endl;
myResult << "radius: " << aCylRadius << " height: " << aCylHeight << std::endl;
myResult << "base coord X: " << aCylX << " Y: " << aCylY << " Z: " << aCylZ << std::endl;
// Open a new command (for undo)
myOcafDoc->NewCommand();
// Modify the cylinder - 2x increase
aCylRadius *= 2.0; aCylHeight *= 2.0;
// and move base point in XY plane
aCylX *= 2.0; aCylY *= 2.0;
TDataStd_Real::Set(aLabel.FindChild(1), aCylRadius);
TDataStd_Real::Set(aLabel.FindChild(2), aCylHeight);
TDataStd_Real::Set(aLabel.FindChild(3), aCylX);
TDataStd_Real::Set(aLabel.FindChild(4), aCylY);
TDataStd_Real::Set(aLabel.FindChild(5), aCylZ);
// Get the TFunction_FunctionDriver GUID used with the TFunction_Function
aDriverID = aFunction->GetDriverGUID();
Handle(TFunction_Logbook) aLogBook = TFunction_Logbook::Set(aLabel);
Handle(TFunction_Driver) aCylDriver;
// Find the TOcafFunction_CylDriver in the TFunction_DriverTable using its GUID
TFunction_DriverTable::Get()->FindDriver(aDriverID, aCylDriver);
// Execute the cut if it must be (if an attribute changes)
aCylDriver->Init(aLabel);
// Set the cylinder touched, it will be useful to recompute an object which used this box as attribute
aLogBook->SetTouched(aLabel);
if (aCylDriver->Execute(aLogBook))
{
myResult << "Recompute failed" << std::endl;
}
// Get the presentation of the box, display it and set it selected
anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
TDataStd_Integer::Set(aLabel, 1);
anAisPresentation->Display(1);
myContext->UpdateCurrentViewer();
// Close the command (for undo)
myOcafDoc->CommitCommand();
myResult << std::endl;
myResult << "New cylinder parameters: " << std::endl;
myResult << "radius: " << aCylRadius << " height: " << aCylHeight << std::endl;
myResult << "base coord X: " << aCylX << " Y: " << aCylY << " Z: " << aCylZ << std::endl;
}
}
if (aCylCount)
{
myResult << "Number of modified boxes: " << aCylCount << std::endl;
}
else
{
myResult << "No boxes to modify" << std::endl;
}
}
void OcafSamples::UndoOcafSample()
{
if (myOcafDoc->Undo())
{
myOcafDoc->CommitCommand();
myContext->UpdateCurrentViewer();
myResult << "Undo was done successfully" << std::endl;
}
else
{
myResult << "Nothing to undo" << std::endl;
}
}
void OcafSamples::RedoOcafSample()
{
if (myOcafDoc->Redo())
{
myOcafDoc->CommitCommand();
myContext->UpdateCurrentViewer();
myResult << "Redo was done successfully" << std::endl;
}
else
{
myResult << "Nothing to redo" << std::endl;
}
}
void OcafSamples::DialogOpenOcafSample()
{
Handle(TOcaf_Application) anOcaf_Application = new TOcaf_Application;
// load persistence
BinDrivers::DefineFormat(anOcaf_Application);
XmlDrivers::DefineFormat(anOcaf_Application);
// Look for already opened
if (anOcaf_Application->IsInSession(myFileName))
{
myResult << "Document: " << myFileName << " is already in session" << std::endl;
return;
}
// Open the document in the current application
PCDM_ReaderStatus aReaderStatus = anOcaf_Application->Open(myFileName, myOcafDoc);
if (aReaderStatus == PCDM_ReaderStatus::PCDM_RS_OK)
{
// Connect the document CAF (myDoc) with the AISContext (myAISContext)
TPrsStd_AISViewer::New(myOcafDoc->Main(), myViewer);
myOcafDoc->SetUndoLimit(10);
myContext->RemoveAll(Standard_False);
Handle(AIS_InteractiveContext) aContext;
TPrsStd_AISViewer::Find(myOcafDoc->Main(), aContext);
aContext->SetDisplayMode(AIS_Shaded, Standard_True);
myContext = aContext;
// Display the presentations (which was not stored in the document)
DisplayPresentation();
myResult << "Open a document" << std::endl;
}
else
{
myResult << "Error! The file wasn't opened. PCDM_ReaderStatus: " << aReaderStatus << std::endl;
}
}
void OcafSamples::DialogSaveBinOcafSample()
{
Handle(TOcaf_Application) anOcaf_Application = new TOcaf_Application;
BinDrivers::DefineFormat(anOcaf_Application);
myOcafDoc->ChangeStorageFormat("BinOcaf");
// Saves the document in the current application
PCDM_StoreStatus aStoreStatus = anOcaf_Application->SaveAs(myOcafDoc, myFileName);
if (aStoreStatus == PCDM_StoreStatus::PCDM_SS_OK)
{
myResult << "The file was saved successfully" << std::endl;
}
else
{
myResult << "Error! The file wasn't saved. PCDM_StoreStatus: " << aStoreStatus << std::endl;
}
}
void OcafSamples::DialogSaveXmlOcafSample()
{
Handle(TOcaf_Application) anOcaf_Application = new TOcaf_Application;
XmlDrivers::DefineFormat(anOcaf_Application);
myOcafDoc->ChangeStorageFormat("XmlOcaf");
// Saves the document in the current application
PCDM_StoreStatus aStoreStatus = anOcaf_Application->SaveAs(myOcafDoc, myFileName);
if (aStoreStatus == PCDM_StoreStatus::PCDM_SS_OK)
{
myResult << "The file was saved successfully" << std::endl;
}
else
{
myResult << "Error! The file wasn't saved. PCDM_StoreStatus: " << aStoreStatus << std::endl;
}
}
void OcafSamples::DisplayPresentation()
{
TDF_Label aRootlabel = myOcafDoc->Main();
for (TDF_ChildIterator it(aRootlabel); it.More(); it.Next())
{
TDF_Label aLabel = it.Value();
Handle(TNaming_NamedShape) aNamedShape;
if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(), aNamedShape))
{
continue;
}
Handle(TDataStd_Integer) aDataInteger;
// To know if the object was displayed
if (aLabel.FindAttribute(TDataStd_Integer::GetID(), aDataInteger))
{
if (!aDataInteger->Get())
{
continue;
}
}
Handle(TPrsStd_AISPresentation) anAisPresentation;
if (!aLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), anAisPresentation))
{
anAisPresentation = TPrsStd_AISPresentation::Set(aLabel, TNaming_NamedShape::GetID());
}
anAisPresentation->SetColor(Quantity_NOC_ORANGE);
anAisPresentation->Display(1);
}
myContext->UpdateCurrentViewer();
}

View File

@@ -0,0 +1,85 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef OCAFSAMPLES_H
#define OCAFSAMPLES_H
#include "BaseSample.h"
#include "TOcaf_Application.h"
#include <AIS_InteractiveContext.hxx>
#include <V3d_Viewer.hxx>
#include <TDocStd_Document.hxx>
//! Implements OCAF samples
class OcafSamples : public BaseSample
{
DEFINE_STANDARD_RTTI_INLINE(OcafSamples, BaseSample)
public:
OcafSamples (const TCollection_AsciiString& theSampleSourcePath,
const Handle(V3d_Viewer)& theViewer,
const Handle(AIS_InteractiveContext)& theContext)
: BaseSample (theSampleSourcePath, theContext),
myViewer (theViewer)
{
//
}
enum ExchangeType { None, Binary, Xml };
virtual void Process (const TCollection_AsciiString& theSampleName) Standard_OVERRIDE;
void ClearExtra();
void SetFileName (const TCollection_AsciiString& theFileName) { myFileName = theFileName; };
static Standard_Boolean IsExportSample (const TCollection_AsciiString& theSampleName);
static Standard_Boolean IsImportSample (const TCollection_AsciiString& theSampleName);
static Standard_Boolean IsBinarySample (const TCollection_AsciiString& theSampleName);
static Standard_Boolean IsXmlSample (const TCollection_AsciiString& theSampleName);
protected:
virtual void ExecuteSample (const TCollection_AsciiString& theSampleName) Standard_OVERRIDE;
private:
// One function for every sample
void CreateOcafDocument();
void CreateBoxOcafSample();
void CreateCylinderOcafSample();
void ModifyBoxOcafSample();
void ModifyCylinderOcafSample();
void UndoOcafSample();
void RedoOcafSample();
void DialogOpenOcafSample();
void DialogSaveBinOcafSample();
void DialogSaveXmlOcafSample();
void DisplayPresentation();
private:
ExchangeType myExchangeType;
TCollection_AsciiString myFileName;
Handle(V3d_Viewer) myViewer;
Handle(TDocStd_Document) myOcafDoc;
};
#endif //OCAFSAMPLES_H

View File

@@ -0,0 +1,486 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "Sample2D_Face.h"
#include <BRep_Tool.hxx>
#include <BRepAdaptor_Curve2d.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <GeomLib.hxx>
#include <Select3D_SensitiveGroup.hxx>
#include <Select3D_SensitiveCurve.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
Sample2D_Face::Sample2D_Face (const TopoDS_Shape& theFace)
: myFORWARDColor (Quantity_NOC_BLUE1),
myREVERSEDColor (Quantity_NOC_YELLOW),
myINTERNALColor (Quantity_NOC_RED1),
myEXTERNALColor (Quantity_NOC_MAGENTA1),
myWidthIndex (1),
myTypeIndex (1),
//
myshape (theFace),
myForwardNum (0),
myReversedNum (0),
myInternalNum (0),
myExternalNum (0),
//
myForwardBounds (0),
myReversedBounds (0),
myInternalBounds (0),
myExternalBounds (0)
{
SetAutoHilight(Standard_False);
FillData(Standard_True);
}
void Sample2D_Face::DrawMarker (const Handle(Geom2d_TrimmedCurve)& theCurve,
const Handle(Prs3d_Presentation)& thePresentation)
{
Standard_Real aCenterParam = (theCurve->FirstParameter() + theCurve->LastParameter()) / 2;
gp_Pnt2d p;
gp_Vec2d v;
theCurve->D1(aCenterParam, p, v);
if (v.Magnitude() > gp::Resolution())
{
gp_Vec aDir(v.X(), v.Y(), 0.);
gp_Pnt aPoint(p.X(), p.Y(), 0.);
aDir.Normalize();
aDir.Reverse();
gp_Dir aZ(0, 0, 1);
gp_Pnt aLeft (aPoint.Translated(aDir.Rotated(gp_Ax1(aPoint, aZ), M_PI / 6) * 5));
gp_Pnt aRight(aPoint.Translated(aDir.Rotated(gp_Ax1(aPoint, aZ), M_PI * 11 / 6) * 5));
Handle(Graphic3d_ArrayOfPolylines) anArrow = new Graphic3d_ArrayOfPolylines(3);
anArrow->AddVertex(aLeft);
anArrow->AddVertex(aPoint);
anArrow->AddVertex(aRight);
thePresentation->CurrentGroup()->AddPrimitiveArray(anArrow);
}
}
void Sample2D_Face::FillData(Standard_Boolean isSizesRecompute)
{
if (myshape.IsNull() || myshape.ShapeType() != TopAbs_FACE)
{
return;
}
Standard_Real f, l;
TopoDS_Face aFace = TopoDS::Face(myshape);
// count number of vertices and bounds in primitive arrays
if (isSizesRecompute)
{
mySeq_FORWARD.Clear();
mySeq_REVERSED.Clear();
mySeq_INTERNAL.Clear();
mySeq_EXTERNAL.Clear();
myshape.Orientation(TopAbs_FORWARD);
for (TopExp_Explorer anEdgeIter (myshape, TopAbs_EDGE); anEdgeIter.More(); anEdgeIter.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgeIter.Current());
BRepAdaptor_Curve2d aCurveOnEdge (anEdge, aFace);
GCPnts_QuasiUniformDeflection anEdgeDistrib(aCurveOnEdge, 1.e-2);
if (!anEdgeDistrib.IsDone())
{
continue;
}
switch (anEdge.Orientation())
{
case TopAbs_FORWARD:
{
myForwardNum += anEdgeDistrib.NbPoints();
myForwardBounds++;
break;
}
case TopAbs_REVERSED:
{
myReversedNum += anEdgeDistrib.NbPoints();
myReversedBounds++;
break;
}
case TopAbs_INTERNAL:
{
myInternalNum += anEdgeDistrib.NbPoints();
myInternalBounds++;
break;
}
case TopAbs_EXTERNAL:
{
myExternalNum += anEdgeDistrib.NbPoints();
myExternalBounds++;
break;
}
}
}
}
myForwardArray = new Graphic3d_ArrayOfPolylines(myForwardNum, myForwardBounds);
myReversedArray = new Graphic3d_ArrayOfPolylines(myReversedNum, myReversedBounds);
myInternalArray = new Graphic3d_ArrayOfPolylines(myInternalNum, myInternalBounds);
myExternalArray = new Graphic3d_ArrayOfPolylines(myExternalNum, myExternalBounds);
// fill primitive arrays
for (TopExp_Explorer anEdgeIter (myshape, TopAbs_EDGE); anEdgeIter.More(); anEdgeIter.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgeIter.Current());
const Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface (anEdge, aFace, f, l);
Handle(Geom2d_TrimmedCurve) aTrimmedCurve = new Geom2d_TrimmedCurve(aCurve, f, l);
if (!aTrimmedCurve.IsNull())
{
Handle(Geom_Curve) aCurve3d = GeomLib::To3d(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), aTrimmedCurve);
BRepAdaptor_Curve2d aCurveOnEdge (anEdge, aFace);
GCPnts_QuasiUniformDeflection anEdgeDistrib (aCurveOnEdge, 1.e-2);
if (!anEdgeDistrib.IsDone())
{
continue;
}
switch (anEdge.Orientation())
{
case TopAbs_FORWARD:
{
myForwardArray->AddBound(anEdgeDistrib.NbPoints());
for (Standard_Integer i = 1; i <= anEdgeDistrib.NbPoints(); ++i)
{
myForwardArray->AddVertex(anEdgeDistrib.Value(i));
}
if (isSizesRecompute)
{
mySeq_FORWARD.Append(aCurve3d);
}
break;
}
case TopAbs_REVERSED:
{
myReversedArray->AddBound(anEdgeDistrib.NbPoints());
for (Standard_Integer i = 1; i <= anEdgeDistrib.NbPoints(); ++i)
{
myReversedArray->AddVertex(anEdgeDistrib.Value(i));
}
if (isSizesRecompute)
{
mySeq_REVERSED.Append(aCurve3d);
}
break;
}
case TopAbs_INTERNAL:
{
myInternalArray->AddBound(anEdgeDistrib.NbPoints());
for (Standard_Integer i = 1; i <= anEdgeDistrib.NbPoints(); ++i)
{
myInternalArray->AddVertex(anEdgeDistrib.Value(i));
}
if (isSizesRecompute)
{
mySeq_INTERNAL.Append(aCurve3d);
}
break;
}
case TopAbs_EXTERNAL:
{
myExternalArray->AddBound(anEdgeDistrib.NbPoints());
for (Standard_Integer i = 1; i <= anEdgeDistrib.NbPoints(); ++i)
{
myExternalArray->AddVertex(anEdgeDistrib.Value(i));
}
if (isSizesRecompute)
{
mySeq_EXTERNAL.Append(aCurve3d);
}
break;
}
}
}
}
}
void Sample2D_Face::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode)
{
if (theMode != 0)
{
return;
}
thePresentation->Clear();
myDrawer->SetWireDraw(1);
if (myshape.IsNull() || myshape.ShapeType() != TopAbs_FACE)
{
return;
}
Handle(Graphic3d_AspectLine3d) aLineAspect_FORWARD = new Graphic3d_AspectLine3d(myFORWARDColor, Aspect_TOL_SOLID, 1);
Handle(Graphic3d_AspectLine3d) aLineAspect_REVERSED = new Graphic3d_AspectLine3d(myREVERSEDColor, Aspect_TOL_SOLID, 1);
Handle(Graphic3d_AspectLine3d) aLineAspect_INTERNAL = new Graphic3d_AspectLine3d(myINTERNALColor, Aspect_TOL_SOLID, 1);
Handle(Graphic3d_AspectLine3d) aLineAspect_EXTERNAL = new Graphic3d_AspectLine3d(myEXTERNALColor, Aspect_TOL_SOLID, 1);
Standard_Real f, l;
TopoDS_Face aFace = TopoDS::Face(myshape);
// estimating number of vertices in primitive arrays
for (TopExp_Explorer anEdgeIter (myshape, TopAbs_EDGE); anEdgeIter.More(); anEdgeIter.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeIter.Current());
const Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface (anEdge, aFace, f, l);
Handle(Geom2d_TrimmedCurve) aTrimmedCurve = new Geom2d_TrimmedCurve(aCurve, f, l);
// make a 3D curve from 2D trimmed curve to display it
Handle(Geom_Curve) aCurve3d = GeomLib::To3d(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), aTrimmedCurve);
// make distribution of points
BRepAdaptor_Curve2d aCurveOnEdge (anEdge, aFace);
GCPnts_QuasiUniformDeflection anEdgeDistrib(aCurveOnEdge, 1.e-2);
if (anEdgeDistrib.IsDone())
{
switch (anEdge.Orientation())
{
case TopAbs_FORWARD:
{
thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_FORWARD);
DrawMarker(aTrimmedCurve, thePresentation);
break;
}
case TopAbs_REVERSED:
{
thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_REVERSED);
DrawMarker(aTrimmedCurve, thePresentation);
break;
}
case TopAbs_INTERNAL:
{
thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_INTERNAL);
DrawMarker(aTrimmedCurve, thePresentation);
mySeq_INTERNAL.Append(aCurve3d);
break;
}
case TopAbs_EXTERNAL:
{
thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_EXTERNAL);
DrawMarker(aTrimmedCurve, thePresentation);
break;
}
}
}
}
// add all primitives to the presentation
thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_FORWARD);
thePresentation->CurrentGroup()->AddPrimitiveArray(myForwardArray);
thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_REVERSED);
thePresentation->CurrentGroup()->AddPrimitiveArray(myReversedArray);
thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_INTERNAL);
thePresentation->CurrentGroup()->AddPrimitiveArray(myInternalArray);
thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_EXTERNAL);
thePresentation->CurrentGroup()->AddPrimitiveArray(myExternalArray);
}
void Sample2D_Face::HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const SelectMgr_SequenceOfOwner& theOwners)
{
Handle(Prs3d_Presentation) aSelectionPrs = GetSelectPresentation (thePrsMgr);
Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(Quantity_NOC_ANTIQUEWHITE, Aspect_TOL_SOLID, 2);
if (HasPresentation())
{
aSelectionPrs->SetTransformPersistence(Presentation()->TransformPersistence());
}
const Standard_Integer aLength = theOwners.Length();
aSelectionPrs->Clear();
FillData();
Handle(Graphic3d_Group) aSelectGroup = aSelectionPrs->NewGroup();
for (Standard_Integer i = 1; i <= aLength; ++i)
{
Handle(SelectMgr_EntityOwner) anOwner = theOwners.Value(i);
// check priority of owner to add primitives in one of array
// containing primitives with certain type of orientation
switch (anOwner->Priority())
{
case 7:
{
// add to objects with forward orientation
aSelectGroup->SetGroupPrimitivesAspect(aLineAspect);
aSelectGroup->AddPrimitiveArray(myForwardArray);
break;
}
case 6:
{
// add to objects with reversed orientation
aSelectGroup->SetGroupPrimitivesAspect(aLineAspect);
aSelectGroup->AddPrimitiveArray(myReversedArray);
break;
}
case 5:
{
// add to objects with internal orientation
aSelectGroup->SetGroupPrimitivesAspect(aLineAspect);
aSelectGroup->AddPrimitiveArray(myInternalArray);
break;
}
case 4:
{
// add to objects with external orientation
aSelectGroup->SetGroupPrimitivesAspect(aLineAspect);
aSelectGroup->AddPrimitiveArray(myExternalArray);
break;
}
}
}
aSelectionPrs->Display();
}
void Sample2D_Face::ClearSelected()
{
if (Handle(Prs3d_Presentation) aSelectionPrs = GetSelectPresentation(NULL))
{
aSelectionPrs->Clear();
}
}
void Sample2D_Face::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
const Handle(Prs3d_Drawer)& theStyle,
const Handle(SelectMgr_EntityOwner)& theOwner)
{
Handle(Prs3d_Presentation) aHighlightPrs = GetHilightPresentation(thePM);
if (HasPresentation())
{
aHighlightPrs->SetTransformPersistence(Presentation()->TransformPersistence());
}
if (theOwner.IsNull())
{
return;
}
aHighlightPrs->Clear();
FillData();
// Direct highlighting
aHighlightPrs->NewGroup();
Handle(Graphic3d_Group) aHilightGroup = aHighlightPrs->CurrentGroup();
Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theStyle->Color(), Aspect_TOL_SOLID, 2);
switch (theOwner->Priority())
{
case 7:
{
aHilightGroup->SetGroupPrimitivesAspect(aLineAspect);
aHilightGroup->AddPrimitiveArray(myForwardArray);
break;
}
case 6:
{
aHilightGroup->SetGroupPrimitivesAspect(aLineAspect);
aHilightGroup->AddPrimitiveArray(myReversedArray);
break;
}
case 5:
{
aHilightGroup->SetGroupPrimitivesAspect(aLineAspect);
aHilightGroup->AddPrimitiveArray(myInternalArray);
break;
}
case 4:
{
aHilightGroup->SetGroupPrimitivesAspect(aLineAspect);
aHilightGroup->AddPrimitiveArray(myExternalArray);
break;
}
}
if (thePM->IsImmediateModeOn())
{
thePM->AddToImmediateList(aHighlightPrs);
}
}
void Sample2D_Face::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
const Standard_Integer theMode)
{
if (myshape.IsNull()
|| theMode != 0)
{
return;
}
if (mySeq_FORWARD.IsEmpty()
&& mySeq_REVERSED.IsEmpty()
&& mySeq_INTERNAL.IsEmpty()
&& mySeq_EXTERNAL.IsEmpty())
{
return;
}
// create entity owner for every part of the face
// set different priorities for primitives of different orientation
Handle(SelectMgr_EntityOwner) anOwner_Forward = new SelectMgr_EntityOwner(this, 7);
Handle(SelectMgr_EntityOwner) anOwner_Reversed = new SelectMgr_EntityOwner(this, 6);
Handle(SelectMgr_EntityOwner) anOwner_Internal = new SelectMgr_EntityOwner(this, 5);
Handle(SelectMgr_EntityOwner) anOwner_External = new SelectMgr_EntityOwner(this, 4);
// create a sensitive for every part
Handle(Select3D_SensitiveGroup) aForwardGroup = new Select3D_SensitiveGroup(anOwner_Forward);
Handle(Select3D_SensitiveGroup) aReversedGroup = new Select3D_SensitiveGroup(anOwner_Reversed);
Handle(Select3D_SensitiveGroup) aInternalGroup = new Select3D_SensitiveGroup(anOwner_Internal);
Handle(Select3D_SensitiveGroup) aExternalGroup = new Select3D_SensitiveGroup(anOwner_External);
Standard_Integer aLength = mySeq_FORWARD.Length();
for (Standard_Integer i = 1; i <= aLength; ++i)
{
Handle(Select3D_SensitiveCurve) aSensitveCurve = new Select3D_SensitiveCurve(anOwner_Forward, mySeq_FORWARD(i));
aForwardGroup->Add(aSensitveCurve);
}
theSelection->Add(aForwardGroup);
aLength = mySeq_REVERSED.Length();
for (Standard_Integer i = 1; i <= aLength; ++i)
{
Handle(Select3D_SensitiveCurve) aSensitveCurve = new Select3D_SensitiveCurve(anOwner_Reversed, mySeq_REVERSED(i));
aReversedGroup->Add(aSensitveCurve);
}
theSelection->Add(aReversedGroup);
aLength = mySeq_INTERNAL.Length();
for (Standard_Integer i = 1; i <= aLength; ++i)
{
Handle(Select3D_SensitiveCurve) aSensitveCurve = new Select3D_SensitiveCurve(anOwner_Internal, mySeq_INTERNAL(i));
aInternalGroup->Add(aSensitveCurve);
}
theSelection->Add(aInternalGroup);
aLength = mySeq_EXTERNAL.Length();
for (Standard_Integer i = 1; i <= aLength; ++i)
{
Handle(Select3D_SensitiveCurve) aSensitveCurve = new Select3D_SensitiveCurve(anOwner_External, mySeq_EXTERNAL(i));
aExternalGroup->Add(aSensitveCurve);
}
theSelection->Add(aExternalGroup);
}

View File

@@ -0,0 +1,107 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef _Sample2D_Face_HeaderFile
#define _Sample2D_Face_HeaderFile
#include <AIS_InteractiveObject.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Graphic3d_ArrayOfPolylines.hxx>
#include <TopoDS_Face.hxx>
#include <TColGeom_SequenceOfCurve.hxx>
//! AIS interactive Object for sample 2D face
class Sample2D_Face : public AIS_InteractiveObject
{
DEFINE_STANDARD_RTTI_INLINE(Sample2D_Face, AIS_InteractiveObject)
public:
Standard_EXPORT Sample2D_Face (const TopoDS_Shape& theFace);
public:
TopoDS_Shape& Shape() { return myshape; }
void SetFace (const TopoDS_Shape& theFace) { myshape = theFace; }
public:
Quantity_Color myFORWARDColor;
Quantity_Color myREVERSEDColor;
Quantity_Color myINTERNALColor;
Quantity_Color myEXTERNALColor;
Standard_Integer myWidthIndex;
Standard_Integer myTypeIndex;
private:
//! Return TRUE for supported display modes (only mode 0 is supported).
virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
//! Compute presentation.
virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode) Standard_OVERRIDE;
//! Compute selection.
virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
const Standard_Integer theMode) Standard_OVERRIDE;
virtual void ClearSelected() Standard_OVERRIDE;
//! Method for advanced customizable selection of picked object
virtual void HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const SelectMgr_SequenceOfOwner& theOwners) Standard_OVERRIDE;
//! Method for advanced customizable highlighting of picked object.
virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
const Handle(Prs3d_Drawer)& theStyle,
const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
void DrawMarker (const Handle(Geom2d_TrimmedCurve)& theCurve,
const Handle(Prs3d_Presentation)& thePresentation);
void FillData(Standard_Boolean isSizesRecomputed = Standard_False);
private:
TopoDS_Shape myshape;
TColGeom_SequenceOfCurve mySeq_FORWARD;
TColGeom_SequenceOfCurve mySeq_REVERSED;
TColGeom_SequenceOfCurve mySeq_INTERNAL;
TColGeom_SequenceOfCurve mySeq_EXTERNAL;
Handle(Graphic3d_ArrayOfPolylines) myForwardArray;
Handle(Graphic3d_ArrayOfPolylines) myReversedArray;
Handle(Graphic3d_ArrayOfPolylines) myInternalArray;
Handle(Graphic3d_ArrayOfPolylines) myExternalArray;
Standard_Integer myForwardNum;
Standard_Integer myReversedNum;
Standard_Integer myInternalNum;
Standard_Integer myExternalNum;
Standard_Integer myForwardBounds;
Standard_Integer myReversedBounds;
Standard_Integer myInternalBounds;
Standard_Integer myExternalBounds;
};
#endif

View File

@@ -0,0 +1,88 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "Sample2D_Image.h"
#include <AIS_InteractiveContext.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <gp_Pnt.hxx>
#include <Graphic3d_Texture1D.hxx>
#include <Graphic3d_Texture1Dsegment.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
#include <Image_AlienPixMap.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
Sample2D_Image::Sample2D_Image (const TCollection_AsciiString& theFileName,
const Standard_Real theX,
const Standard_Real theY,
const Standard_Real theScale)
: AIS_Shape (TopoDS_Shape()),
myFilename (theFileName),
myX (theX),
myY (theY),
myScale (theScale)
{
//
}
void Sample2D_Image::MakeShape()
{
Standard_Real coeff = 1.0;
Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
if (anImage->Load (myFilename))
{
coeff = Standard_Real(anImage->Height()) / Standard_Real(anImage->Width()) * myScale;
}
TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge (gp_Pnt(myX, myY, 0.),
gp_Pnt(100 * myScale + myX, myY, 0.));
TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge (gp_Pnt(100 * myScale + myX, myY, 0.),
gp_Pnt(100 * myScale + myX, 100 * coeff + myY, 0.));
TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge (gp_Pnt(100 * myScale + myX, 100 * coeff + myY, 0.),
gp_Pnt(myX, 100 * coeff + myY, 0.));
TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge (gp_Pnt(myX, 100 * coeff + myY, 0.),
gp_Pnt(myX, myY, 0.));
TopoDS_Wire anImageBounds = BRepBuilderAPI_MakeWire(E1, E2, E3, E4);
myFace = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), anImageBounds);
}
void Sample2D_Image::SetContext (const Handle(AIS_InteractiveContext)& theContext)
{
if (theContext.IsNull() || theContext->CurrentViewer().IsNull())
{
AIS_InteractiveObject::SetContext (theContext);
return;
}
AIS_InteractiveObject::SetContext (theContext);
MakeShape();
this->Set(TopoDS_Shape(myFace));
myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(myFilename);
aTexture->DisableModulate();
myDrawer->ShadingAspect()->Aspect()->SetTextureMap (aTexture);
myDrawer->ShadingAspect()->Aspect()->SetTextureMapOn();
}

View File

@@ -0,0 +1,86 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef _Sample2D_Image_HeaderFile
#define _Sample2D_Image_HeaderFile
#include <Standard_Macro.hxx>
#include <Standard_DefineHandle.hxx>
#include <OSD_File.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_CString.hxx>
#include <Standard_Integer.hxx>
#include <SelectMgr_Selection.hxx>
#include <Standard_OStream.hxx>
#include <Standard_IStream.hxx>
#include <AIS_Shape.hxx>
#include <TopoDS_Face.hxx>
//! AIS shape for sample 2D image
class Sample2D_Image : public AIS_Shape
{
DEFINE_STANDARD_RTTI_INLINE(Sample2D_Image, AIS_Shape)
public:
//! Constructor.
Standard_EXPORT Sample2D_Image (const TCollection_AsciiString& theFileName,
const Standard_Real theX = 0.0,
const Standard_Real theY = 0.0,
const Standard_Real theScale = 1.0);
//! Return image coordinates.
void GetCoord (Standard_Real& theX, Standard_Real& theY) const
{
theX = myX;
theY = myY;
}
//! Return image coordinates.
void SetCoord (const Standard_Real theX, const Standard_Real theY)
{
myX = theX;
myY = theY;
}
//! Return image scale factor.
Standard_Real GetScale() const { return myScale; }
//! Set image scale factor.
void SetScale(const Standard_Real theNewScale) { myScale = theNewScale; }
//! Assign new interactive context to the object.
Standard_EXPORT virtual void SetContext (const Handle(AIS_InteractiveContext)& theContext) Standard_OVERRIDE;
private:
void MakeShape();
protected:
TopoDS_Face myFace;
TCollection_AsciiString myFilename;
Standard_Real myX;
Standard_Real myY;
Standard_Real myScale;
};
#endif

View File

@@ -0,0 +1,80 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "Sample2D_Markers.h"
#include <Aspect_TypeOfMarker.hxx>
// generic marker
Sample2D_Markers::Sample2D_Markers (const Standard_Real theXPosition,
const Standard_Real theYPosition,
const Aspect_TypeOfMarker theMarkerType,
const Quantity_Color theColor,
const Standard_Real theScaleOrId)
: myArrayOfPoints (new Graphic3d_ArrayOfPoints(1))
{
myXPosition = theXPosition;
myYPosition = theYPosition;
myMarkerType = theMarkerType;
myColor = theColor;
myIndex = theScaleOrId;
}
Sample2D_Markers::Sample2D_Markers (const Standard_Real theXPosition,
const Standard_Real theYPosition,
const Handle(Graphic3d_ArrayOfPoints)& theArrayOfPoints,
const Aspect_TypeOfMarker theMarkerType,
const Quantity_Color theColor,
const Standard_Real theScaleOrId)
: myArrayOfPoints (new Graphic3d_ArrayOfPoints(6))
{
myXPosition = theXPosition;
myYPosition = theYPosition;
myMarkerType = theMarkerType;
myColor = theColor;
myIndex = theScaleOrId;
myArrayOfPoints = theArrayOfPoints;
}
void Sample2D_Markers::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode)
{
if (theMode != 0)
{
return;
}
if (myMarkerType == Aspect_TOM_USERDEFINED)
{
Handle(Graphic3d_AspectMarker3d) aMarker = new Graphic3d_AspectMarker3d(Aspect_TOM_POINT, myColor, myIndex);
thePrs->CurrentGroup()->SetGroupPrimitivesAspect(aMarker);
thePrs->CurrentGroup()->AddPrimitiveArray(myArrayOfPoints);
}
else
{
Handle(Graphic3d_AspectMarker3d) aMarker = new Graphic3d_AspectMarker3d(myMarkerType, myColor, myIndex);
thePrs->CurrentGroup()->SetPrimitivesAspect(aMarker);
Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints(1);
anArrayOfPoints->AddVertex(myXPosition, myYPosition, 0);
thePrs->CurrentGroup()->AddPrimitiveArray(anArrayOfPoints);
}
}

View File

@@ -0,0 +1,88 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef _Sample2D_Markers_HeaderFile
#define _Sample2D_Markers_HeaderFile
#include <AIS_InteractiveObject.hxx>
#include <Graphic3d_ArrayOfPoints.hxx>
//! AIS AIS interactive object for sample 2D marker
class Sample2D_Markers : public AIS_InteractiveObject
{
DEFINE_STANDARD_RTTI_INLINE(Sample2D_Markers, AIS_InteractiveObject)
private:
enum Sample2D_CurrentTypeOfMarker
{
Sample2D_CTOM_Generic,
Sample2D_CTOM_Polyline,
Sample2D_CTOM_Circle,
Sample2D_CTOM_Ellips
};
public:
//! Generic marker
Standard_EXPORT Sample2D_Markers (const Standard_Real theXPosition,
const Standard_Real theYPosition,
const Aspect_TypeOfMarker theMarkerType,
const Quantity_Color theColor,
const Standard_Real theScaleOrId=5.0);
//! Polyline marker
Standard_EXPORT Sample2D_Markers (const Standard_Real theXPosition,
const Standard_Real theYPosition,
const Handle(Graphic3d_ArrayOfPoints)& theArrayOfPoints,
const Aspect_TypeOfMarker theMarkerType,
const Quantity_Color theColor,
const Standard_Real theScaleOrId=2.0);
private:
//! Return TRUE for supported display modes (only mode 0 is supported).
virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
//! Compute presentation.
virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
const Handle(Prs3d_Presentation)& /*aPresentation*/,
const Standard_Integer theMode) Standard_OVERRIDE;
//! Compute selection (not implemented).
virtual void ComputeSelection (const Handle(SelectMgr_Selection)& ,
const Standard_Integer ) Standard_OVERRIDE {}
virtual void SetContext(const Handle(AIS_InteractiveContext)& ) Standard_OVERRIDE {}
private:
Sample2D_CurrentTypeOfMarker myCurrentTypeOfMarker;
Standard_Real myXPosition;
Standard_Real myYPosition;
Aspect_TypeOfMarker myMarkerType;
Quantity_Color myColor;
Standard_Real myWidth;
Standard_Real myHeight;
Standard_Real myIndex;
//! specific polyline marker
Handle(Graphic3d_ArrayOfPoints) myArrayOfPoints;
};
#endif

View File

@@ -0,0 +1,11 @@
<RCC>
<qresource prefix="/menus">
<file>Geometry.json</file>
<file>Topology.json</file>
<file>Triangulation.json</file>
<file>DataExchange.json</file>
<file>Viewer3d.json</file>
<file>Viewer2d.json</file>
<file>Ocaf.json</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,148 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "TOcafFunction_BoxDriver.h"
#include <BRepPrimAPI_MakeBox.hxx>
#include <Standard_GUID.hxx>
#include <TDataStd_Real.hxx>
#include <TNaming_Builder.hxx>
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& TOcafFunction_BoxDriver::GetID()
{
static const Standard_GUID anID("22D22E51-D69A-11d4-8F1A-0060B0EE18E8");
return anID;
}
//=======================================================================
//function : Validate
//purpose :
//=======================================================================
void TOcafFunction_BoxDriver::Validate(Handle(TFunction_Logbook)& log) const
{
// We validate the object label ( Label() ), all the arguments and the results of the object:
log->SetValid(Label(), Standard_True);
}
//=======================================================================
//function : MustExecute
//purpose :
//=======================================================================
Standard_Boolean TOcafFunction_BoxDriver::MustExecute(const Handle(TFunction_Logbook)& log) const
{
// If the object's label is modified:
if (log->IsModified(Label())) return Standard_True;
// Cut (in our simple case) has two arguments: The original shape, and the tool shape.
// They are on the child labels of the box's label:
// So, OriginalNShape - is attached to the first child label
// ToolNShape - is attached to the second child label.
//
// Let's check them:
if (log->IsModified(Label().FindChild(1)))
{
return Standard_True; // width.
}
if (log->IsModified(Label().FindChild(2)))
{
return Standard_True; // length,
}
if (log->IsModified(Label().FindChild(3)))
{
return Standard_True; // width.
}
if (log->IsModified(Label().FindChild(4)))
{
return Standard_True; // length,
}
if (log->IsModified(Label().FindChild(5)))
{
return Standard_True; // width.
}
if (log->IsModified(Label().FindChild(6)))
{
return Standard_True; // length,
}
// if there are no any modifications concerned the box,
// it's not necessary to recompute (to call the method Execute()):
return Standard_False;
}
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer TOcafFunction_BoxDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
{
// Get the values of dimension and position attributes
Handle(TDataStd_Real) TSR;
Standard_Real x, y, z, l, h, w;
if (!Label().FindChild(1).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
l = TSR->Get();
if (!Label().FindChild(2).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
h = TSR->Get();
if (!Label().FindChild(3).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
w = TSR->Get();
if (!Label().FindChild(4).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
x = TSR->Get();
if (!Label().FindChild(5).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
y = TSR->Get();
if (!Label().FindChild(6).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
z = TSR->Get();
// Build a box using the dimension and position attributes
BRepPrimAPI_MakeBox mkBox(gp_Pnt(x, y, z), l, h, w);
TopoDS_Shape ResultShape = mkBox.Shape();
// Build a TNaming_NamedShape using built box
TNaming_Builder B(Label());
B.Generated(ResultShape);
// That's all:
// If there are no any mistakes we return 0:
return 0;
}

View File

@@ -0,0 +1,57 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef _TOcafFunction_BoxDriver_HeaderFile
#define _TOcafFunction_BoxDriver_HeaderFile
#include <TFunction_Driver.hxx>
#include <TFunction_Logbook.hxx>
//! Creation of an instance of the box driver. It's possible (and recommended)
//! to have only one instance of a driver for the whole session.
class TOcafFunction_BoxDriver : public TFunction_Driver
{
DEFINE_STANDARD_RTTI_INLINE(TOcafFunction_BoxDriver, TFunction_Driver)
public:
Standard_EXPORT static const Standard_GUID& GetID();
public:
TOcafFunction_BoxDriver() {}
//! Validation of the object label, its arguments and its results.
Standard_EXPORT virtual void Validate (Handle(TFunction_Logbook)& theLog) const Standard_OVERRIDE;
//! We call this method to check if the object was modified to be invoked.
//! If the object label or an argument is modified, we must recompute the object - to call the method Execute().
Standard_EXPORT virtual Standard_Boolean MustExecute (const Handle(TFunction_Logbook)& theLog) const Standard_OVERRIDE;
//! We compute the object and topologically name it.
//! If during the execution we found something wrong, we return the number of the failure.
//! For example:
//! 1 - an attribute hasn't been found,
//! 2 - algorithm failed,
//! if there are no any mistakes occurred we return 0:
//! 0 - no mistakes were found.
Standard_EXPORT virtual Standard_Integer Execute (Handle(TFunction_Logbook)& theLog) const Standard_OVERRIDE;
};
#endif

View File

@@ -0,0 +1,152 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "TOcafFunction_CutDriver.h"
#include <TNaming_NamedShape.hxx>
#include <TNaming_Builder.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <Standard_GUID.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_Tool.hxx>
#include <TDF_Reference.hxx>
#include <TFunction_Logbook.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QMessageBox>
#include <QApplication>
#include <QObject>
#include <Standard_WarningsRestore.hxx>
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& TOcafFunction_CutDriver::GetID()
{
static const Standard_GUID anID("22D22E52-D69A-11d4-8F1A-0060B0EE18E8");
return anID;
}
//=======================================================================
//function : Validate
//purpose :
//=======================================================================
void TOcafFunction_CutDriver::Validate (Handle(TFunction_Logbook)& log) const
{
// We validate the object label ( Label() ), all the arguments and the results of the object:
log->SetValid(Label(), Standard_True);
}
//=======================================================================
//function : MustExecute
//purpose :
//=======================================================================
Standard_Boolean TOcafFunction_CutDriver::MustExecute(const Handle(TFunction_Logbook)& log) const
{
// If the object's label is modified:
if (log->IsModified(Label())) return Standard_True;
// Cut (in our simple case) has two arguments: The original shape, and the tool shape.
// They are on the child labels of the cut's label:
// So, OriginalNShape - is attached to the first child label
// ToolNShape - is attached to the second child label,
// .
// Let's check them:
Handle(TDF_Reference) OriginalRef;
//TDF_Label aLabel = Label().FindChild(1);
/*
BOOL f = Label().IsNull();
int a = Label().NbChildren();
*/
TCollection_AsciiString aEntry;
TDF_Tool::Entry(Label(), aEntry);
std::cout << "Entry: " << aEntry.ToCString() << std::endl;
Label().FindChild(1).FindAttribute(TDF_Reference::GetID(), OriginalRef);
if (log->IsModified(OriginalRef->Get())) return Standard_True; // Original shape.
Handle(TDF_Reference) ToolRef;
Label().FindChild(2).FindAttribute(TDF_Reference::GetID(), ToolRef);
if (log->IsModified(ToolRef->Get())) return Standard_True; // Tool shape.
// if there are no any modifications concerned the cut,
// it's not necessary to recompute (to call the method Execute()):
return Standard_False;
}
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer TOcafFunction_CutDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
{
// Let's get the arguments (OriginalNShape, ToolNShape of the object):
// First, we have to retrieve the TDF_Reference attributes to obtain
// the root labels of the OriginalNShape and the ToolNShape:
Handle(TDF_Reference) OriginalRef, ToolRef;
if (!Label().FindChild(1).FindAttribute(TDF_Reference::GetID(), OriginalRef))
{
return 1;
}
TDF_Label OriginalLab = OriginalRef->Get();
if (!Label().FindChild(2).FindAttribute(TDF_Reference::GetID(), ToolRef))
{
return 1;
}
TDF_Label ToolLab = ToolRef->Get();
// Get the TNaming_NamedShape attributes of these labels
Handle(TNaming_NamedShape) OriginalNShape, ToolNShape;
if (!(OriginalLab.FindAttribute(TNaming_NamedShape::GetID(), OriginalNShape)))
{
throw Standard_Failure("TOcaf_Commands::CutObjects");
}
if (!(ToolLab.FindAttribute(TNaming_NamedShape::GetID(), ToolNShape)))
{
throw Standard_Failure("TOcaf_Commands::CutObjects");
}
// Now, let's get the TopoDS_Shape of these TNaming_NamedShape:
TopoDS_Shape OriginalShape = OriginalNShape->Get();
TopoDS_Shape ToolShape = ToolNShape->Get();
// STEP 2:
// Let's call for algorithm computing a cut operation:
BRepAlgoAPI_Cut mkCut(OriginalShape, ToolShape);
// Let's check if the Cut has been successful:
if (!mkCut.IsDone())
{
QMessageBox::critical(qApp->activeWindow(),
QObject::tr("Cut Function Driver"),
QObject::tr("Cut not done."));
return 2;
}
TopoDS_Shape ResultShape = mkCut.Shape();
// Build a TNaming_NamedShape using built cut
TNaming_Builder B(Label());
B.Modify(OriginalShape, ResultShape);
// That's all:
// If there are no any mistakes we return 0:
return 0;
}

View File

@@ -0,0 +1,57 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef _TOcafFunction_CutDriver_HeaderFile
#define _TOcafFunction_CutDriver_HeaderFile
#include <TFunction_Driver.hxx>
#include <TFunction_Logbook.hxx>
//! Creation of an instance of the cut driver. It's possible (and recommended)
//! to have only one instance of a driver for the whole session.
class TOcafFunction_CutDriver : public TFunction_Driver
{
DEFINE_STANDARD_RTTI_INLINE(TOcafFunction_CutDriver, TFunction_Driver)
public:
Standard_EXPORT static const Standard_GUID& GetID();
public:
TOcafFunction_CutDriver() {}
//! Validation of the object label, its arguments and its results.
Standard_EXPORT virtual void Validate (Handle(TFunction_Logbook)& theLog) const Standard_OVERRIDE;
//! We call this method to check if the object was modified to be invoked.
//! If the object label or an argument is modified, we must recompute the object - to call the method Execute().
Standard_EXPORT virtual Standard_Boolean MustExecute (const Handle(TFunction_Logbook)& theLog) const Standard_OVERRIDE;
//! We compute the object and topologically name it.
//! If during the execution we found something wrong, we return the number of the failure.
//! For example:
//! 1 - an attribute hasn't been found,
//! 2 - algorithm failed,
//! if there are no any mistakes occurred we return 0:
//! 0 - no mistakes were found.
Standard_EXPORT virtual Standard_Integer Execute (Handle(TFunction_Logbook)& theLog) const Standard_OVERRIDE;
};
#endif

View File

@@ -0,0 +1,147 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "TOcafFunction_CylDriver.h"
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <Standard_GUID.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_Tool.hxx>
#include <TDataStd_Real.hxx>
#include <TNaming_Builder.hxx>
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& TOcafFunction_CylDriver::GetID()
{
static const Standard_GUID anID("22D22E53-D69A-11d4-8F1A-0060B0EE18E8");
return anID;
}
//=======================================================================
//function : TPartStd_CylDriver
//purpose :
//=======================================================================
TOcafFunction_CylDriver::TOcafFunction_CylDriver()
{
//
}
//=======================================================================
//function : Validate
//purpose :
//=======================================================================
void TOcafFunction_CylDriver::Validate (Handle(TFunction_Logbook)& log) const
{
// We validate the object label ( Label() ), all the arguments and the results of the object:
log->SetValid(Label(), Standard_True);
}
//=======================================================================
//function : MustExecute
//purpose :
//=======================================================================
Standard_Boolean TOcafFunction_CylDriver::MustExecute(const Handle(TFunction_Logbook)& log) const
{
// If the object's label is modified:
if (log->IsModified(Label())) return Standard_True;
// Cylinder (in our simple case) has 5 arguments:
//
// Let's check them:
if (log->IsModified(Label().FindChild(1)))
{
return Standard_True; // radius.
}
if (log->IsModified(Label().FindChild(2)))
{
return Standard_True; // height,
}
if (log->IsModified(Label().FindChild(3)))
{
return Standard_True; // x.
}
if (log->IsModified(Label().FindChild(4)))
{
return Standard_True; // y,
}
if (log->IsModified(Label().FindChild(5)))
{
return Standard_True; // z.
}
// if there are no any modifications concerned the Cyl,
// it's not necessary to recompute (to call the method Execute()):
return Standard_False;
}
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer TOcafFunction_CylDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
{
// Get the values of dimension and position attributes
Handle(TDataStd_Real) TSR;
Standard_Real x, y, z, r, h;
if (!Label().FindChild(1).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
r = TSR->Get();
if (!Label().FindChild(2).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
h = TSR->Get();
if (!Label().FindChild(3).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
x = TSR->Get();
if (!Label().FindChild(4).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
y = TSR->Get();
if (!Label().FindChild(5).FindAttribute(TDataStd_Real::GetID(), TSR))
{
return 1;
}
z = TSR->Get();
// Build a Cyl using the dimension and position attributes
BRepPrimAPI_MakeCylinder mkCyl(gp_Ax2(gp_Pnt(x, y, z), gp_Dir(0, 0, 1)), r, h);
TopoDS_Shape ResultShape = mkCyl.Shape();
// Build a TNaming_NamedShape using built Cyl
TNaming_Builder B(Label());
B.Generated(ResultShape);
// That's all:
// If there are no any mistakes we return 0:
return 0;
}

View File

@@ -0,0 +1,59 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef _TOcafFunction_CylDriver_HeaderFile
#define _TOcafFunction_CylDriver_HeaderFile
#include <TFunction_Driver.hxx>
#include <TFunction_Logbook.hxx>
//! Creation of an instance of the cylinder driver. It's possible (and recommended)
//! to have only one instance of a driver for the whole session.
class TOcafFunction_CylDriver : public TFunction_Driver
{
DEFINE_STANDARD_RTTI_INLINE(TOcafFunction_CylDriver, TFunction_Driver)
public:
Standard_EXPORT static const Standard_GUID& GetID();
public:
//! Creation of an instance of the driver. It's possible (and recommended)
//! to have only one instance of a driver for the whole session.
Standard_EXPORT TOcafFunction_CylDriver();
//! Validation of the object label, its arguments and its results.
Standard_EXPORT virtual void Validate (Handle(TFunction_Logbook)& theLog) const Standard_OVERRIDE;
//! We call this method to check if the object was modified to be invoked.
//! If the object label or an argument is modified, we must recompute the object - to call the method Execute().
Standard_EXPORT virtual Standard_Boolean MustExecute (const Handle(TFunction_Logbook)& theLog) const Standard_OVERRIDE;
//! We compute the object and topologically name it.
//! If during the execution we found something wrong,
//! we return the number of the failure. For example:
//! 1 - an attribute hasn't been found,
//! 2 - algorithm failed,
//! if there are no any mistakes occurred we return 0:
//! 0 - no mistakes were found.
Standard_EXPORT virtual Standard_Integer Execute (Handle(TFunction_Logbook)& theLog) const Standard_OVERRIDE;
};
#endif

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "TOcaf_Application.h"
#include <TDF_Label.hxx>
#include <TFunction_DriverTable.hxx>
#include <TNaming_NamedShape.hxx>
#include <TPrsStd_AISPresentation.hxx>
#include <TPrsStd_AISViewer.hxx>
#include "TOcafFunction_BoxDriver.h"
#include "TOcafFunction_CylDriver.h"
#include "TOcafFunction_CutDriver.h"
//=======================================================================
//function : TOcaf_Application
//purpose :
//=======================================================================
TOcaf_Application::TOcaf_Application()
{
// Instantiate a TOcafFunction_BoxDriver and add it to the TFunction_DriverTable
TFunction_DriverTable::Get()->AddDriver (TOcafFunction_BoxDriver::GetID(),
new TOcafFunction_BoxDriver());
// Instantiate a TOcafFunction_Cyl Driver and add it to the TFunction_DriverTable
TFunction_DriverTable::Get()->AddDriver (TOcafFunction_CylDriver::GetID(),
new TOcafFunction_CylDriver());
// Instantiate a TOcafFunction_CutDriver and add it to the TFunction_DriverTable
Handle(TOcafFunction_CutDriver) myCutDriver = new TOcafFunction_CutDriver();
TFunction_DriverTable::Get()->AddDriver (TOcafFunction_CutDriver::GetID(),
new TOcafFunction_CutDriver());
}

View File

@@ -0,0 +1,37 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef _TOcaf_Application_HeaderFile
#define _TOcaf_Application_HeaderFile
#include <TColStd_SequenceOfExtendedString.hxx>
#include <TDocStd_Application.hxx>
//! Sample OCAF application
class TOcaf_Application : public TDocStd_Application
{
DEFINE_STANDARD_RTTI_INLINE(TOcaf_Application, TDocStd_Application)
public:
Standard_EXPORT TOcaf_Application();
};
#endif

View File

@@ -0,0 +1,176 @@
{
"Topology": {
"Topological Shape": [{
"text": "Vertex",
"function": "Vertex3dSample",
"description": ""
},
{
"text": "Edge",
"function": "Edge3dSample",
"description": ""
},
{
"text": "Face",
"function": "Face3dSample",
"description": ""
},
{
"text": "Wire",
"function": "Wire3dSample",
"description": ""
},
{
"text": "Shell",
"function": "Shell3dSample",
"description": ""
},
{
"text": "Solid",
"function": "Solid3dSample",
"description": ""
},
{
"text": "Edge (2D)",
"function": "Edge2dSample",
"description": ""
}
],
"BRep primitive objects": [{
"text": "Box",
"function": "Box3dSample",
"description": ""
},
{
"text": "Cylinder",
"function": "Cylinder3dSample",
"description": ""
},
{
"text": "Revolution",
"function": "Revolution3dSample",
"description": ""
}
],
"Topology access": [{
"text": "Topology iterator",
"function": "TopologyIterator3dSample",
"description": ""
},
{
"text": "Topology explorer",
"function": "TopologyExplorer3dSample",
"description": ""
},
{
"text": "Assess to curve",
"function": "AssessToCurve3dSample",
"description": ""
},
{
"text": "Assess to composite curve",
"function": "AssessToCompositeCurve3dSample",
"description": ""
},
{
"text": "Assess to surface",
"function": "AssessToSurface3dSample",
"description": ""
}
],
"Boolean operation": [{
"text": "Common",
"function": "Common3dSample",
"description": ""
},
{
"text": "Cut",
"function": "Cut3dSample",
"description": ""
},
{
"text": "Fuse",
"function": "Fuse3dSample",
"description": ""
},
{
"text": "Section",
"function": "Section3dSample",
"description": ""
},
{
"text": "Splitter",
"function": "Splitter3dSample",
"description": ""
},
{
"text": "Defeaturing",
"function": "Defeaturing3dSample",
"description": ""
}
],
"Complex modelling": [{
"text": "Fillet",
"function": "Fillet3dSample",
"description": ""
},
{
"text": "Chamfer",
"function": "Chamfer3dSample",
"description": ""
},
{
"text": "Offset",
"function": "Offset3dSample",
"description": ""
},
{
"text": "Evolved",
"function": "Evolved3dSample",
"description": ""
}
],
"Modification": [{
"text": "Copy",
"function": "Copy3dSample",
"description": ""
},
{
"text": "Transform",
"function": "Transform3dSample",
"description": ""
},
{
"text": "Convert to NURBS",
"function": "ConvertToNurbs3dSample",
"description": ""
},
{
"text": "Sew contiguous faces",
"function": "SewContiguousFaces3dSample",
"description": ""
}
],
"Calculation": [{
"text": "Check validity",
"function": "CheckValidity3dSample",
"description": ""
},
{
"text": "Compute linear properties",
"function": "ComputeLinearProperties3dSample",
"description": ""
},
{
"text": "Compute surface properties",
"function": "ComputeSurfaceProperties3dSample",
"description": ""
},
{
"text": "Compute volume properties",
"function": "ComputeVolumeProperties3dSample",
"description": ""
}
]
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,80 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef TOPOLOGYSAMPLES_H
#define TOPOLOGYSAMPLES_H
#include "BaseSample.h"
#include <AIS_InteractiveContext.hxx>
//! Implements Topology samples
class TopologySamples : public BaseSample
{
DEFINE_STANDARD_RTTI_INLINE(TopologySamples, BaseSample)
public:
TopologySamples (const TCollection_AsciiString& theSampleSourcePath,
const Handle(AIS_InteractiveContext)& theContext)
: BaseSample(theSampleSourcePath, theContext)
{}
protected:
virtual void ExecuteSample (const TCollection_AsciiString& theSampleName) Standard_OVERRIDE;
private:
// One function for every sample
void Vertex3dSample();
void Edge3dSample();
void Face3dSample();
void Wire3dSample();
void Shell3dSample();
void Solid3dSample();
void Edge2dSample();
void Box3dSample();
void Cylinder3dSample();
void Revolution3dSample();
void TopologyIterator3dSample();
void TopologyExplorer3dSample();
void AssessToCurve3dSample();
void AssessToCompositeCurve3dSample();
void AssessToSurface3dSample();
void Common3dSample();
void Cut3dSample();
void Fuse3dSample();
void Section3dSample();
void Splitter3dSample();
void Defeaturing3dSample();
void Fillet3dSample();
void Chamfer3dSample();
void Offset3dSample();
void Evolved3dSample();
void Copy3dSample();
void Transform3dSample();
void ConvertToNurbs3dSample();
void SewContiguousFaces3dSample();
void CheckValidity3dSample();
void ComputeLinearProperties3dSample();
void ComputeSurfaceProperties3dSample();
void ComputeVolumeProperties3dSample();
};
#endif //TOPOLOGYSAMPLES_H

View File

@@ -0,0 +1,10 @@
{
"Triangulation": {
"Create Triangulation": [{
"text": "Triangulation on shape",
"function": "Triangulation3dSample",
"description": ""
}]
}
}

View File

@@ -0,0 +1,118 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "TriangulationSamples.h"
#include "MakeBottle.h"
#include <AIS_Shape.hxx>
#include <AIS_Triangulation.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <BRep_Tool.hxx>
#include <BRep_Builder.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Poly_Triangulation.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
void TriangulationSamples::ExecuteSample (const TCollection_AsciiString& theSampleName)
{
Standard_Boolean anIsSamplePresent = Standard_True;
FindSourceCode(theSampleName);
if (theSampleName == "Triangulation3dSample")
{
Triangulation3dSample();
}
else
{
myResult << "No function found: " << theSampleName;
myCode += TCollection_AsciiString("No function found: ") + theSampleName;
anIsSamplePresent = Standard_False;
}
myIsProcessed = anIsSamplePresent;
}
void TriangulationSamples::Triangulation3dSample()
{
TopoDS_Shape aBottle = MakeBottle(50, 70, 30);
BRepMesh_IncrementalMesh(aBottle, 1);
BRep_Builder aBuilder;
TopoDS_Compound aCompound;
aBuilder.MakeCompound(aCompound);
Standard_Integer aNbTriangles(0);
for (TopExp_Explorer anExplorer(aBottle, TopAbs_FACE); anExplorer.More(); anExplorer.Next())
{
TopoDS_Face aFace = TopoDS::Face(anExplorer.Current());
TopLoc_Location aLocation;
Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(aFace, aLocation);
TColgp_Array1OfPnt aTriangNodes(1, (aTriangulation->NbNodes()));
aTriangNodes = aTriangulation->Nodes();
Poly_Array1OfTriangle aTriangles(1, aTriangulation->NbTriangles());
aTriangles = aTriangulation->Triangles();
for (Standard_Integer i = 1; i <= (aTriangulation->NbTriangles()); i++)
{
Poly_Triangle trian = aTriangles.Value(i);
Standard_Integer index1, index2, index3, M = 0, N = 0;
trian.Get(index1, index2, index3);
for (Standard_Integer j = 1; j <= 3; j++)
{
switch (j)
{
case 1:
M = index1;
N = index2;
break;
case 2:
N = index3;
break;
case 3:
M = index2;
}
BRepBuilderAPI_MakeEdge anEdgeMaker(aTriangNodes.Value(M), aTriangNodes.Value(N));
if (anEdgeMaker.IsDone())
{
aBuilder.Add(aCompound, anEdgeMaker.Edge());
}
}
}
Handle(AIS_Triangulation) anAisTriangulation = new AIS_Triangulation(aTriangulation);
aNbTriangles += aTriangulation->NbTriangles();
myObject3d.Append(anAisTriangulation);
}
Handle(AIS_Shape) anAisCompound = new AIS_Shape(aCompound);
myObject3d.Append(anAisCompound);
Handle(AIS_Shape) AISBottle = new AIS_Shape(aBottle);
myObject3d.Append(AISBottle);
myResult << "Compute the triangulation on a shape: " << aNbTriangles;
}

View File

@@ -0,0 +1,49 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef TRIANGULATIONSAMPLES_H
#define TRIANGULATIONSAMPLES_H
#include "BaseSample.h"
//! Implements Triangulation sample
class TriangulationSamples : public BaseSample
{
DEFINE_STANDARD_RTTI_INLINE(TriangulationSamples, BaseSample)
public:
TriangulationSamples (const TCollection_AsciiString& theSampleSourcePath,
const Handle(AIS_InteractiveContext)& theContext)
: BaseSample (theSampleSourcePath, theContext)
{
//
}
protected:
virtual void ExecuteSample (const TCollection_AsciiString& theSampleName) Standard_OVERRIDE;
private:
// One function for every sample
void Triangulation3dSample();
};
#endif //TRIANGULATIONSAMPLES_H

View File

@@ -0,0 +1,58 @@
{
"Viewer 2D": {
"Labels": [{
"text": "Text",
"function": "TextView2dSample",
"description": ""
},
{
"text": "Marker",
"function": "MarkerView2dSample",
"description": ""
},
{
"text": "Fill Area",
"function": "FillAreaView2dSample",
"description": ""
},
{
"text": "Loop on face",
"function": "LoopOnFaceView2dSample",
"description": ""
}
],
"Grids": [{
"text": "Rectagular Lines",
"function": "RectagularLineGrid2dSample",
"description": ""
},
{
"text": "Rectagular Points",
"function": "RectagularPointGrid2dSample",
"description": ""
},
{
"text": "Circular Lines",
"function": "CircularLineGrid2dSample",
"description": ""
},
{
"text": "Circular Points",
"function": "CircularPointGrid2dSample",
"description": ""
},
{
"text": "Clear",
"function": "ClearGrid2dSample",
"description": ""
}
],
"Image": [{
"text": "Backgroung Image",
"function": "BackgroungImage2dSample",
"description": ""
}]
}
}

View File

@@ -0,0 +1,282 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "Viewer2dSamples.h"
#include "Sample2D_Markers.h"
#include "Sample2D_Face.h"
#include "Sample2D_Image.h"
#include <AIS_ColoredShape.hxx>
#include <AIS_TextLabel.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <Quantity_NameOfColor.hxx>
void Viewer2dSamples::ExecuteSample (const TCollection_AsciiString& theSampleName)
{
Standard_Boolean anIsSamplePresent = Standard_True;
FindSourceCode(theSampleName);
if (theSampleName == "TextView2dSample")
TextView2dSample();
else if (theSampleName == "MarkerView2dSample")
MarkerView2dSample();
else if (theSampleName == "FillAreaView2dSample")
FillAreaView2dSample();
else if (theSampleName == "LoopOnFaceView2dSample")
LoopOnFaceView2dSample();
else if (theSampleName == "RectagularLineGrid2dSample")
RectagularLineGrid2dSample();
else if (theSampleName == "RectagularPointGrid2dSample")
RectagularPointGrid2dSample();
else if (theSampleName == "CircularLineGrid2dSample")
CircularLineGrid2dSample();
else if (theSampleName == "CircularPointGrid2dSample")
CircularPointGrid2dSample();
else if (theSampleName == "ClearGrid2dSample")
ClearGrid2dSample();
else if (theSampleName == "BackgroungImage2dSample")
BackgroungImage2dSample();
else {
myResult << "No function found: " << theSampleName;
myCode += TCollection_AsciiString("No function found: ") + theSampleName;
anIsSamplePresent = Standard_False;
}
myIsProcessed = anIsSamplePresent;
}
void Viewer2dSamples::ClearExtra()
{
myContext->RemoveAll(Standard_True);
myViewer->DeactivateGrid();
}
void Viewer2dSamples::TextView2dSample()
{
Standard_Integer aColor = Quantity_NameOfColor::Quantity_NOC_MATRABLUE;
for (Standard_Integer j = 15; j <= 20; j++)
{
Handle(AIS_TextLabel) aText = new AIS_TextLabel();
aText->SetText(TCollection_AsciiString("font 0 scale ") + (j / 20.0));
aText->SetPosition(gp_Pnt(0.0, 15.0 * (j - 15.0), 0.0));
aText->SetAngle(30.0 * M_PI / 180.0);
aText->SetColor(Quantity_NameOfColor(aColor++));
aText->SetFontAspect(Font_FA_Regular);
aText->SetFont("Courier");
aText->SetHeight(j);
aText->SetHJustification(Graphic3d_HTA_LEFT);
aText->SetVJustification(Graphic3d_VTA_BOTTOM);
aText->SetZoomable(Standard_False);
myObject2d.Append(aText);
}
for (Standard_Real j = 10; j <= 15; j++)
{
Handle(AIS_TextLabel) aText = new AIS_TextLabel();
aText->SetText(TCollection_AsciiString("font 1 scale ") + (j / 10.0));
aText->SetPosition(gp_Pnt(80.0, 15.0 * (j - 10.0), 0.0));
aText->SetAngle(0.0);
aText->SetColor(Quantity_NameOfColor(aColor++));
aText->SetFontAspect(Font_FA_BoldItalic);
aText->SetFont("Cambria");
aText->SetHeight(j * 2);
aText->SetHJustification(Graphic3d_HTA_LEFT);
aText->SetVJustification(Graphic3d_VTA_BOTTOM);
aText->SetZoomable(Standard_False);
myObject2d.Append(aText);
}
aColor = Quantity_NOC_MATRABLUE;
for (Standard_Real j = 5; j <= 10; j++)
{
Handle(AIS_TextLabel) aText = new AIS_TextLabel();
aText->SetText(TCollection_AsciiString("font 2 scale ") + (j / 10.0));
aText->SetPosition(gp_Pnt(140.0, 15.0 * (j - 5.0), 0.0));
aText->SetAngle(0.0);
aText->SetColor(Quantity_NameOfColor(aColor++));
aText->SetFontAspect(Font_FA_Bold);
aText->SetFont("Arial");
aText->SetHeight(j * 2);
aText->SetHJustification(Graphic3d_HTA_LEFT);
aText->SetVJustification(Graphic3d_VTA_BOTTOM);
aText->SetZoomable(Standard_False);
myObject2d.Append(aText);
}
for (Standard_Real j = 10; j <= 15; j++)
{
Handle(AIS_TextLabel) aText = new AIS_TextLabel();
aText->SetText(TCollection_AsciiString("font 3 scale ") + (j / 10.0));
aText->SetPosition(gp_Pnt(200.0, 15.0 * (j - 10.0), 0.0));
aText->SetAngle(0.0);
aText->SetColor(Quantity_NameOfColor(aColor++));
aText->SetFontAspect(Font_FA_Italic);
aText->SetFont("Georgia");
aText->SetHeight(j * 2);
aText->SetHJustification(Graphic3d_HTA_LEFT);
aText->SetVJustification(Graphic3d_VTA_BOTTOM);
aText->SetZoomable(Standard_False);
myObject2d.Append(aText);
}
}
void Viewer2dSamples::MarkerView2dSample()
{
// generic Markers
Standard_Integer aColor = 20;
for (int i = 1; i <= 2; i++)
{
Handle(Sample2D_Markers) aMarker = new Sample2D_Markers(10 + 5, 5 * i, Aspect_TOM_POINT, Quantity_NOC_YELLOW, 2.0);
myObject2d.Append(aMarker);
}
for (int i = 1; i <= 2; i++)
{
Handle(Sample2D_Markers) aMarker = new Sample2D_Markers(10 + 10, 5 * i, Aspect_TOM_O, (Quantity_NameOfColor)(aColor++));
myObject2d.Append(aMarker);
}
for (int i = 1; i <= 2; i++)
{
Handle(Sample2D_Markers) aMarker = new Sample2D_Markers(10 + 15, 5 * i, Aspect_TOM_O_PLUS, (Quantity_NameOfColor)(aColor++));
myObject2d.Append(aMarker);
}
for (int i = 1; i <= 2; i++)
{
Handle(Sample2D_Markers) aMarker = new Sample2D_Markers(10 + 20, 5 * i, Aspect_TOM_RING1, (Quantity_NameOfColor)(aColor++));
myObject2d.Append(aMarker);
}
for (int i = 1; i <= 2; i++)
{
Handle(Sample2D_Markers) aMarker = new Sample2D_Markers(10 + 25, 5 * i, Aspect_TOM_STAR, (Quantity_NameOfColor)(aColor++));
myObject2d.Append(aMarker);
}
for (int i = 1; i <= 2; i++)
{
Handle(Sample2D_Markers) aMarker = new Sample2D_Markers(10 + 30, 5 * i, Aspect_TOM_O_X, (Quantity_NameOfColor)(aColor++));
myObject2d.Append(aMarker);
}
}
void Viewer2dSamples::FillAreaView2dSample()
{
for (int i = 0; i <= 13; ++i)
{
for (int j = 0; j <= 5; ++j)
{
// set of rectangles here
TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(10 * i, 10 * j, 0.), gp_Pnt(10 * i + 7, 10 * j, 0.));
TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(10 * i + 7, 10 * j, 0.), gp_Pnt(10 * i + 7, 10 * j + 5, 0.));
TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(10 * i + 7, 10 * j + 5, 0.), gp_Pnt(10 * i, 10 * j + 5, 0.));
TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt(10 * i, 10 * j + 5, 0.), gp_Pnt(10 * i, 10 * j, 0.));
TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1, E2, E3, E4);
TopoDS_Face F = BRepBuilderAPI_MakeFace(W);
Handle(AIS_Shape) aRect = new AIS_Shape(F);
// set attributes of boundaries
Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer();
Handle(Prs3d_LineAspect) aLineAttrib = new Prs3d_LineAspect (Quantity_NOC_YELLOW,
(Aspect_TypeOfLine)(Aspect_TOL_SOLID + j), 1);
aDrawer->SetFaceBoundaryAspect(aLineAttrib);
aDrawer->SetFaceBoundaryDraw(Standard_True);
aRect->SetAttributes(aDrawer);
myContext->SetDisplayMode(aRect, 1, Standard_False);
myContext->SetColor(aRect, (Quantity_NameOfColor)(Quantity_NOC_CADETBLUE + 2 * i), Standard_False);
myContext->SetMaterial(aRect, Graphic3d_NOM_PLASTIC, Standard_False);
myObject2d.Append(aRect);
}
}
}
void Viewer2dSamples::LoopOnFaceView2dSample()
{
// Make a flat rectangular face on XY plane.
gp_Pln aPln(gp::XOY());
TopoDS_Face aFaceRect = BRepBuilderAPI_MakeFace(aPln, -10.0, +10.0, -20.0, +20.0);
Handle(AIS_ColoredShape) anAisFaceRect = new AIS_ColoredShape(aFaceRect);
anAisFaceRect->SetColor(Quantity_Color(Quantity_NOC_RED));
myObject2d.Append(anAisFaceRect);
TopoDS_Shape aFaceShape;
Handle(Sample2D_Face) anAISFace = new Sample2D_Face(aFaceRect);
myObject2d.Append(anAISFace);
}
void Viewer2dSamples::RectagularLineGrid2dSample()
{
Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1, Quantity_NOC_WHITE, 2);
myViewer->SetGridEcho(aGridAspect);
Standard_Integer aWidth = 0, aHeight = 0, anOffset = 0;
myView->Window()->Size(aWidth, aHeight);
myViewer->SetRectangularGridGraphicValues(aWidth, aHeight, anOffset);
myViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Lines);
myViewer->Redraw();
}
void Viewer2dSamples::RectagularPointGrid2dSample()
{
Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1, Quantity_NOC_WHITE, 2);
myViewer->SetGridEcho(aGridAspect);
Standard_Integer aWidth = 0, aHeight = 0, anOffset = 0;
myView->Window()->Size(aWidth, aHeight);
myViewer->SetRectangularGridGraphicValues(aWidth, aHeight, anOffset);
myViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Points);
myViewer->Redraw();
}
void Viewer2dSamples::CircularLineGrid2dSample()
{
Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1, Quantity_NOC_WHITE, 2);
myViewer->SetGridEcho(aGridAspect);
Standard_Integer aWidth = 0, aHeight = 0, anOffset = 0;
myView->Window()->Size(aWidth, aHeight);
myViewer->SetRectangularGridGraphicValues(aWidth, aHeight, anOffset);
myViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Lines);
myViewer->Redraw();
}
void Viewer2dSamples::CircularPointGrid2dSample()
{
Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1, Quantity_NOC_WHITE, 2);
myViewer->SetGridEcho(aGridAspect);
Standard_Integer aWidth = 0, aHeight = 0, anOffset = 0;
myView->Window()->Size(aWidth, aHeight);
myViewer->SetRectangularGridGraphicValues(aWidth, aHeight, anOffset);
myViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Points);
myViewer->Redraw();
}
void Viewer2dSamples::ClearGrid2dSample()
{
myViewer->DeactivateGrid();
myViewer->Redraw();
}
void Viewer2dSamples::BackgroungImage2dSample()
{
Handle(Sample2D_Image) anImage = new Sample2D_Image(myFileName);
anImage->SetCoord(40, 50);
anImage->SetScale(1.0);
myObject2d.Append(anImage);
}

View File

@@ -0,0 +1,76 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef VIEWER2DSAMPLES_H
#define VIEWER2DSAMPLES_H
#include "BaseSample.h"
#include <AIS_InteractiveContext.hxx>
#include <V3d_View.hxx>
//! Implements viewer 2D samples.
class Viewer2dSamples : public BaseSample
{
DEFINE_STANDARD_RTTI_INLINE(Viewer2dSamples, BaseSample)
public:
Viewer2dSamples(const TCollection_AsciiString& theSampleSourcePath,
const Handle(V3d_View)& theView,
const Handle(V3d_Viewer)& theViewer,
const Handle(AIS_InteractiveContext)& theContext)
: BaseSample (theSampleSourcePath, theContext),
myView (theView),
myViewer (theViewer)
{}
void SetFileName (const TCollection_AsciiString& theFileName) { myFileName = theFileName; }
void ClearExtra();
static Standard_Boolean IsFileSample (const TCollection_AsciiString& theSampleName) { return theSampleName == "BackgroungImage2dSample"; }
static Standard_Boolean IsShadedSample(const TCollection_AsciiString& theSampleName) { return theSampleName == "BackgroungImage2dSample"; }
protected:
virtual void ExecuteSample (const TCollection_AsciiString& theSampleName) Standard_OVERRIDE;
private:
// One function for every sample
void TextView2dSample();
void MarkerView2dSample();
void FillAreaView2dSample();
void LoopOnFaceView2dSample();
void RectagularLineGrid2dSample();
void RectagularPointGrid2dSample();
void CircularLineGrid2dSample();
void CircularPointGrid2dSample();
void ClearGrid2dSample();
void BackgroungImage2dSample();
private:
TCollection_AsciiString myFileName;
Handle(V3d_View) myView;
Handle(V3d_Viewer) myViewer;
};
#endif // VIEWER2DSAMPLES_H

View File

@@ -0,0 +1,106 @@
{
"Viewer 3D": {
"Light source": [{
"text": "Spot",
"function": "SpotLight3dSample",
"description": ""
},
{
"text": "Positional",
"function": "PositionalLight3dSample",
"description": ""
},
{
"text": "Directional",
"function": "DirectionalLight3dSample",
"description": ""
},
{
"text": "Ambient",
"function": "AmbientLight3dSample",
"description": ""
},
{
"text": "Clear",
"function": "ClearLight3dSample",
"description": ""
}
],
"Selection mode": [{
"text": "Vertices",
"function": "VerticesSelect3dSample",
"description": ""
},
{
"text": "Edges",
"function": "EdgesSelect3dSample",
"description": ""
},
{
"text": "Faces",
"function": "FacesSelect3dSample",
"description": ""
},
{
"text": "Neutral point",
"function": "NeutralPointSelect3dSample",
"description": ""
}
],
"Shape presentation": [
{
"text": "WireFrame",
"function": "WireFramePresentation3dSample",
"description": ""
},
{
"text": "Shading",
"function": "ShadingPresentation3dSample",
"description": ""
},
{
"text": "Set color to red",
"function": "RedColorPresentation3dSample",
"description": ""
},
{
"text": "Set color to gray",
"function": "GrayColorPresentation3dSample",
"description": ""
},
{
"text": "Set plastic material",
"function": "PlasticPresentation3dSample",
"description": ""
},
{
"text": "Set bronze material",
"function": "BronzePresentation3dSample",
"description": ""
},
{
"text": "Set opaque",
"function": "OpaquePresentation3dSample",
"description": ""
},
{
"text": "Set half transparency",
"function": "HalfTransparencyPresentation3dSample",
"description": ""
}
],
"OpenGL VBO mode": [{
"text": "Vertex Buffer Object mode ON",
"function": "VboOn3dSample",
"description": ""
},
{
"text": "Vertex Buffer Object mode OFF",
"function": "VboOff3dSample",
"description": ""
}
]
}
}

View File

@@ -0,0 +1,312 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#include "Viewer3dSamples.h"
#include "MakeBottle.h"
#include <AIS_Shape.hxx>
#include <AIS_ViewCube.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <V3d_SpotLight.hxx>
#include <V3d_PositionalLight.hxx>
#include <V3d_DirectionalLight.hxx>
#include <V3d_AmbientLight.hxx>
void Viewer3dSamples::ExecuteSample (const TCollection_AsciiString& theSampleName)
{
Standard_Boolean anIsSamplePresent = Standard_True;
FindSourceCode(theSampleName);
if (theSampleName == "SpotLight3dSample")
SpotLight3dSample();
else if (theSampleName == "PositionalLight3dSample")
PositionalLight3dSample();
else if (theSampleName == "DirectionalLight3dSample")
DirectionalLight3dSample();
else if (theSampleName == "AmbientLight3dSample")
AmbientLight3dSample();
else if (theSampleName == "ClearLight3dSample")
ClearLight3dSample();
else if (theSampleName == "VerticesSelect3dSample")
VerticesSelect3dSample();
else if (theSampleName == "EdgesSelect3dSample")
EdgesSelect3dSample();
else if (theSampleName == "FacesSelect3dSample")
FacesSelect3dSample();
else if (theSampleName == "NeutralPointSelect3dSample")
NeutralPointSelect3dSample();
else if (theSampleName == "WireFramePresentation3dSample")
WireFramePresentation3dSample();
else if (theSampleName == "ShadingPresentation3dSample")
ShadingPresentation3dSample();
else if (theSampleName == "RedColorPresentation3dSample")
RedColorPresentation3dSample();
else if (theSampleName == "GrayColorPresentation3dSample")
GrayColorPresentation3dSample();
else if (theSampleName == "PlasticPresentation3dSample")
PlasticPresentation3dSample();
else if (theSampleName == "BronzePresentation3dSample")
BronzePresentation3dSample();
else if (theSampleName == "OpaquePresentation3dSample")
OpaquePresentation3dSample();
else if (theSampleName == "HalfTransparencyPresentation3dSample")
HalfTransparencyPresentation3dSample();
else if (theSampleName == "VboOn3dSample")
VboOn3dSample();
else if (theSampleName == "VboOff3dSample")
VboOff3dSample();
else
{
myResult << "No function found: " << theSampleName;
myCode += TCollection_AsciiString("No function found: ") + theSampleName;
anIsSamplePresent = Standard_False;
}
myIsProcessed = anIsSamplePresent;
}
void Viewer3dSamples::AppendBottle()
{
TopoDS_Shape aBottle = MakeBottle(50, 70, 30);
Handle(AIS_InteractiveObject) aShape = new AIS_Shape(aBottle);
myObject3d.Append(aShape);
Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube();
myObject3d.Append(aViewCube);
myResult << "A bottle shape was created." << std::endl;
}
void Viewer3dSamples::ClearExtra()
{
NeutralPointSelect3dSample();
VboOff3dSample();
ClearLight3dSample();
// Delete Lights
V3d_ListOfLight aLights;
for (V3d_ListOfLightIterator anIter = myView->Viewer()->DefinedLightIterator(); anIter.More(); anIter.Next())
{
aLights.Append(anIter.Value());
}
for (V3d_ListOfLightIterator aLightIter (aLights); aLightIter.More(); aLightIter.Next())
{
myView->Viewer()->DelLight (aLightIter.Value());
}
myView->Viewer()->SetDefaultLights(); // Setting the default lights on
myView->Update();
myContext->RemoveAll (Standard_True);
}
void Viewer3dSamples::SpotLight3dSample()
{
// Spot light source creation
Handle(V3d_SpotLight) aSpotLight = new V3d_SpotLight(gp_Pnt(100.0, 0.0, 0.0), gp_Dir(-1.0, 0.0, 0.0), Quantity_NOC_RED);
aSpotLight->SetIntensity(5000);
myView->SetLightOn(aSpotLight);
}
void Viewer3dSamples::PositionalLight3dSample()
{
Handle(V3d_PositionalLight) aPositionalLight = new V3d_PositionalLight(gp_Pnt(0.0, -100.0, 5.0), Quantity_NOC_GREEN);
aPositionalLight->SetAttenuation(1, 0);
myView->SetLightOn(aPositionalLight);
}
void Viewer3dSamples::DirectionalLight3dSample()
{
Handle(V3d_DirectionalLight) aDirectionalLight = new V3d_DirectionalLight(gp_Dir(-1.0, 0.0, -1.0), Quantity_NOC_BLUE1);
myView->SetLightOn(aDirectionalLight);
}
void Viewer3dSamples::AmbientLight3dSample()
{
Handle(V3d_AmbientLight) aAmbientLight = new V3d_AmbientLight(Quantity_NOC_MAGENTA1);
myView->SetLightOn(aAmbientLight);
}
void Viewer3dSamples::ClearLight3dSample()
{
// Setting Off all viewer active lights
V3d_ListOfLight aLights;
for (V3d_ListOfLightIterator anIter = myView->Viewer()->ActiveLightIterator(); anIter.More(); anIter.Next())
{
aLights.Append(anIter.Value());
}
for (V3d_ListOfLightIterator aLightIter (aLights); aLightIter.More(); aLightIter.Next())
{
myView->Viewer()->SetLightOff (aLightIter.Value());
}
// Setting Off all view active lights
aLights.Clear();
for (V3d_ListOfLightIterator anIter = myView->ActiveLightIterator(); anIter.More(); anIter.Next())
{
aLights.Append(anIter.Value());
}
for (V3d_ListOfLightIterator aLightIter (aLights); aLightIter.More(); aLightIter.Next())
{
myView->SetLightOff (aLightIter.Value());
}
myView->Viewer()->SetDefaultLights(); // Setting the default lights on
myView->Update();
}
void Viewer3dSamples::VerticesSelect3dSample()
{
myContext->Deactivate();
myContext->Activate(AIS_Shape::SelectionMode(TopAbs_VERTEX));
}
void Viewer3dSamples::EdgesSelect3dSample()
{
myContext->Deactivate();
myContext->Activate(AIS_Shape::SelectionMode(TopAbs_EDGE));
}
void Viewer3dSamples::FacesSelect3dSample()
{
myContext->Deactivate();
myContext->Activate(AIS_Shape::SelectionMode(TopAbs_FACE));
}
void Viewer3dSamples::NeutralPointSelect3dSample()
{
myContext->Deactivate();
myContext->Activate(0);
}
void Viewer3dSamples::WireFramePresentation3dSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
myContext->SetDisplayMode(anAisObject, 0, false); // set wireframe
}
myContext->UpdateCurrentViewer();
}
void Viewer3dSamples::ShadingPresentation3dSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
myContext->SetDisplayMode(anAisObject, 1, false); // set shading
}
myContext->UpdateCurrentViewer();
}
void Viewer3dSamples::RedColorPresentation3dSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
Quantity_Color aShapeColor;
myContext->Color(anAisObject, aShapeColor);
myResult << "A Current shape color: Red = " << aShapeColor.Red()
<< " Green = " << aShapeColor.Green() << " Blue = " << aShapeColor.Blue() << std::endl;
aShapeColor.SetValues(0.8, 0.1, 0.1, Quantity_TOC_RGB);
myContext->SetColor(anAisObject, aShapeColor, Standard_False);
myResult << "A New shape color: Red = " << aShapeColor.Red()
<< " Green = " << aShapeColor.Green() << " Blue = " << aShapeColor.Blue() << std::endl;
}
}
void Viewer3dSamples::GrayColorPresentation3dSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
Quantity_Color aShapeColor;
myContext->Color(anAisObject, aShapeColor);
myResult << "A Current shape color: Hue = " << aShapeColor.Hue()
<< " Light = " << aShapeColor.Light() << " Saturation = " << aShapeColor.Saturation() << std::endl;
aShapeColor.SetValues(0.0, 0.3, 0.1, Quantity_TOC_HLS);
myContext->SetColor(anAisObject, aShapeColor, Standard_False);
myResult << "A New shape color: Hue = " << aShapeColor.Hue()
<< " Light = " << aShapeColor.Light() << " Saturation = " << aShapeColor.Saturation() << std::endl;
}
}
void Viewer3dSamples::PlasticPresentation3dSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
Graphic3d_NameOfMaterial aMaterial = Graphic3d_NOM_PLASTIC;
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
myContext->SetMaterial(anAisObject, aMaterial, Standard_False);
}
myContext->UpdateCurrentViewer();
}
void Viewer3dSamples::BronzePresentation3dSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
Graphic3d_NameOfMaterial aMaterial = Graphic3d_NOM_BRONZE;
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
myContext->SetMaterial(anAisObject, aMaterial, Standard_False);
}
myContext->UpdateCurrentViewer();
}
void Viewer3dSamples::OpaquePresentation3dSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
myContext->SetTransparency(anAisObject, 0.0, Standard_False);
}
myContext->UpdateCurrentViewer();
}
void Viewer3dSamples::HalfTransparencyPresentation3dSample()
{
AIS_ListOfInteractive anAisObjectsList;
myContext->DisplayedObjects(anAisObjectsList);
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
{
myContext->SetTransparency(anAisObject, 0.5, Standard_False);
}
myContext->UpdateCurrentViewer();
}
void Viewer3dSamples::VboOn3dSample()
{
if (Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myContext->CurrentViewer()->Driver()))
{
aDriver->ChangeOptions().vboDisable = Standard_False;
}
}
void Viewer3dSamples::VboOff3dSample()
{
if (Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myContext->CurrentViewer()->Driver()))
{
aDriver->ChangeOptions().vboDisable = Standard_True;
}
}

View File

@@ -0,0 +1,78 @@
// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of the examples of the Open CASCADE Technology software library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
#ifndef VIEWER3DSAMPLES_H
#define VIEWER3DSAMPLES_H
#include "BaseSample.h"
#include <AIS_InteractiveContext.hxx>
#include <V3d_View.hxx>
//! Implements viewer 3D samples.
class Viewer3dSamples : public BaseSample
{
DEFINE_STANDARD_RTTI_INLINE(Viewer3dSamples, BaseSample)
public:
Viewer3dSamples (const TCollection_AsciiString& theSampleSourcePath,
const Handle(V3d_View)& theView,
const Handle(AIS_InteractiveContext)& theContext)
: BaseSample (theSampleSourcePath, theContext),
myView (theView)
{}
void AppendBottle();
void ClearExtra();
protected:
virtual void ExecuteSample (const TCollection_AsciiString& theSampleName) Standard_OVERRIDE;
private:
// One function for every sample
void SpotLight3dSample();
void PositionalLight3dSample();
void DirectionalLight3dSample();
void AmbientLight3dSample();
void ClearLight3dSample();
void VerticesSelect3dSample();
void EdgesSelect3dSample();
void FacesSelect3dSample();
void NeutralPointSelect3dSample();
void WireFramePresentation3dSample();
void ShadingPresentation3dSample();
void RedColorPresentation3dSample();
void GrayColorPresentation3dSample();
void PlasticPresentation3dSample();
void BronzePresentation3dSample();
void OpaquePresentation3dSample();
void HalfTransparencyPresentation3dSample();
void VboOn3dSample();
void VboOff3dSample();
private:
Handle(V3d_View) myView;
};
#endif //VIEWER3DSAMPLES_H