From: Pasukhin Dmitry Date: Fri, 25 Jul 2025 09:38:48 +0000 (+0100) Subject: Samples - CMake configuration fix (#643) X-Git-Tag: V8_0_0_rc2~8 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=e42a043abe0f1549840752d0986c20601121cb21;p=occt.git Samples - CMake configuration fix (#643) - Migrates legacy text-based FILES, PACKAGES, and EXTERNLIB configuration files to proper CMake format (.cmake extensions) - Updates CMakeLists.txt files to use modern CMake practices with explicit configurations and target-specific definitions - Modifies the qt_macro.cmake to work with the new CMake variable-based file management system --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b1b6e962f3..74ba8ff1df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1174,7 +1174,6 @@ if (INSTALL_SAMPLES) OCCT_INSTALL_FILE_OR_DIR ("samples/java" "${INSTALL_DIR_SAMPLES}") OCCT_INSTALL_FILE_OR_DIR ("samples/ocafsamples" "${INSTALL_DIR_SAMPLES}") OCCT_INSTALL_FILE_OR_DIR ("samples/qt" "${INSTALL_DIR_SAMPLES}") - OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code" "${INSTALL_DIR_SAMPLES}/OCCTOverview") install (FILES "${CMAKE_BINARY_DIR}/env.samples.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR_SAMPLES}/qt/FuncDemo" RENAME "env.${SCRIPT_EXT}") install (FILES "${CMAKE_BINARY_DIR}/env.samples.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR_SAMPLES}/qt/IESample" RENAME "env.${SCRIPT_EXT}") @@ -1403,13 +1402,13 @@ if (BUILD_SAMPLES_QT) endforeach() ## Copy sources of OCCTOverview for using in the sample - OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/DataExchangeSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") - OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/OcafSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") - OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/GeometrySamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") - OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/TopologySamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") - OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/TriangulationSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") - OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/Viewer2dSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") - OCCT_INSTALL_FILE_OR_DIR ("samples/OCCTOverview/code/Viewer3dSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") + OCCT_INSTALL_FILE_OR_DIR ("samples/qt/OCCTOverview/code/DataExchangeSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") + OCCT_INSTALL_FILE_OR_DIR ("samples/qt/OCCTOverview/code/OcafSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") + OCCT_INSTALL_FILE_OR_DIR ("samples/qt/OCCTOverview/code/GeometrySamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") + OCCT_INSTALL_FILE_OR_DIR ("samples/qt/OCCTOverview/code/TopologySamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") + OCCT_INSTALL_FILE_OR_DIR ("samples/qt/OCCTOverview/code/TriangulationSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") + OCCT_INSTALL_FILE_OR_DIR ("samples/qt/OCCTOverview/code/Viewer2dSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") + OCCT_INSTALL_FILE_OR_DIR ("samples/qt/OCCTOverview/code/Viewer3dSamples.cxx" "${INSTALL_DIR_SAMPLES}/OCCTOverview/code") endif() @@ -1488,6 +1487,18 @@ endif() OCCT_MODULES_AND_TOOLKITS (SAMPLES "SAMPLES_TOOLKITS" OCCT_SAMPLES) +# Load sample configuration files +foreach (OCCT_SAMPLE ${OCCT_SAMPLES}) + foreach (BUILD_SAMPLE_TOOLKIT ${${OCCT_SAMPLE}_SAMPLES_TOOLKITS}) + OCCT_INCLUDE_CMAKE_FILE (samples/${OCCT_SAMPLE}/${BUILD_SAMPLE_TOOLKIT}/PACKAGES) + OCCT_INCLUDE_CMAKE_FILE (samples/${OCCT_SAMPLE}/${BUILD_SAMPLE_TOOLKIT}/EXTERNLIB) + OCCT_INCLUDE_CMAKE_FILE (samples/${OCCT_SAMPLE}/${BUILD_SAMPLE_TOOLKIT}/FILES) + foreach (PACKAGE ${OCCT_${BUILD_SAMPLE_TOOLKIT}_LIST_OF_PACKAGES}) + OCCT_INCLUDE_CMAKE_FILE (samples/${OCCT_SAMPLE}/${PACKAGE}/FILES) + endforeach() + endforeach() +endforeach() + if (BUILD_SAMPLES_QT) if (BUILD_SAMPLES_QT) if (NOT Qt5_FOUND OR "${Qt5Gui_EGL_INCLUDE_DIRS}" STREQUAL "" OR NOT WIN32) diff --git a/adm/cmake/qt_macro.cmake b/adm/cmake/qt_macro.cmake index 36aec9086f..5c1824b0a0 100644 --- a/adm/cmake/qt_macro.cmake +++ b/adm/cmake/qt_macro.cmake @@ -79,8 +79,24 @@ macro (FIND_AND_WRAP_TS_FILE RESOURCE_FILE_NAME TARGET_FOLDER QM_FILES) endmacro() macro (FIND_AND_INSTALL_QT_RESOURCES OCCT_PACKAGE RESOURCE_FILES) - file (STRINGS "${OCCT_ROOT_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" TS_FILES REGEX ".+[.]ts") - file (STRINGS "${OCCT_ROOT_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" QRC_FILES REGEX ".+[.]qrc") + # Package name is now the sample name (e.g., "Tutorial") + set(PACKAGE_NAME ${OCCT_PACKAGE}) + + # Get files from CMAKE variables with proper location + set(ALL_FILES ${OCCT_${PACKAGE_NAME}_FILES}) + set(FILES_LOCATION ${OCCT_${PACKAGE_NAME}_FILES_LOCATION}) + + # Filter for .ts and .qrc files with full paths + set(TS_FILES) + set(QRC_FILES) + foreach(FILE ${ALL_FILES}) + if(FILE MATCHES ".+[.]ts$") + list(APPEND TS_FILES "${FILES_LOCATION}/${FILE}") + endif() + if(FILE MATCHES ".+[.]qrc$") + list(APPEND QRC_FILES "${FILES_LOCATION}/${FILE}") + endif() + endforeach() string (FIND "${OCCT_PACKAGE}" "/" _index) if (_index GREATER -1) @@ -92,19 +108,17 @@ macro (FIND_AND_INSTALL_QT_RESOURCES OCCT_PACKAGE RESOURCE_FILES) #message("QRC files are: ${QRC_FILES} in ${OCCT_PACKAGE}") foreach (QRC_FILE ${QRC_FILES}) - set (QRC_FILE_RELATIVE "${OCCT_ROOT_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${QRC_FILE}") - if (EXISTS ${QRC_FILE_RELATIVE}) - FIND_AND_WRAP_RESOURCE_FILE(${QRC_FILE_RELATIVE} RCC_FILES) + if (EXISTS ${QRC_FILE}) + FIND_AND_WRAP_RESOURCE_FILE(${QRC_FILE} RCC_FILES) list (APPEND ${RESOURCE_FILES} "${RCC_FILES}") endif() endforeach() #message("TS files are: ${TS_FILES} in ${OCCT_PACKAGE}") foreach (TS_FILE ${TS_FILES}) - set (TS_FILE_RELATIVE "${OCCT_ROOT_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${TS_FILE}") - FIND_AND_WRAP_TS_FILE(${TS_FILE_RELATIVE} "${TARGET_FOLDER}/${CURRENT_MODULE}" QM_FILES) - if (EXISTS ${TS_FILE_RELATIVE}) - list (APPEND ${RESOURCE_FILES} "${TS_FILE_RELATIVE}") + FIND_AND_WRAP_TS_FILE(${TS_FILE} "${TARGET_FOLDER}/${CURRENT_MODULE}" QM_FILES) + if (EXISTS ${TS_FILE}) + list (APPEND ${RESOURCE_FILES} "${TS_FILE}") list (APPEND ${RESOURCE_FILES} "${QM_FILES}") endif() endforeach() diff --git a/adm/templates/env.samples.sh.in b/adm/templates/env.samples.sh.in index dddd137f21..08db608092 100644 --- a/adm/templates/env.samples.sh.in +++ b/adm/templates/env.samples.sh.in @@ -21,4 +21,4 @@ export RES_DIR=${aSamplePath}/${STATION}/res export PATH=${QTDIR}/bin:${PATH} -export "CSF_OCCTOverviewSampleCodePath=${aSamplePath}/../../OCCTOverview/code" +export "CSF_OCCTOverviewSampleCodePath=${aSamplePath}/../../qt/OCCTOverview/code" diff --git a/adm/templates/sample.sh b/adm/templates/sample.sh index 5ed26b9418..65647576a7 100644 --- a/adm/templates/sample.sh +++ b/adm/templates/sample.sh @@ -32,7 +32,7 @@ if [ ! -f "$EXE_PATH" ]; then exit 1 fi -export CSF_OCCTOverviewSampleCodePath="${CSF_OCCTSamplesPath}/OCCTOverview/code" +export CSF_OCCTOverviewSampleCodePath="${CSF_OCCTSamplesPath}/qt/OCCTOverview/code" cd ${aCurrentPath} "$EXE_PATH" diff --git a/dox/samples/novice_guide.md b/dox/samples/novice_guide.md index 9818c843a6..fc4c90b8b7 100644 --- a/dox/samples/novice_guide.md +++ b/dox/samples/novice_guide.md @@ -95,7 +95,7 @@ In addition to these two samples, there are much more that might be of use to a Check Readme files in the sample directories to learn more about samples compilation. **Note:** source code for OCCTOverview is stored at 'samples/qt/OCCTOverview/src' folder in your OCCT root, -and the source code files for examples presented in subsections are stored at 'samples/OCCTOverview/code folder'. +and the source code files for examples presented in subsections are stored at 'samples/qt/OCCTOverview/code folder'. Several utility classes that are not presented in the example window may be found in example source code files. The overall classes introduction may be found in the @ref occt_user_guides__foundation_classes "Foundation Classes" section of the documentation. diff --git a/samples/OCCTOverview/code/AdaptorCurve2d_AIS.cxx b/samples/OCCTOverview/code/AdaptorCurve2d_AIS.cxx deleted file mode 100644 index 0fa262ba39..0000000000 --- a/samples/OCCTOverview/code/AdaptorCurve2d_AIS.cxx +++ /dev/null @@ -1,147 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include -#include -#include - -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_PresentationManager)&, - 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; - } - } - } -} diff --git a/samples/OCCTOverview/code/AdaptorCurve2d_AIS.h b/samples/OCCTOverview/code/AdaptorCurve2d_AIS.h deleted file mode 100644 index ad66bb4d13..0000000000 --- a/samples/OCCTOverview/code/AdaptorCurve2d_AIS.h +++ /dev/null @@ -1,77 +0,0 @@ -// 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 -#include -#include -#include - -//! 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_PresentationManager)& 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 diff --git a/samples/OCCTOverview/code/AdaptorCurve_AIS.cxx b/samples/OCCTOverview/code/AdaptorCurve_AIS.cxx deleted file mode 100644 index 18ef438ba3..0000000000 --- a/samples/OCCTOverview/code/AdaptorCurve_AIS.cxx +++ /dev/null @@ -1,49 +0,0 @@ -// 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 -#include -#include -#include - -void AdaptorCurve_AIS::Compute (const Handle(PrsMgr_PresentationManager)&, - 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; - } - } -} diff --git a/samples/OCCTOverview/code/AdaptorCurve_AIS.h b/samples/OCCTOverview/code/AdaptorCurve_AIS.h deleted file mode 100644 index f4f377c5b8..0000000000 --- a/samples/OCCTOverview/code/AdaptorCurve_AIS.h +++ /dev/null @@ -1,52 +0,0 @@ -// 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 -#include - -//! 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_PresentationManager)& 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 diff --git a/samples/OCCTOverview/code/AdaptorPnt2d_AIS.cxx b/samples/OCCTOverview/code/AdaptorPnt2d_AIS.cxx deleted file mode 100644 index 5159a34545..0000000000 --- a/samples/OCCTOverview/code/AdaptorPnt2d_AIS.cxx +++ /dev/null @@ -1,38 +0,0 @@ -// 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 -#include - -void AdaptorPnt2d_AIS::Compute (const Handle(PrsMgr_PresentationManager)& , - 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); -} diff --git a/samples/OCCTOverview/code/AdaptorPnt2d_AIS.h b/samples/OCCTOverview/code/AdaptorPnt2d_AIS.h deleted file mode 100644 index e37a2bd672..0000000000 --- a/samples/OCCTOverview/code/AdaptorPnt2d_AIS.h +++ /dev/null @@ -1,57 +0,0 @@ -// 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 -#include - -//! 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_PresentationManager)& 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 diff --git a/samples/OCCTOverview/code/AdaptorVec_AIS.cxx b/samples/OCCTOverview/code/AdaptorVec_AIS.cxx deleted file mode 100644 index 725e2a53ea..0000000000 --- a/samples/OCCTOverview/code/AdaptorVec_AIS.cxx +++ /dev/null @@ -1,77 +0,0 @@ -// 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 -#include -#include -#include -#include - -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_PresentationManager)& , - 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); - } -} diff --git a/samples/OCCTOverview/code/AdaptorVec_AIS.h b/samples/OCCTOverview/code/AdaptorVec_AIS.h deleted file mode 100644 index e04711c11b..0000000000 --- a/samples/OCCTOverview/code/AdaptorVec_AIS.h +++ /dev/null @@ -1,121 +0,0 @@ -// 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 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_PresentationManager)& 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 diff --git a/samples/OCCTOverview/code/BaseSample.cxx b/samples/OCCTOverview/code/BaseSample.cxx deleted file mode 100644 index b0aa8d2ce5..0000000000 --- a/samples/OCCTOverview/code/BaseSample.cxx +++ /dev/null @@ -1,185 +0,0 @@ -// 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 -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -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(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; -} diff --git a/samples/OCCTOverview/code/BaseSample.h b/samples/OCCTOverview/code/BaseSample.h deleted file mode 100644 index 20c2470af6..0000000000 --- a/samples/OCCTOverview/code/BaseSample.h +++ /dev/null @@ -1,87 +0,0 @@ -// 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 - -#include -#include -#include - -//! 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& Get2dObjects() const { return myObject2d; } - - const NCollection_Vector& 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 myObject2d; - NCollection_Vector 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 diff --git a/samples/OCCTOverview/code/DataExchange.xml b/samples/OCCTOverview/code/DataExchange.xml deleted file mode 100644 index a664a7a3f7..0000000000 --- a/samples/OCCTOverview/code/DataExchange.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/OCCTOverview/code/DataExchangeSamples.cxx b/samples/OCCTOverview/code/DataExchangeSamples.cxx deleted file mode 100644 index 81abc8aad7..0000000000 --- a/samples/OCCTOverview/code/DataExchangeSamples.cxx +++ /dev/null @@ -1,422 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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(NCollection_Vector::Iterator anIter(myObject3d); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); - 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(NCollection_Vector::Iterator anIter(myObject3d); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); - 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(NCollection_Vector::Iterator anIter(myObject3d); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); - 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(NCollection_Vector::Iterator anIter(myObject3d); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); - 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(NCollection_Vector::Iterator anIter(myObject3d); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); - 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(NCollection_Vector::Iterator anIter (myObject3d); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); - 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; -} diff --git a/samples/OCCTOverview/code/DataExchangeSamples.h b/samples/OCCTOverview/code/DataExchangeSamples.h deleted file mode 100644 index 5925065717..0000000000 --- a/samples/OCCTOverview/code/DataExchangeSamples.h +++ /dev/null @@ -1,90 +0,0 @@ -// 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 -#include - -//! 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_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 diff --git a/samples/OCCTOverview/code/FILES b/samples/OCCTOverview/code/FILES deleted file mode 100644 index 342bae1275..0000000000 --- a/samples/OCCTOverview/code/FILES +++ /dev/null @@ -1,48 +0,0 @@ -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.xml -DataExchangeSamples.cxx -DataExchangeSamples.h -Geometry.xml -GeometrySamples.cxx -GeometrySamples.h -MakeBottle.cxx -MakeBottle.h -Ocaf.xml -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.xml -TopologySamples.cxx -TopologySamples.h -Triangulation.xml -TriangulationSamples.cxx -TriangulationSamples.h -Viewer2d.xml -Viewer2dSamples.cxx -Viewer2dSamples.h -Viewer3d.xml -Viewer3dSamples.cxx -Viewer3dSamples.h diff --git a/samples/OCCTOverview/code/Geometry.xml b/samples/OCCTOverview/code/Geometry.xml deleted file mode 100644 index 75133644bb..0000000000 --- a/samples/OCCTOverview/code/Geometry.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/OCCTOverview/code/GeometrySamples.cxx b/samples/OCCTOverview/code/GeometrySamples.cxx deleted file mode 100644 index 278e5e1089..0000000000 --- a/samples/OCCTOverview/code/GeometrySamples.cxx +++ /dev/null @@ -1,2027 +0,0 @@ -// 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 "GeometrySamples.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "AdaptorPnt2d_AIS.h" -#include "AdaptorVec_AIS.h" -#include "AdaptorCurve_AIS.h" -#include "AdaptorCurve2d_AIS.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -void GeometrySamples::ExecuteSample (const TCollection_AsciiString& theSampleName) -{ - Standard_Boolean anIsSamplePresent = Standard_True; - FindSourceCode(theSampleName); - if (theSampleName == "ZeroDimensionObjects3dSample") - ZeroDimensionObjects3dSample(); - else if (theSampleName == "Vectors3dSample") - Vectors3dSample(); - else if (theSampleName == "InfinityLines3dSample") - InfinityLines3dSample(); - else if (theSampleName == "SecondOrderCurves3dSample") - SecondOrderCurves3dSample(); - else if (theSampleName == "PlaneSurfaces3dSample") - PlaneSurfaces3dSample(); - else if (theSampleName == "SecondOrderSurfaces3dSample") - SecondOrderSurfaces3dSample(); - else if (theSampleName == "ZeroDimensionObjects2dSample") - ZeroDimensionObjects2dSample(); - else if (theSampleName == "Vectors2dSample") - Vectors2dSample(); - else if (theSampleName == "InfinityLines2dSample") - InfinityLines2dSample(); - else if (theSampleName == "SecondOrderCurves2dSample") - SecondOrderCurves2dSample(); - else if (theSampleName == "BarycenterPoint3dSample") - BarycenterPoint3dSample(); - else if (theSampleName == "RotatedVector3dSample") - RotatedVector3dSample(); - else if (theSampleName == "MirroredLine3dSample") - MirroredLine3dSample(); - else if (theSampleName == "ScaledEllipse3dSample") - ScaledEllipse3dSample(); - else if (theSampleName == "TransformedCylinder3dSample") - TransformedCylinder3dSample(); - else if (theSampleName == "TranslatedTorus3dSample") - TranslatedTorus3dSample(); - else if (theSampleName == "ConjugateObjects3dSample") - ConjugateObjects3dSample(); - else if (theSampleName == "ProjectionOfPoint3dSample") - ProjectionOfPoint3dSample(); - else if (theSampleName == "MinimalDistance3dSample") - MinimalDistance3dSample(); - else if (theSampleName == "MirroredAxis2dSample") - MirroredAxis2dSample(); - else if (theSampleName == "TransformedEllipse2dSample") - TransformedEllipse2dSample(); - else if (theSampleName == "ConjugateObjects2dSample") - ConjugateObjects2dSample(); - else if (theSampleName == "Intersection3dSample") - Intersection3dSample(); - else if (theSampleName == "TranslatedPoint2dSample") - TranslatedPoint2dSample(); - else if (theSampleName == "RotatedDirection2dSample") - RotatedDirection2dSample(); - else if (theSampleName == "Tangent2dSample") - Tangent2dSample(); - else if (theSampleName == "ProjectionOfPoint2dSample") - ProjectionOfPoint2dSample(); - else if (theSampleName == "MinimalDistance2dSample") - MinimalDistance2dSample(); - else if (theSampleName == "Intersection2dSample") - Intersection2dSample(); - else if (theSampleName == "PointInfo3dSample") - PointInfo3dSample(); - else if (theSampleName == "EllipseInfo3dSample") - EllipseInfo3dSample(); - else if (theSampleName == "PointInfo2dSample") - PointInfo2dSample(); - else if (theSampleName == "CircleInfo2dSample") - CircleInfo2dSample(); - else if (theSampleName == "SecondOrderCurves3dSample") - SecondOrderCurves3dSample(); - else if (theSampleName == "FreeStyleCurves3dSample") - FreeStyleCurves3dSample(); - else if (theSampleName == "AnalyticalSurfaces3dSample") - AnalyticalSurfaces3dSample(); - else if (theSampleName == "FreeStyleSurfaces3dSample") - FreeStyleSurfaces3dSample(); - else if (theSampleName == "SecondOrderCurves2dSample") - SecondOrderCurves2dSample(); - else if (theSampleName == "FreeStyleCurves2dSample") - FreeStyleCurves2dSample(); - else if (theSampleName == "TrimmedCurve3dSample") - TrimmedCurve3dSample(); - else if (theSampleName == "OffsetCurve3dSample") - OffsetCurve3dSample(); - else if (theSampleName == "BSplineFromCircle3dSample") - BSplineFromCircle3dSample(); - else if (theSampleName == "TrimmedSurface3dSample") - TrimmedSurface3dSample(); - else if (theSampleName == "OffsetSurface3dSample") - OffsetSurface3dSample(); - else if (theSampleName == "ExtrusionSurface3dSample") - ExtrusionSurface3dSample(); - else if (theSampleName == "RevolutionSurface3dSample") - RevolutionSurface3dSample(); - else if (theSampleName == "TrimmedCurve2dSample") - TrimmedCurve2dSample(); - else if (theSampleName == "OffsetCurve2dSample") - OffsetCurve2dSample(); - else if (theSampleName == "BoundingBoxOfSurface3dSample") - BoundingBoxOfSurface3dSample(); - else if (theSampleName == "BoundingBoxOfCurves3dSample") - BoundingBoxOfCurves3dSample(); - else if (theSampleName == "BoundingBoxOfCurves2dSample") - BoundingBoxOfCurves2dSample(); - else if (theSampleName == "DumpCircleInfoSample") - DumpCircleInfoSample(); - else if (theSampleName == "DumpBSplineCurveInfoSample") - DumpBSplineCurveInfoSample(); - else - { - myResult << "No function found: " << theSampleName; - myCode += TCollection_AsciiString("No function found: ") + theSampleName; - anIsSamplePresent = Standard_False; - } - myIsProcessed = anIsSamplePresent; -} - -void GeometrySamples::DisplayPnt (const gp_Pnt2d& thePnt2d, const TCollection_AsciiString& theText, - Aspect_TypeOfMarker theMarker, Standard_Real theDistance) -{ - gp_Pnt aPnt(thePnt2d.X(), thePnt2d.Y(), 0.0); - Handle(Geom_CartesianPoint) aGeomPoint = new Geom_CartesianPoint(aPnt); - Handle(AIS_Point) anAisPoint = new AIS_Point(aGeomPoint); - anAisPoint->SetMarker(theMarker); - myObject2d.Append(anAisPoint); - Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel(); - aPntLabel->SetText(theText); - aPntLabel->SetPosition(gp_Pnt(aPnt.X(), aPnt.Y() + theDistance, aPnt.Z())); - myObject2d.Append(aPntLabel); -} -void GeometrySamples::DisplayPnt (const gp_Pnt& thePnt, const TCollection_AsciiString& theText, - Aspect_TypeOfMarker theMarker, Standard_Real theDistance) -{ - Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(thePnt); - Handle(AIS_Point) anAisPoint = new AIS_Point(aPoint); - anAisPoint->SetMarker(theMarker); - myObject3d.Append(anAisPoint); - Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel(); - aPntLabel->SetText(theText); - aPntLabel->SetPosition(gp_Pnt(thePnt.X(), thePnt.Y(), thePnt.Z() + theDistance)); - myObject3d.Append(aPntLabel); -} - -void GeometrySamples::ZeroDimensionObjects3dSample() -{ - // gp_Pnt describes a point in 3D space. A Geom_CartesianPoint is defined by - // a gp_Pnt point, with its three Cartesian coordinates X, Y and Z. - gp_Pnt aCoordPnt(10.0, 20.0, 30.0); - Handle(Geom_CartesianPoint) aCoordGeomPoint = new Geom_CartesianPoint(aCoordPnt); - Handle(AIS_Point) aCoordAisPoint = new AIS_Point(aCoordGeomPoint); - myObject3d.Append(aCoordAisPoint); - - Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel(); - aPntLabel->SetText(" gp_Pnt"); - aPntLabel->SetPosition(gp_Pnt(aCoordPnt.X(), aCoordPnt.Y(), aCoordPnt.Z() + 5.0)); - myObject3d.Append(aPntLabel); - myResult << "gp_Pnt was created" << std::endl; - - // gp_XYZ class describes a Cartesian coordinate entity in 3D space (X,Y,Z). - // This entity is used for algebraic calculation. - // This entity can be transformed with a "Trsf" or a "GTrsf" from package "gp". - // It is used in vectorial computations or for holding this type of information - // in data structures. - gp_XYZ aXyz1(10.0, 20.0, 30.0); - gp_XYZ aXyz2(20.0, 10.0, 30.0); - gp_XYZ aXyzSum = aXyz1 + aXyz2; - gp_Pnt aSumPnt(aXyzSum); - Handle(Geom_CartesianPoint) aXyzGeomPoint = new Geom_CartesianPoint(aSumPnt); - Handle(AIS_Point) aSumAisPoint = new AIS_Point(aXyzGeomPoint); - myObject3d.Append(aSumAisPoint); - - Handle(AIS_TextLabel) aXyzLabel = new AIS_TextLabel(); - aXyzLabel->SetText(" gp_XYZ"); - aXyzLabel->SetPosition(gp_Pnt(aXyzSum.X(), aXyzSum.Y(), aXyzSum.Z() + 5.0)); - myObject3d.Append(aXyzLabel); - myResult << "gp_XYZ was created" << std::endl; -} - -void GeometrySamples::Vectors3dSample() -{ - gp_Pnt aPnt1(0.0, 0.0, 0.0); - gp_Pnt aPnt2(5.0, 0.0, 0.0); - - // gp_Vec defines a non-persistent vector in 3D space. - gp_Vec aVec(aPnt1, aPnt2); - Handle(AdaptorVec_AIS) aVecAIS = new AdaptorVec_AIS(aPnt1, aVec, 0.5); - aVecAIS->SetText(" gp_Vec"); - myObject3d.Append(aVecAIS); - myResult << "gp_Vec magnitude: " << aVec.Magnitude() << std::endl; - - // Describes a unit vector in 3D space. - // This unit vector is also called "Direction". - // See Also gce_MakeDir which provides functions for more complex unit vector - // constructions Geom_Direction which provides additional functions - // for constructing unit vectors and works, in particular, - // with the parametric equations of unit vectors. - gp_Dir aDir(aVec); - Handle(AdaptorVec_AIS) aDirAIS = new AdaptorVec_AIS(gp_Pnt(0.0, 0.0, 10.0), aDir, 1.0, 0.5); - aDirAIS->SetText(" gp_Dir"); - myObject3d.Append(aDirAIS); - myResult << "gp_Dir coordinates: X: " << aDir.X() << ", Y: " << aDir.Y() << ", Z: " << aDir.Z() << std::endl; -} - -void GeometrySamples::InfinityLines3dSample() -{ - gp_Pnt aBasePoint(0.0, 0.0, 0.0); - gp_Dir aX_Direction(1.0, 0.0, 0.0); - gp_Dir anY_Direction(0.0, 1.0, 0.0); - gp_Dir aZ_Direction(0.0, 0.0, 1.0); - - // Describes an axis in 3D space. - gp_Ax1 anAxis1(aBasePoint, aZ_Direction); - Handle(AdaptorVec_AIS) anAx1Ais = new AdaptorVec_AIS(anAxis1.Location(), anAxis1.Direction(), 1.0, 0.3); - anAx1Ais->SetText(" gp_Ax1"); - myObject3d.Append(anAx1Ais); - myResult << "gp_Ax1 was created" << std::endl << std::endl; - - // Describes a right - handed coordinate system in 3D space. - aBasePoint.SetCoord(0.0, 0.0, 3.0); - gp_Ax2 anAxis2(aBasePoint, aZ_Direction); - Handle(AdaptorVec_AIS) aAx2AisZ = new AdaptorVec_AIS(anAxis2.Location(), anAxis2.Direction(), 1.0, 0.3); - aAx2AisZ->SetText(" gp_Ax2 Z"); - myObject3d.Append(aAx2AisZ); - Handle(AdaptorVec_AIS) aAx2AisX = new AdaptorVec_AIS(anAxis2.Location(), anAxis2.XDirection(), 1.0, 0.3); - aAx2AisX->SetText(" gp_Ax2 X"); - myObject3d.Append(aAx2AisX); - Handle(AdaptorVec_AIS) aAx2AisY = new AdaptorVec_AIS(anAxis2.Location(), anAxis2.YDirection(), 1.0, 0.3); - aAx2AisY->SetText(" gp_Ax2 Y"); - myObject3d.Append(aAx2AisY); - myResult << "gp_Ax2 was created" << std::endl; - - // Describes a coordinate system in 3D space.Unlike a gp_Ax2 coordinate system, - // a gp_Ax3 can be right - handed("direct sense") or left - handed("indirect sense"). - gp_Ax3 anAxis3(gp_XYZ(0.0, 0.0, 6.0), aZ_Direction, aX_Direction); - anAxis3.YReverse(); - Handle(AdaptorVec_AIS) anAx3AisZ = new AdaptorVec_AIS(anAxis3.Location(), anAxis3.Direction(), 1.0, 0.3); - anAx3AisZ->SetText(" gp_Ax3 Z"); - myObject3d.Append(anAx3AisZ); - Handle(AdaptorVec_AIS) anAx3AisX = new AdaptorVec_AIS(anAxis3.Location(), anAxis3.XDirection(), 1.0, 0.3); - anAx3AisX->SetText(" gp_Ax3 X"); - myObject3d.Append(anAx3AisX); - Handle(AdaptorVec_AIS) anAx3AisY = new AdaptorVec_AIS(anAxis3.Location(), anAxis3.YDirection(), 1.0, 0.3); - anAx3AisY->SetText(" gp_Ax3 Y"); - myObject3d.Append(anAx3AisY); - - myResult << "gp_Ax3 was created" << std::endl; - const gp_Dir& anAxis3_xDir = anAxis3.XDirection(); - const gp_Dir& anAxis3_yDir = anAxis3.YDirection(); - myResult << "gp_Ax3 X direction: " << anAxis3_xDir.X() << " " << anAxis3_xDir.Y() << " " << anAxis3_xDir.Z() << std::endl; - myResult << "gp_Ax3 Y direction: " << anAxis3_yDir.X() << " " << anAxis3_yDir.Y() << " " << anAxis3_yDir.Z() << std::endl; - TCollection_AsciiString aDirectionDescription; - if (anAxis3.Direct()) - { - aDirectionDescription = "anAxis3 is a right-handed axis system"; - } - else - { - aDirectionDescription = "anAxis3 is a left-handed axis system"; - } - myResult << aDirectionDescription << std::endl << std::endl; - - // Describes a line in 3D space. A line is positioned in space with an axis - // (a gp_Ax1 object) which gives it an origin and a unit vector. - gp_Lin aLine(gp_Pnt(5.0, 0.0, 0.0), gp_Dir(0.0, 1.0, 0.0)); - Handle(AdaptorVec_AIS) anLineAis = new AdaptorVec_AIS(aLine.Location(), aLine.Direction(), 8.0); - anLineAis->SetText(" gp_Lin"); - myObject3d.Append(anLineAis); - myResult << "gp_Lin was created" << std::endl << std::endl; -} - -void GeometrySamples::SecondOrderCurves3dSample() -{ - gp_Ax2 anAxis2(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)); - gp_Circ aCirc(anAxis2, 10.0); - Handle(Geom_Circle) aGeomCircle = new Geom_Circle(aCirc); - Handle(AIS_Circle) anAisCircle = new AIS_Circle(aGeomCircle); - myObject3d.Append(anAisCircle); - - // Describes an ellipse in 3D space. An ellipse is defined by its major and minor - // radii and positioned in space with a coordinate system (a gp_Ax2 object) - gp_Elips anElips(anAxis2.Translated(gp_Vec(0.0, 0.0, 10.0)), 20.0, 10.0); - Handle(Geom_Ellipse) aGeomEllipse = new Geom_Ellipse(anElips); - Handle(AdaptorCurve_AIS) anAisEllipce = new AdaptorCurve_AIS(aGeomEllipse); - myObject3d.Append(anAisEllipce); - - // Describes a parabola in 3D space. A parabola is defined by its focal length - // (that is, the distance between its focus and apex) and positioned in space with - // a coordinate system (a gp_Ax2 object) - gp_Parab aParab(anAxis2.Translated(gp_Vec(0.0, 0.0, 20.0)), 2.0); - Handle(Geom_Parabola) aGeomParabola = new Geom_Parabola(aParab); - Handle(Geom_TrimmedCurve) aTrimmedParabola = new Geom_TrimmedCurve(aGeomParabola, 20.0, -20.0); - Handle(AdaptorCurve_AIS) anAisParabola = new AdaptorCurve_AIS(aTrimmedParabola); - myObject3d.Append(anAisParabola); - - // Describes a branch of a hyperbola in 3D space. A hyperbola is defined by its major - // and minor radii and positioned in space with a coordinate system (a gp_Ax2 object) - gp_Hypr aHypr(anAxis2.Translated(gp_Vec(0.0, 0.0, 30.0)), 20.0, 10.0); - Handle(Geom_Hyperbola) aGeomHyperbola = new Geom_Hyperbola(aHypr); - Handle(Geom_TrimmedCurve) aTrimmedHyperbola = new Geom_TrimmedCurve(aGeomHyperbola, 2.0, -2.0); - Handle(AdaptorCurve_AIS) anAisHyperbola = new AdaptorCurve_AIS(aTrimmedHyperbola); - myObject3d.Append(anAisHyperbola); -} - -void GeometrySamples::PlaneSurfaces3dSample() -{ - // Describes a plane.A plane is positioned in space with a coordinate system(a gp_Ax3 object), - // such that the plane is defined by the origin, "X Direction" and "Y Direction" of this - // coordinate system, which is the "local coordinate system" of the plane.The "main Direction" - // of the coordinate system is a vector normal to the plane. - gp_Pln aPln(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)); - Handle(Geom_Plane) aPlane = new Geom_Plane(aPln); - Handle(AIS_Plane) anAisPlane = new AIS_Plane(aPlane, aPln.Location(), - gp_Pnt(10.0, 10.0, 0.0), - gp_Pnt(-10.0, -10.0, 0.0), - Standard_False); - myObject3d.Append(anAisPlane); - - // Describes an infinite cylindrical surface.A cylinder is defined by its radius and positioned - // in space with a coordinate system(a gp_Ax3 object), the "main Axis" of which is the axis of - // the cylinder.This coordinate system is the "local coordinate system" of the cylinder. - gp_Cylinder aCylinder(gp_Ax3(gp_Pnt(0.0, 0.0, 10.0), gp_Dir(0.0, 0.0, 1.0)), 10.0); - Handle(Geom_CylindricalSurface) aCylindricalSurface = new Geom_CylindricalSurface(aCylinder); - Handle(AIS_Shape) anAisCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace( - aCylindricalSurface, 0.0, 2.0*M_PI, 0.0, 10.0, Precision::Confusion()).Shape()); - myObject3d.Append(anAisCylinder); - - // Defines an infinite conical surface. A cone is defined by its half-angle (can be negative) at - // the apex and positioned in space with a coordinate system (a gp_Ax3 object) and a "reference radius" - gp_Cone aCone(gp_Ax3(gp_Pnt(0.0, 0.0, 30.0), gp_Dir(0.0, 0.0, 1.0)), 0.25*M_PI, 0.0); - Handle(Geom_ConicalSurface) aConicalSurface = new Geom_ConicalSurface(aCone); - Handle(AIS_Shape) anAisCone = new AIS_Shape(BRepBuilderAPI_MakeFace( - aConicalSurface, 0.0, 2.0*M_PI, 0.0, 20.0, Precision::Confusion()).Shape()); - myObject3d.Append(anAisCone); -} - -void GeometrySamples::SecondOrderSurfaces3dSample() -{ - gp_Sphere aSphere(gp_Ax3(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)), 10.0); - Handle(Geom_SphericalSurface) aSphericalSurface = new Geom_SphericalSurface(aSphere); - Handle(AIS_Shape) anAisSphere = new AIS_Shape(BRepBuilderAPI_MakeFace( - aSphericalSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); - myObject3d.Append(anAisSphere); - - gp_Torus aTorus(gp_Ax3(gp_Pnt(0.0, 0.0, 20.0), gp_Dir(0.0, 0.0, 1.0)), 40.0, 10.0); - Handle(Geom_ToroidalSurface) aToroidalSurface = new Geom_ToroidalSurface(aTorus); - Handle(AIS_Shape) anAisTorus = new AIS_Shape(BRepBuilderAPI_MakeFace( - aToroidalSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); - myObject3d.Append(anAisTorus); -} - -void GeometrySamples::ZeroDimensionObjects2dSample() -{ - // Defines a non-persistent 2D Cartesian point. - gp_Pnt2d aCoordPnt(10.0, 20.0); - Handle(Geom2d_CartesianPoint) aCoordGeomPoint = new Geom2d_CartesianPoint(aCoordPnt); - Handle(AdaptorPnt2d_AIS) aCoordAisPoint = new AdaptorPnt2d_AIS(aCoordGeomPoint); - myObject2d.Append(aCoordAisPoint); - - Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel(); - aPntLabel->SetText("gp_Pnt2d"); - aPntLabel->SetPosition(gp_Pnt(aCoordPnt.X(), aCoordPnt.Y() + 0.5, 0.0)); - myObject2d.Append(aPntLabel); - myResult << "gp_Pnt was created" << std::endl; - - // This class describes a Cartesian coordinate entity in 2D space{ X,Y }. - // This class is non persistent.This entity used for algebraic calculation. - // An XY can be transformed with a Trsf2d or a GTrsf2d from package gp. - // It is used in vectorial computations or for holding this type of information in data structures. - gp_XY aXy(20.0, 10.0); - Handle(Geom2d_CartesianPoint) aXyGeomPoint = new Geom2d_CartesianPoint(aXy); - Handle(AdaptorPnt2d_AIS) aXyAisPoint = new AdaptorPnt2d_AIS(aXyGeomPoint); - myObject2d.Append(aXyAisPoint); - - Handle(AIS_TextLabel) aXyLabel = new AIS_TextLabel(); - aXyLabel->SetText(" gp_XY"); - aXyLabel->SetPosition(gp_Pnt(aXy.X(), aXy.Y() + 0.5, 0.0)); - myObject2d.Append(aXyLabel); - myResult << "gp_XY was created" << std::endl; -} - -void GeometrySamples::Vectors2dSample() -{ - // Describes a unit vector in the plane (2D space). - // This unit vector is also called "Direction". - gp_Dir2d aDir(3.0, 4.0); - Handle(AdaptorVec_AIS) anAisDir = new AdaptorVec_AIS(gp_Pnt2d(0.0, 0.0), aDir, 1.0, 0.3); - anAisDir->SetText(" gp_Dir2d"); - myObject2d.Append(anAisDir); - myResult << "gp_Dir2d coordinates: X: " << aDir.X() << ", Y: " << aDir.Y() << std::endl; - - // Defines a non-persistent vector in 2D space. - gp_Vec2d aVec(aDir); - aVec = aVec * 2; - Handle(AdaptorVec_AIS) anAisVec = new AdaptorVec_AIS(gp_Pnt2d(0.0, 5.0), aVec, 0.3); - anAisVec->SetText(" gp_Vec2d"); - myObject2d.Append(anAisVec); - myResult << "gp_Vec2d magnitude: " << aVec.Magnitude() << std::endl; -} - -void GeometrySamples::InfinityLines2dSample() -{ - // Describes an axis in the plane (2D space) - gp_Ax2d anAx2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 0.0)); - Handle(AdaptorVec_AIS) anAisAx2d = new AdaptorVec_AIS(anAx2d.Location(), anAx2d.Direction(), 1.0, 0.3); - anAisAx2d->SetText(" gp_Ax2d"); - myObject2d.Append(anAisAx2d); - - // Describes a coordinate system in a plane (2D space). - gp_Ax22d anAx22d(gp_Pnt2d(0.0, 2.0), gp_Dir2d(1.0, 1.0), Standard_False); - Handle(AdaptorVec_AIS) anAisAx2d_X = new AdaptorVec_AIS(anAx22d.Location(), anAx22d.XDirection(), 1.0, 0.3); - anAisAx2d_X->SetText(" gp_Ax2d X"); - myObject2d.Append(anAisAx2d_X); - Handle(AdaptorVec_AIS) anAisAx2d_Y = new AdaptorVec_AIS(anAx22d.Location(), anAx22d.YDirection(), 1.0, 0.3); - anAisAx2d_Y->SetText(" gp_Ax2d Y"); - myObject2d.Append(anAisAx2d_Y); - - // Describes a line in 2D space. A line is positioned in the plane with an axis (a gp_Ax2d object) which gives - // the line its origin and unit vector. A line and an axis are similar objects, thus, - // we can convert one into the other. A line provides direct access to the majority of the edit and query - // functions available on its positioning axis. - gp_Lin2d aLin2d(gp_Pnt2d(2.0, 4.0), gp_Dir2d(0.0, -1.0)); - Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aLin2d.Location(), aLin2d.Direction(), 1.0, 0.3); - anAisLin->SetText(" gp_Lin2d"); - myObject2d.Append(anAisLin); -} - -void GeometrySamples::SecondOrderCurves2dSample() -{ - // Describes a circle in the plane (2D space). A circle is defined by its radius - // and positioned in the plane with a coordinate system (a gp_Ax22d object) - gp_Circ2d aCirc2d; - aCirc2d.SetLocation(gp_Pnt2d(0.0, 0.0)); - aCirc2d.SetRadius(10.0); - Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(aCirc2d); - Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle, Aspect_TOL_SOLID); - myObject2d.Append(anAisCirc); - - // Describes an ellipse in the plane (2D space). An ellipse is defined by its major - // and minor radii and positioned in the plane with a coordinate system (a gp_Ax22d object) - gp_Elips2d anElips(gp_Ax2d(gp_Pnt2d(0.0, 30.0), gp_Dir2d(1.0, 0.0)), 20.0, 10.0); - Handle(Geom2d_Ellipse) aGeomEllipse = new Geom2d_Ellipse(anElips); - Handle(AdaptorCurve2d_AIS) anAisEllipse = new AdaptorCurve2d_AIS(aGeomEllipse, Aspect_TOL_DASH); - myObject2d.Append(anAisEllipse); - - // Describes a parabola in the plane (2D space). A parabola is defined by its focal length - // (that is, the distance between its focus and apex) and positioned in the plane with - // a coordinate system (a gp_Ax22d object) - gp_Parab2d aParab2d(gp_Ax2d(gp_Pnt2d(20.0, 0.0), gp_Dir2d(1.0, 0.0)), 10.0); - Handle(Geom2d_Parabola) aGeomParabola = new Geom2d_Parabola(aParab2d); - Handle(Geom2d_TrimmedCurve) aTrimmedParabola = new Geom2d_TrimmedCurve(aGeomParabola, 40.0, -40.0); - Handle(AdaptorCurve2d_AIS) anAisParabola = new AdaptorCurve2d_AIS(aTrimmedParabola, Aspect_TOL_DOT); - myObject2d.Append(anAisParabola); - - // Describes a branch of a hyperbola in the plane (2D space). A hyperbola is defined by its major and - // minor radii, and positioned in the plane with a coordinate system (a gp_Ax22d object) - gp_Hypr2d aHypr2d(gp_Ax2d(gp_Pnt2d(20.0, 0.0), gp_Dir2d(1.0, 0.0)), 20.0, 10.0); - Handle(Geom2d_Hyperbola) aGeomHyperbola = new Geom2d_Hyperbola(aHypr2d); - Handle(Geom2d_TrimmedCurve) aTrimmedHyperbola = new Geom2d_TrimmedCurve(aGeomHyperbola, 2.0, -2.0); - Handle(AdaptorCurve2d_AIS) anAisHyperbola = new AdaptorCurve2d_AIS(aTrimmedHyperbola, Aspect_TOL_DOTDASH); - myObject2d.Append(anAisHyperbola); -} - -void GeometrySamples::BarycenterPoint3dSample() -{ - // Barycenter of 2 points - gp_Pnt aPnt1(11, 2, 3); - gp_Pnt aPnt2(13, 4, 5); - gp_Pnt aBarycenterPnt2 = aPnt1; - Standard_Real anAlpha = 3; - Standard_Real anBeta = 7; - // Assigns the result of the following expression to this point: - // (Alpha*this + Beta*P) / (Alpha + Beta) - aBarycenterPnt2.BaryCenter(anAlpha, aPnt2, anBeta); - DisplayPnt(aPnt1, "Pnt1", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt2, "Pnt2", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aBarycenterPnt2, "Barycenter Pnt", Aspect_TOM_O_PLUS, 0.5); - - // BaryCenter of an array of point - gp_Pnt aP1(0, 0, 5); - gp_Pnt aP2(1, 2, 3); - gp_Pnt aP3(2, 3, -2); - gp_Pnt aP4(4, 3, 5); - gp_Pnt aP5(5, 5, 4); - TColgp_Array1OfPnt aPntArray(1, 5); - aPntArray.SetValue(1, aP1); - aPntArray.SetValue(2, aP2); - aPntArray.SetValue(3, aP3); - aPntArray.SetValue(4, aP4); - aPntArray.SetValue(5, aP5); - - Standard_Real Tolerance = 8; - GProp_PEquation aPEquation(aPntArray, Tolerance); - - gp_Pnt aBarycenterPnt5; // P declaration - bool isPoint = false; - if (aPEquation.IsPoint()) - { - isPoint = true; - aBarycenterPnt5 = aPEquation.Point(); - myResult << "GProp_PEquation is a point" << std::endl; - } - else - { - isPoint = false; - myResult << "GProp_PEquation is not a point" << std::endl; - } - - if (aPEquation.IsLinear()) - { - /*... */ - } - if (aPEquation.IsPlanar()) - { - /*... */ - } - if (aPEquation.IsSpace()) - { - /*... */ - } - - const TCollection_AsciiString aPointName("P"); - for (Standard_Integer i = aPntArray.Lower(); i <= aPntArray.Upper(); i++) - { - TCollection_AsciiString aString(i); - aString = aPointName + aString; - DisplayPnt(aPntArray(i), aString, Aspect_TOM_STAR, 0.5); - } - - DisplayPnt(aBarycenterPnt5, "Barycenter of 5 points", Aspect_TOM_O_STAR, 0.5); - myResult << " IsPoint = "; - if (isPoint) - { - myResult << "True --> " << " P ( " << aBarycenterPnt5.X() << aBarycenterPnt5.Y() << aBarycenterPnt5.Z() << " );" << std::endl; - } - else - { - myResult << "False"; - } - myResult << std::endl << " IsLinear = " << (aPEquation.IsLinear() ? "True" : "False"); - myResult << std::endl << " IsPlanar = " << (aPEquation.IsPlanar() ? "True" : "False"); - myResult << std::endl << " IsSpace = " << (aPEquation.IsSpace() ? "True" : "False"); -} - -void GeometrySamples::RotatedVector3dSample() -{ - gp_Vec aBaseVec(0.0, 0.0, 10.0); - gp_Pnt aZeroPnt(0.0, 0.0, 0.0); - gp_Vec aRotatedVec = aBaseVec.Rotated(gp_Ax1(aZeroPnt, gp_Dir(1.0, 0.0, 0.0)), M_PI_4); - - Handle(AdaptorVec_AIS) aBaseVecAIS = new AdaptorVec_AIS(aZeroPnt, aBaseVec); - aBaseVecAIS->SetText(" Base vector"); - myObject3d.Append(aBaseVecAIS); - Handle(AdaptorVec_AIS) aRotatedVecAIS = new AdaptorVec_AIS(aZeroPnt, aRotatedVec); - aRotatedVecAIS->SetText(" Rotated vector"); - myObject3d.Append(aRotatedVecAIS); - Standard_Real anAdgle = aBaseVec.Angle(aRotatedVec)*180.0 / M_PI; - myResult << "An angle between vectors = " << anAdgle << std::endl; -} - -void GeometrySamples::MirroredLine3dSample() -{ - gp_Lin aBaseLin(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(1.0, 1.0, 1.0)); - gp_Ax2 aXyzAxis; - gp_Lin aMirroredLin = aBaseLin.Mirrored(aXyzAxis); - - Handle(AdaptorVec_AIS) aBaseLineAis = new AdaptorVec_AIS(aBaseLin.Location(), aBaseLin.Direction(), 8.0); - aBaseLineAis->SetText(" Base Line"); - myObject3d.Append(aBaseLineAis); - Handle(AdaptorVec_AIS) aMirroredLineAis = new AdaptorVec_AIS(aMirroredLin.Location(), aMirroredLin.Direction(), 8.0); - aMirroredLineAis->SetText(" Mirrored Line"); - myObject3d.Append(aMirroredLineAis); - Handle(AIS_Plane) anAisPlane = new AIS_Plane (new Geom_Plane(gp_Ax3(aXyzAxis)), aXyzAxis.Location(), - gp_Pnt(10.0, 10.0, 0.0), gp_Pnt(-10.0, -10.0, 0.0), Standard_False); - myObject3d.Append(anAisPlane); - Standard_Real anAdgle = aBaseLin.Angle(aMirroredLin)*180.0 / M_PI; - myResult << "An angle between lines = " << anAdgle << std::endl; -} - -void GeometrySamples::ScaledEllipse3dSample() -{ - gp_Ax2 anAxis2(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)); - gp_Elips anBaseElips(anAxis2, 20.0, 10.0); - gp_Elips anScaledElips = anBaseElips.Scaled(gp_Pnt(), 2.5); - - Handle(Geom_Ellipse) aBaseGeomEllipse = new Geom_Ellipse(anBaseElips); - Handle(AdaptorCurve_AIS) anAisBaseEllipce = new AdaptorCurve_AIS(aBaseGeomEllipse); - myObject3d.Append(anAisBaseEllipce); - - Handle(Geom_Ellipse) aScaledGeomEllipse = new Geom_Ellipse(anScaledElips); - Handle(AdaptorCurve_AIS) anAisScaledEllipce = new AdaptorCurve_AIS(aScaledGeomEllipse); - myObject3d.Append(anAisScaledEllipce); -} - -void GeometrySamples::TransformedCylinder3dSample() -{ - gp_Cylinder aBaseCylinder(gp_Ax3(), 10.0); - gp_Trsf aRotTrsf; - aRotTrsf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(1.0, 0.0, 0.0)), M_PI_2); - gp_Trsf aScaleTrsf; - aScaleTrsf.SetScale(gp_Pnt(), 1.5); - gp_Trsf aTranslTrsf; - aTranslTrsf.SetTranslation(gp_Vec(30.0, 0.0, 0.0)); - gp_Trsf aComplexTrsf = aRotTrsf * aScaleTrsf * aTranslTrsf; - gp_Cylinder aTransfCylinder = aBaseCylinder.Transformed(aComplexTrsf); - - Handle(Geom_CylindricalSurface) aBaseCylinderSurface = new Geom_CylindricalSurface(aBaseCylinder); - Handle(AIS_Shape) anAisBaseCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace( - aBaseCylinderSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); - myObject3d.Append(anAisBaseCylinder); - Handle(Geom_CylindricalSurface) aTransfCylinderSurface = new Geom_CylindricalSurface(aTransfCylinder); - Handle(AIS_Shape) anAisTransfCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace( - aTransfCylinderSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); - myObject3d.Append(anAisTransfCylinder); -} - -void GeometrySamples::TranslatedTorus3dSample() -{ - gp_Torus aBaseTorus(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 40.0, 10.0); - gp_Torus aTranslatedTorus = aBaseTorus.Translated(gp_Vec(70.0, 70.0, 70.0)); - - Handle(Geom_ToroidalSurface) aBaseSurface = new Geom_ToroidalSurface(aBaseTorus); - Handle(AIS_Shape) anAisBaseShape = new AIS_Shape(BRepBuilderAPI_MakeFace( - aBaseSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); - myObject3d.Append(anAisBaseShape); - Handle(Geom_ToroidalSurface) aTranslSurface = new Geom_ToroidalSurface(aTranslatedTorus); - Handle(AIS_Shape) anAisTranslShape = new AIS_Shape(BRepBuilderAPI_MakeFace( - aTranslSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); - myObject3d.Append(anAisTranslShape); -} - -void GeometrySamples::ConjugateObjects3dSample() -{ - gp_Hypr aHypr(gp_Ax2(), 20.0, 10.0); - gp_Ax1 anAsymptote1 = aHypr.Asymptote1(); - gp_Ax1 anAsymptote2 = aHypr.Asymptote2(); - gp_Ax1 aDirectrix1 = aHypr.Directrix1(); - gp_Ax1 aDirectrix2 = aHypr.Directrix2(); - gp_Pnt aFocus1 = aHypr.Focus1(); - gp_Pnt aFocus2 = aHypr.Focus2(); - gp_Pnt aLocation = aHypr.Location(); - - Handle(AdaptorVec_AIS) anAsy1AIS = new AdaptorVec_AIS(anAsymptote1.Location(), gp_Vec(anAsymptote1.Direction())*10.0); - anAsy1AIS->SetText(" Asymptote 1"); - myObject3d.Append(anAsy1AIS); - Handle(AdaptorVec_AIS) anAsy2AIS = new AdaptorVec_AIS(anAsymptote2.Location(), gp_Vec(anAsymptote2.Direction())*10.0); - anAsy2AIS->SetText(" Asymptote 2"); - myObject3d.Append(anAsy2AIS); - Handle(AdaptorVec_AIS) anDir1AIS = new AdaptorVec_AIS(aDirectrix1.Location(), gp_Vec(aDirectrix1.Direction())*10.0); - anDir1AIS->SetText(" Directrix 1"); - myObject3d.Append(anDir1AIS); - Handle(AdaptorVec_AIS) anDir2AIS = new AdaptorVec_AIS(aDirectrix2.Location(), gp_Vec(aDirectrix2.Direction())*10.0); - anDir2AIS->SetText(" Directrix 2"); - myObject3d.Append(anDir2AIS); - - DisplayPnt(aFocus1, "Focus 1", Aspect_TOM_PLUS, 2.0); - DisplayPnt(aFocus2, "Focus 2", Aspect_TOM_PLUS, 2.0); - DisplayPnt(aLocation, "Location", Aspect_TOM_O_STAR, 2.0); - - Handle(Geom_Hyperbola) aGeomHyperbola = new Geom_Hyperbola(aHypr); - Handle(Geom_TrimmedCurve) aTrimmedHyperbola = new Geom_TrimmedCurve(aGeomHyperbola, 2.0, -2.0); - Handle(AdaptorCurve_AIS) anAisHyperbola = new AdaptorCurve_AIS(aTrimmedHyperbola); - myObject3d.Append(anAisHyperbola); -} - -void GeometrySamples::ProjectionOfPoint3dSample() -{ - gp_Sphere aSphere(gp_Ax3(), 10.0); - gp_Pnt aBasePnt(20.0, 20.0, 20.0); - // A projection point in surface coordinate - gp_Pnt2d aPrjPnt2d = ProjLib::Project(aSphere, aBasePnt); - gp_Pnt aPrjPnt = ElSLib::Value(aPrjPnt2d.X(), aPrjPnt2d.Y(), aSphere); - - DisplayPnt(aBasePnt, "Base point", Aspect_TOM_PLUS, 2.0); - DisplayPnt(aPrjPnt, "Projection point", Aspect_TOM_O_STAR, 2.0); - Handle(Geom_SphericalSurface) aSphericalSurface = new Geom_SphericalSurface(aSphere); - Handle(AIS_Shape) anAisSphere = new AIS_Shape(BRepBuilderAPI_MakeFace( - aSphericalSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); - myObject3d.Append(anAisSphere); -} - -void GeometrySamples::MinimalDistance3dSample() -{ - gp_Cylinder aCylinder(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 10.0); - gp_Lin aLine(gp_Pnt(20.0, 0.0, 5.0), gp_Dir(0.0, 1.0, 0.0)); - Extrema_ExtElCS anExtrema_ExtElCS(aLine, aCylinder); - - if (anExtrema_ExtElCS.IsDone()) - { - NCollection_Array1 aVecArray(1, anExtrema_ExtElCS.NbExt()); - NCollection_Array1 aPntArray(1, anExtrema_ExtElCS.NbExt()); - for (Standard_Integer i = 1; i <= anExtrema_ExtElCS.NbExt(); i++) - { - Extrema_POnCurv aCurvPoint; - Extrema_POnSurf aSurfPoint; - anExtrema_ExtElCS.Points(i, aCurvPoint, aSurfPoint); - gp_Pnt aCurvPnt = aCurvPoint.Value(); - gp_Pnt aSurfPnt = aSurfPoint.Value(); - - DisplayPnt(aCurvPnt, TCollection_AsciiString(i), Aspect_TOM_O_PLUS, 2.0); - DisplayPnt(aSurfPnt, TCollection_AsciiString(i), Aspect_TOM_O_STAR, 2.0); - gp_Vec aVec(aCurvPnt, aSurfPnt); - aVecArray.SetValue(i, aVec); - aPntArray.SetValue(i, aCurvPnt); - } - Standard_Integer aMinDistIndex(0); - Standard_Real aMinDistance = std::numeric_limits::max(); - for (Standard_Integer i = 1; i <= anExtrema_ExtElCS.NbExt(); i++) - { - if (aMinDistance > aVecArray(i).Magnitude()) - { - aMinDistIndex = i; - aMinDistance = aVecArray(i).Magnitude(); - } - } - Handle(AdaptorVec_AIS) anMinDistanceAis = - new AdaptorVec_AIS(aPntArray(aMinDistIndex), aVecArray(aMinDistIndex)); - anMinDistanceAis->SetText(" Min distance"); - myObject3d.Append(anMinDistanceAis); - } - Handle(Geom_CylindricalSurface) aCylindricalSurface = new Geom_CylindricalSurface(aCylinder); - Handle(AIS_Shape) anAisCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace( - aCylindricalSurface, 0.0, 2.0*M_PI, 0.0, 10.0, Precision::Confusion()).Shape()); - myObject3d.Append(anAisCylinder); - Handle(AdaptorVec_AIS) anLineAis = new AdaptorVec_AIS(aLine.Location(), aLine.Direction(), 8.0); - anLineAis->SetText(" gp_Lin"); - myObject3d.Append(anLineAis); -} - -void GeometrySamples::Intersection3dSample() -{ - gp_Lin aLine(gp_Pnt(0.0, 0.0, 10.0), gp_Dir(0.0, 1.0, 0.0)); - gp_Cone aCone(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 0.25*M_PI, 0.0); - IntAna_Quadric anIntAna_Quadric(aCone); - IntAna_IntConicQuad anIntAna_IntConicQuad(aLine, anIntAna_Quadric); - if (anIntAna_IntConicQuad.IsDone()) - { - for (int i = 1; i <= anIntAna_IntConicQuad.NbPoints(); i++) - { - const gp_Pnt& aIntersectionPnt = anIntAna_IntConicQuad.Point(i); - DisplayPnt(aIntersectionPnt, TCollection_AsciiString(i)); - } - } - Handle(AdaptorVec_AIS) aLineVecAIS = new AdaptorVec_AIS(aLine.Location(), gp_Vec(aLine.Direction())*5.0); - aLineVecAIS->SetText(" Base vector"); - myObject3d.Append(aLineVecAIS); - Handle(Geom_ConicalSurface) aConicalSurface = new Geom_ConicalSurface(aCone); - Handle(AIS_Shape) anAisCone = new AIS_Shape(BRepBuilderAPI_MakeFace( - aConicalSurface, 0.0, 2.0*M_PI, 0.0, 20.0, Precision::Confusion()).Shape()); - myObject3d.Append(anAisCone); -} - -void GeometrySamples::TranslatedPoint2dSample() -{ - gp_Pnt2d aPnt1; - gp_Pnt2d aPnt2 = aPnt1.Translated(gp_Vec2d(10.0, 10.0)); - DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 1.0); - DisplayPnt(aPnt2, "2", Aspect_TOM_PLUS, 1.0); - gp_Vec2d aTranslationVec(aPnt1, aPnt2); - Handle(AdaptorVec_AIS) aVecAIS = new AdaptorVec_AIS(aPnt1, aTranslationVec); - aVecAIS->SetText(" Translation"); - myObject2d.Append(aVecAIS); -} - -void GeometrySamples::RotatedDirection2dSample() -{ - gp_Dir2d aBaseDir(1.0, 1.0); - gp_Dir2d aRotatedDir = aBaseDir.Rotated(M_PI_4); - - myResult << "An angle between directions: " << aBaseDir.Angle(aRotatedDir)*180.0 / M_PI << " grad"; - Handle(AdaptorVec_AIS) aBaseAIS = new AdaptorVec_AIS(gp_Pnt2d(), aBaseDir, 5.0); - aBaseAIS->SetText(" Base"); - myObject2d.Append(aBaseAIS); - Handle(AdaptorVec_AIS) aRotatedAIS = new AdaptorVec_AIS(gp_Pnt2d(), aRotatedDir, 5.0); - aRotatedAIS->SetText(" Rotated"); - myObject2d.Append(aRotatedAIS); -} - -void GeometrySamples::MirroredAxis2dSample() -{ - gp_Ax22d aBaseAx(gp_Pnt2d(10.0, 0.0), gp_Dir2d(1.0, 0.0), Standard_True); - gp_Ax22d aMirrorAx = aBaseAx.Mirrored(gp_Pnt2d()); - - DisplayPnt(gp_Pnt2d(), "Mirror point", Aspect_TOM_PLUS, 1.0); - Handle(AdaptorVec_AIS) aBaseX_AIS = new AdaptorVec_AIS(aBaseAx.Location(), aBaseAx.XDirection(), 5.0); - aBaseX_AIS->SetText(" X (Base)"); - myObject2d.Append(aBaseX_AIS); - Handle(AdaptorVec_AIS) aBaseY_AIS = new AdaptorVec_AIS(aBaseAx.Location(), aBaseAx.YDirection(), 5.0); - aBaseY_AIS->SetText("Y (Base)"); - myObject2d.Append(aBaseY_AIS); - Handle(AdaptorVec_AIS) aMirrorX_AIS = new AdaptorVec_AIS(aMirrorAx.Location(), aMirrorAx.XDirection(), 5.0); - aMirrorX_AIS->SetText("X (Mirror)"); - myObject2d.Append(aMirrorX_AIS); - Handle(AdaptorVec_AIS) aMirrorY_AIS = new AdaptorVec_AIS(aMirrorAx.Location(), aMirrorAx.YDirection(), 5.0); - aMirrorY_AIS->SetText(" Y (Mirror)"); - myObject2d.Append(aMirrorY_AIS); -} - -void GeometrySamples::TransformedEllipse2dSample() -{ - // Creates an ellipse with the major axis, the major and the minor radius. - // The location of the MajorAxis is the center of the ellipse.The sense of - // parametrization is given by Sense.Warnings : It is possible to create - // an ellipse with MajorRadius = MinorRadius.Raises - // ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0. - gp_Elips2d aBaseEllips(gp_Ax2d(gp_Pnt2d(), gp_Dir2d(1.0, 0.0)), 20.0, 10.0); - gp_Trsf2d aRotTrsf; - aRotTrsf.SetRotation(gp_Pnt2d(), M_PI_4); - gp_Trsf2d aScaleTrsf; - aScaleTrsf.SetScale(gp_Pnt2d(), 1.5); - gp_Trsf2d aTranslTrsf; - aTranslTrsf.SetTranslation(gp_Vec2d(30.0, 0.0)); - gp_Trsf2d aComplexTrsf = aRotTrsf * aScaleTrsf * aTranslTrsf; - gp_Elips2d aTransfEllips = aBaseEllips.Transformed(aComplexTrsf); - - Handle(Geom2d_Ellipse) aBaseEllipse = new Geom2d_Ellipse(aBaseEllips); - Handle(AdaptorCurve2d_AIS) anAisBaseEllipse = new AdaptorCurve2d_AIS(aBaseEllipse, Aspect_TOL_DASH); - myObject2d.Append(anAisBaseEllipse); - Handle(Geom2d_Ellipse) aTransfEllipse = new Geom2d_Ellipse(aTransfEllips); - Handle(AdaptorCurve2d_AIS) anAisTransfEllipse = new AdaptorCurve2d_AIS(aTransfEllipse, Aspect_TOL_DASH); - myObject2d.Append(anAisTransfEllipse); -} - -void GeometrySamples::ConjugateObjects2dSample() -{ - gp_Parab2d aParab(gp_Ax2d(), 20.0); - gp_Ax2d aDirectrix = aParab.Directrix(); - gp_Pnt2d aFocus = aParab.Focus(); - gp_Pnt2d aLocation = aParab.Location(); - gp_Ax2d aMirror = aParab.MirrorAxis(); - - Handle(AdaptorVec_AIS) aDirectAIS = new AdaptorVec_AIS(aDirectrix.Location(), gp_Vec2d(aDirectrix.Direction())*10.0); - aDirectAIS->SetText(" Directrix"); - myObject2d.Append(aDirectAIS); - Handle(AdaptorVec_AIS) aMirrorAIS = new AdaptorVec_AIS(aMirror.Location(), gp_Vec2d(aMirror.Direction())*10.0); - aMirrorAIS->SetText(" Mirror Axis"); - myObject2d.Append(aMirrorAIS); - - DisplayPnt(aFocus, "Focus", Aspect_TOM_PLUS, -3.0); - DisplayPnt(aLocation, " Location", Aspect_TOM_O_STAR, 3.0); - Handle(Geom2d_Parabola) aGeomParabola = new Geom2d_Parabola(aParab); - Handle(Geom2d_TrimmedCurve) aTrimmedParabola = new Geom2d_TrimmedCurve(aGeomParabola, 40.0, -40.0); - Handle(AdaptorCurve2d_AIS) anAisParabola = new AdaptorCurve2d_AIS(aTrimmedParabola, Aspect_TOL_DOT); - myObject2d.Append(anAisParabola); -} - -void GeometrySamples::Tangent2dSample() -{ - gp_Circ2d aCirc1(gp_Ax2d(gp_Pnt2d(0.0, 0.0), gp_Vec2d(1.0, 0.0)), 10.0); - gp_Circ2d aCirc2 = aCirc1.Translated(gp_Vec2d(50.0, 0.0)); - aCirc2.SetRadius(20.0); - - GccEnt_QualifiedCirc aQaCirc1(aCirc1, GccEnt_outside); - GccEnt_QualifiedCirc aQaCirc2(aCirc2, GccEnt_outside); - - GccAna_Lin2d2Tan aLin2d2Tan(aQaCirc1, aQaCirc2, 1E-6); - if (aLin2d2Tan.IsDone()) - { - for (int i = 1; i <= aLin2d2Tan.NbSolutions(); i++) - { - const gp_Lin2d& aTangentLin = aLin2d2Tan.ThisSolution(i); - Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aTangentLin.Location(), aTangentLin.Direction(), 20.0); - myObject2d.Append(anAisLin); - } - } - - Handle(Geom2d_Circle) aCircle1 = new Geom2d_Circle(aCirc1); - Handle(AdaptorCurve2d_AIS) anAisCirc1 = new AdaptorCurve2d_AIS(aCircle1, Aspect_TOL_SOLID); - myObject2d.Append(anAisCirc1); - Handle(Geom2d_Circle) aCircle2 = new Geom2d_Circle(aCirc2); - Handle(AdaptorCurve2d_AIS) anAisCirc2 = new AdaptorCurve2d_AIS(aCircle2, Aspect_TOL_SOLID); - myObject2d.Append(anAisCirc2); -} - -void GeometrySamples::ProjectionOfPoint2dSample() -{ - gp_Pnt2d aPntToProject(40.0, 40.0); - gp_Circ2d aCirc(gp_Ax2d(), 20.0); - Handle(Geom2d_Circle) aGeom_Circle = new Geom2d_Circle(aCirc); - Geom2dAPI_ProjectPointOnCurve aProjector(aPntToProject, aGeom_Circle); - gp_Pnt2d aProjectionPnt = aProjector.NearestPoint(); - - Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeom_Circle, Aspect_TOL_SOLID); - myObject2d.Append(anAisCirc); - DisplayPnt(aPntToProject, "Pnt to project"); - DisplayPnt(aProjectionPnt, "Projection Pnt", Aspect_TOM_O_STAR); -} - -void GeometrySamples::MinimalDistance2dSample() -{ - gp_Lin2d aLin(gp_Pnt2d(-40.0, 0.0), gp_Dir2d(1.0, 1.0)); - Handle(Geom2d_Line) aGeom_Line = new Geom2d_Line(aLin); - gp_Circ2d aCirc(gp_Ax2d(), 20.0); - Handle(Geom2d_Circle) aGeom_Circle = new Geom2d_Circle(aCirc); - - Geom2dAPI_ExtremaCurveCurve anExtremaFinder(aGeom_Line, aGeom_Circle, - std::numeric_limits::min(), - std::numeric_limits::max(), 0.0, M_PI*2.0); - if (anExtremaFinder.NbExtrema()) - { - gp_Pnt2d aPnt1, aPnt2; - anExtremaFinder.NearestPoints(aPnt1, aPnt2); - myResult << "Extrema found: " << anExtremaFinder.NbExtrema() << std::endl; - myResult << "Minimal distance: " << anExtremaFinder.LowerDistance() << std::endl; - DisplayPnt(aPnt1, "1"); - DisplayPnt(aPnt2, "2"); - } - else - { - myResult << "No Extrema found" << std::endl; - } - - Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeom_Circle, Aspect_TOL_SOLID); - myObject2d.Append(anAisCirc); - Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aLin.Location(), aLin.Direction(), 60.0); - anAisLin->SetText(" gp_Lin2d"); - myObject2d.Append(anAisLin); -} - -void GeometrySamples::Intersection2dSample() -{ - gp_Lin2d aLin(gp_Pnt2d(-20.0, 20.0), gp_Dir2d(1.0, -1.5)); - Handle(Geom2d_Line) aGeom_Line = new Geom2d_Line(aLin); - gp_Parab2d aParab(gp_Ax2d(), 20.0); - Handle(Geom2d_Parabola) aGeom_Parabola = new Geom2d_Parabola(aParab); - - Geom2dAPI_InterCurveCurve anIntersectFinder(aGeom_Line, aGeom_Parabola); - for (Standard_Integer i = 1; i <= anIntersectFinder.NbPoints(); i++) - { - gp_Pnt2d aPnt = anIntersectFinder.Point(i); - DisplayPnt(aPnt, i); - } - - myResult << "Number of intersections : " << anIntersectFinder.NbPoints() << std::endl; - - Handle(Geom2d_Parabola) aGeomParabola = new Geom2d_Parabola(aParab); - Handle(Geom2d_TrimmedCurve) aTrimmedParabola = new Geom2d_TrimmedCurve(aGeomParabola, 60.0, -60.0); - Handle(AdaptorCurve2d_AIS) anAisParabola = new AdaptorCurve2d_AIS(aTrimmedParabola, Aspect_TOL_DOT); - myObject2d.Append(anAisParabola); - Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aLin.Location(), aLin.Direction(), 90.0); - anAisLin->SetText(" gp_Lin2d"); - myObject2d.Append(anAisLin); -} - -void GeometrySamples::PointInfo3dSample() -{ - gp_Pnt aPnt1; - gp_Pnt aPnt2(10.0, 10.0, 10.0); - gp_Pnt aPnt3(10.0, -10.0, 0.0); - gp_Pnt aPnt4(10.0, 10.0, 10.0); - Standard_Boolean anIsEqual2_3 = aPnt2.IsEqual(aPnt3, 1E-6); - Standard_Boolean anIsEqual2_4 = aPnt2.IsEqual(aPnt4, 1E-6); - Standard_Real aDistance1_2 = aPnt1.Distance(aPnt2); - Standard_Real aDistance2_4 = aPnt2.Distance(aPnt4); - Standard_Real aSquareDistance1_2 = aPnt1.SquareDistance(aPnt2); - Standard_Real aSquareDistance2_4 = aPnt2.SquareDistance(aPnt4); - - myResult << "A coordinate of a point 1: X: " << aPnt1.X() << " Y: " << aPnt1.Y() << " Z: " << aPnt1.Z() << std::endl; - myResult << "A coordinate of a point 2: X: " << aPnt2.X() << " Y: " << aPnt2.Y() << " Z: " << aPnt2.Z() << std::endl; - myResult << "A coordinate of a point 3: X: " << aPnt3.X() << " Y: " << aPnt3.Y() << " Z: " << aPnt3.Z() << std::endl; - myResult << "A coordinate of a point 4: X: " << aPnt4.X() << " Y: " << aPnt4.Y() << " Z: " << aPnt4.Z() << std::endl; - - if (anIsEqual2_3) - { - myResult << "A point 2 is equal to a point 3" << std::endl; - } - else - { - myResult << "A point 2 is different from a point 3" << std::endl; - } - if (anIsEqual2_4) - { - myResult << "A point 2 is equal to a point 4" << std::endl; - } - else - { - myResult << "A point 2 is different from a point 4" << std::endl; - } - myResult << "A distance from a point 1 to a point 2 is: " << aDistance1_2 << std::endl; - myResult << "A distance from a point 2 to a point 4 is: " << aDistance2_4 << std::endl; - - myResult << "A square distance from a point 1 to a point 2 is: " << aSquareDistance1_2 << std::endl; - myResult << "A square distance from a point 2 to a point 4 is: " << aSquareDistance2_4 << std::endl; - - DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt2, "2 & 4", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt4, "", Aspect_TOM_PLUS, 0.5); -} - -void GeometrySamples::EllipseInfo3dSample() -{ - gp_Elips anElips(gp_Ax2(gp_Pnt(), gp_Dir(1.0, 0.0, 0.0)), 20.0, 10.0); - Standard_Real anArea = anElips.Area(); - // Returns the eccentricity of the ellipse between 0.0 and 1.0 - // If f is the distance between the center of the ellipse and the Focus1 then - // the eccentricity e = f / MajorRadius. Returns 0 if MajorRadius = 0. - Standard_Real anEccentricity = anElips.Eccentricity(); - // Returns the distance between the center of the ellipse and focus1 or focus2. - Standard_Real aFocal = anElips.Focal(); - // Returns p = (1 - e * e) * MajorRadius where e is the eccentricity - // of the ellipse. Returns 0 if MajorRadius = 0. - Standard_Real aParameter = anElips.Parameter(); - - myResult << "Ellipse area = " << anArea << " square units" << std::endl; - myResult << "Eccentricity = " << anEccentricity; - myResult << "Focal distance = " << aFocal; - myResult << "Ellipse parameter = " << aParameter; - - gp_Pnt aCenter = anElips.Location(); - gp_Pnt aFocus1 = anElips.Focus1(); - gp_Pnt aFocus2 = anElips.Focus2(); - DisplayPnt(aCenter, "Center", Aspect_TOM_PLUS, 2.0); - DisplayPnt(aFocus1, "focus 1", Aspect_TOM_PLUS, 2.0); - DisplayPnt(aFocus2, "focus 2", Aspect_TOM_PLUS, 2.0); - - Handle(Geom_Ellipse) aGeomEllipse = new Geom_Ellipse(anElips); - Handle(AdaptorCurve_AIS) anAisEllipce = new AdaptorCurve_AIS(aGeomEllipse); - myObject3d.Append(anAisEllipce); -} - -void GeometrySamples::PointInfo2dSample() -{ - gp_Pnt2d aPnt1; - gp_Pnt2d aPnt2(10.0, 10.0); - gp_Pnt2d aPnt3(10.0, -10.0); - gp_Pnt2d aPnt4(10.0, 10.0); - Standard_Boolean anIsEqual2_3 = aPnt2.IsEqual(aPnt3, 1E-6); - Standard_Boolean anIsEqual2_4 = aPnt2.IsEqual(aPnt4, 1E-6); - Standard_Real aDistance1_2 = aPnt1.Distance(aPnt2); - Standard_Real aDistance2_4 = aPnt2.Distance(aPnt4); - Standard_Real aSquareDistance1_2 = aPnt1.SquareDistance(aPnt2); - Standard_Real aSquareDistance2_4 = aPnt2.SquareDistance(aPnt4); - - myResult << "A coordinate of a point 1: X: " << aPnt1.X() << " Y: " << aPnt1.Y() << std::endl; - myResult << "A coordinate of a point 2: X: " << aPnt2.X() << " Y: " << aPnt2.Y() << std::endl; - myResult << "A coordinate of a point 3: X: " << aPnt3.X() << " Y: " << aPnt3.Y() << std::endl; - myResult << "A coordinate of a point 4: X: " << aPnt4.X() << " Y: " << aPnt4.Y() << std::endl; - if (anIsEqual2_3) - { - myResult << "A point 2 is equal to a point 3" << std::endl; - } - else - { - myResult << "A point 2 is different from a point 3" << std::endl; - } - if (anIsEqual2_4) - { - myResult << "A point 2 is equal to a point 4" << std::endl; - } - else - { - myResult << "A point 2 is different from a point 4" << std::endl; - } - - myResult << "A distance from a point 1 to a point 2 is: " << aDistance1_2 << std::endl; - myResult << "A distance from a point 2 to a point 4 is: " << aDistance2_4 << std::endl; - - myResult << "A square distance from a point 1 to a point 2 is: " << aSquareDistance1_2 << std::endl; - myResult << "A square distance from a point 2 to a point 4 is: " << aSquareDistance2_4 << std::endl; - - DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt2, "2 & 4", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt4, ""); -} - -void GeometrySamples::CircleInfo2dSample() -{ - gp_Circ2d aCirc(gp_Ax22d(gp_Pnt2d(10.0, 10.0), gp_Vec2d(1.0, 0.0)), 10.0); - gp_Pnt2d aPnt1(0.0, 10.0); - gp_Pnt2d aPnt2(10.0, 0.0); - gp_Pnt2d aPnt3(20.0, 20.0); - - if (aCirc.Contains(aPnt1, 1E-6)) - { - DisplayPnt(aPnt1, "1", Aspect_TOM_STAR, 3.0); - myResult << "A circle contains a point 1" << std::endl; - } - else - { - DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 1.0); - myResult << "A circle does contain a point 1" << std::endl; - } - if (aCirc.Contains(aPnt2, 1E-6)) - { - DisplayPnt(aPnt2, "2", Aspect_TOM_STAR, 1.0); - myResult << "A circle contains a point 2" << std::endl; - } - else - { - DisplayPnt(aPnt2, "2", Aspect_TOM_PLUS, 1.0); - myResult << "A circle does contain a point 2" << std::endl; - } - if (aCirc.Contains(aPnt3, 1E-6)) - { - DisplayPnt(aPnt3, "3", Aspect_TOM_STAR, 1.0); - myResult << "A circle contains a point 3" << std::endl; - } - else - { - DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 1.0); - myResult << "A circle does contain a point 3" << std::endl; - } - myResult << "Circle area = " << aCirc.Area() << "square units" << std::endl; - Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(aCirc); - Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle); - myObject2d.Append(anAisCirc); -} - -void GeometrySamples::FreeStyleCurves3dSample() -{ - // Define points. - gp_Pnt aPnt1(0.0, 0.0, 0.0); - gp_Pnt aPnt2(5.0, 5.0, 0.0); - gp_Pnt aPnt3(10.0, 5.0, 0.0); - gp_Pnt aPnt4(15.0, 0.0, 0.0); - - // Add points to the curve poles array. - TColgp_Array1OfPnt aPoles(1, 4); - aPoles.SetValue(1, aPnt1); - aPoles.SetValue(2, aPnt2); - aPoles.SetValue(3, aPnt3); - aPoles.SetValue(4, aPnt4); - - // Define BSpline weights. - TColStd_Array1OfReal aBSplineWeights(1, 4); - aBSplineWeights.SetValue(1, 1.0); - aBSplineWeights.SetValue(2, 0.5); - aBSplineWeights.SetValue(3, 0.5); - aBSplineWeights.SetValue(4, 1.0); - - // Define knots. - TColStd_Array1OfReal aKnots(1, 2); - aKnots.SetValue(1, 0.0); - aKnots.SetValue(2, 1.0); - - // Define multiplicities. - TColStd_Array1OfInteger aMults(1, 2); - aMults.SetValue(1, 4); - aMults.SetValue(2, 4); - - // Define BSpline degree and periodicity. - Standard_Integer aDegree = 3; - Standard_Boolean aPeriodic = Standard_False; - - // Create a BSpline curve. - Handle(Geom_BSplineCurve) aBSplineCurve = new Geom_BSplineCurve( - aPoles, aBSplineWeights, aKnots, aMults, aDegree, aPeriodic); - myResult << "Geom_BSplineCurve was created in red" << std::endl; - - // Define Bezier weights. - TColStd_Array1OfReal aBezierWeights(1, 4); - aBezierWeights.SetValue(1, 0.5); - aBezierWeights.SetValue(2, 1.5); - aBezierWeights.SetValue(3, 1.5); - aBezierWeights.SetValue(4, 0.5); - - // Create Bezier curve. - Handle(Geom_BezierCurve) aBezierCurve = new Geom_BezierCurve(aPoles, aBezierWeights); - myResult << "Geom_BezierCurve was created in green" << std::endl; - - Handle(AIS_ColoredShape) anAisBSplineCurve = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aBSplineCurve).Shape()); - Handle(AIS_ColoredShape) anAisBezierCurve = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aBezierCurve).Shape()); - anAisBSplineCurve->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisBezierCurve->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisBSplineCurve); - myObject3d.Append(anAisBezierCurve); - myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt1))); - myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt2))); - myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt3))); - myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt4))); -} - -void GeometrySamples::AnalyticalSurfaces3dSample() -{ - // Define a XY plane. - gp_Pln aPln(gp::Origin(), gp::DZ()); - // Create plane geometry. - Handle(Geom_Plane) aPlaneSurf = new Geom_Plane(aPln); - myResult << "Geom_Plane was created in red" << std::endl; - - // Define a cylinder. - gp_Cylinder aCyl(gp::XOY(), 2.5); - // Create cylindrical surface. - Handle(Geom_CylindricalSurface) aCylSurf = new Geom_CylindricalSurface(aCyl); - myResult << "Geom_CylindricalSurface was created in green" << std::endl; - - // Define a cone. - gp_Cone aCone(gp::XOY(), M_PI_4, 2.5); - // Create conical surface. - Handle(Geom_ConicalSurface) aConeSurf = new Geom_ConicalSurface(aCone); - myResult << "Geom_ConicalSurface was created in blue" << std::endl; - - // Define a sphere. - gp_Pnt aSphereCenter(15.0, 15.0, 15.0); - gp_Sphere aSphere(gp_Ax3(aSphereCenter, gp::DZ()), 8.0); - // Create conical surface. - Handle(Geom_SphericalSurface) aSphereSurf = new Geom_SphericalSurface(aSphere); - myResult << "Geom_SphericalSurface was created in cyan" << std::endl; - - // Define a sphere. - gp_Pnt aTorusCenter(-15.0, -15.0, 25.0); - gp_Torus aTorus(gp_Ax3(aTorusCenter, gp::DZ()), 15.0, 5.0); - // Create toroidal surface. - Handle(Geom_ToroidalSurface) aTorusSurf = new Geom_ToroidalSurface(aTorus); - myResult << "Geom_ToroidalSurface was created in yellow" << std::endl; - - Handle(AIS_ColoredShape) anAisPlane = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( - aPlaneSurf, 0.0, 20.0, 0.0, 20.0, Precision::Confusion()).Shape()); - Handle(AIS_ColoredShape) anAisCylinder = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( - aCylSurf, 0.0, 2.0 * M_PI, 5.0, 15.0, Precision::Confusion()).Shape()); - Handle(AIS_ColoredShape) anAisCone = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( - aConeSurf, 0.0, 2.0 * M_PI, 0.0, 15.0, Precision::Confusion()).Shape()); - Handle(AIS_ColoredShape) anAisSphere = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( - aSphereSurf, Precision::Confusion()).Shape()); - Handle(AIS_ColoredShape) anAisTorus = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( - aTorusSurf, Precision::Confusion()).Shape()); - anAisPlane->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisCylinder->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - anAisCone->SetColor(Quantity_Color(Quantity_NOC_BLUE1)); - anAisSphere->SetColor(Quantity_Color(Quantity_NOC_CYAN1)); - anAisTorus->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - myObject3d.Append(anAisPlane); - myObject3d.Append(anAisCylinder); - myObject3d.Append(anAisCone); - myObject3d.Append(anAisSphere); - myObject3d.Append(anAisTorus); -} - -void GeometrySamples::FreeStyleSurfaces3dSample() -{ - // Define a 4x4 grid of points for BSpline surface. - TColgp_Array2OfPnt aBSplinePnts(1, 4, 1, 4); - for (Standard_Integer i = 1; i <= 4; ++i) - { - gp_Pnt aPnt; - aPnt.SetX(5.0 * i); - for (Standard_Integer j = 1; j <= 4; ++j) - { - aPnt.SetY(5.0 * j); - if (1 < i && i < 4 && 1 < j && j < 4) - { - aPnt.SetZ(5.0); - } - else - { - aPnt.SetZ(0.0); - } - aBSplinePnts.SetValue(i, j, aPnt); - } - } - - // Define a 4x4 grid of points for Bezier surface. - TColgp_Array2OfPnt aBezierPnts(1, 4, 1, 4); - for (Standard_Integer i = 1; i <= 4; ++i) - { - gp_Pnt aPnt; - aPnt.SetX(20.0 + 5.0 * i); - for (Standard_Integer j = 1; j <= 4; ++j) - { - aPnt.SetY(20.0 + 5.0 * j); - if (1 < i && i < 4 && 1 < j && j < 4) - { - aPnt.SetZ(5.0); - } - else - { - aPnt.SetZ(0.0); - } - aBezierPnts.SetValue(i, j, aPnt); - } - } - - // Define BSpline weights. - TColStd_Array2OfReal aBSplineWeights(1, 4, 1, 4); - for (Standard_Integer i = 1; i <= 4; ++i) - { - for (Standard_Integer j = 1; j <= 4; ++j) - { - if (1 < i && i < 4 && 1 < j && j < 4) - { - aBSplineWeights.SetValue(i, j, 0.5); - } - else - { - aBSplineWeights.SetValue(i, j, 1.0); - } - } - } - - // Define knots. - TColStd_Array1OfReal aUKnots(1, 2), aVKnots(1, 2); - aUKnots.SetValue(1, 0.0); - aUKnots.SetValue(2, 1.0); - aVKnots.SetValue(1, 0.0); - aVKnots.SetValue(2, 1.0); - - // Define multiplicities. - TColStd_Array1OfInteger aUMults(1, 2), aVMults(1, 2); - aUMults.SetValue(1, 4); - aUMults.SetValue(2, 4); - aVMults.SetValue(1, 4); - aVMults.SetValue(2, 4); - - // Define BSpline degree and periodicity. - Standard_Integer aUDegree = 3; - Standard_Integer aVDegree = 3; - Standard_Boolean aUPeriodic = Standard_False; - Standard_Boolean aVPeriodic = Standard_False; - - // Create a BSpline surface. - Handle(Geom_BSplineSurface) aBSplineSurf = new Geom_BSplineSurface( - aBSplinePnts, aBSplineWeights, aUKnots, aVKnots, - aUMults, aVMults, aUDegree, aVDegree, aUPeriodic, aVPeriodic); - myResult << "Geom_BSplineSurface was created in red" << std::endl; - - // Define BSpline weights. - TColStd_Array2OfReal aBezierWeights(1, 4, 1, 4); - for (Standard_Integer i = 1; i <= 4; ++i) - { - for (Standard_Integer j = 1; j <= 4; ++j) - { - if (1 < i && i < 4 && 1 < j && j < 4) - { - aBezierWeights.SetValue(i, j, 1.5); - } - else - { - aBezierWeights.SetValue(i, j, 0.5); - } - } - } - - // Create a Bezier surface. - Handle(Geom_BezierSurface) aBezierSurf = new Geom_BezierSurface(aBezierPnts, aBezierWeights); - myResult << "Geom_BezierSurface was created in green" << std::endl; - - Handle(AIS_ColoredShape) anAisBSplineSurf = new AIS_ColoredShape( - BRepBuilderAPI_MakeFace(aBSplineSurf, Precision::Confusion()).Shape()); - Handle(AIS_ColoredShape) anAisBezierSurf = new AIS_ColoredShape( - BRepBuilderAPI_MakeFace(aBezierSurf, Precision::Confusion()).Shape()); - anAisBSplineSurf->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisBezierSurf->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisBSplineSurf); - myObject3d.Append(anAisBezierSurf); - for (TColgp_Array2OfPnt::Iterator anIt(aBSplinePnts); anIt.More(); anIt.Next()) - { - myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(anIt.Value()))); - } - for (TColgp_Array2OfPnt::Iterator anIt(aBezierPnts); anIt.More(); anIt.Next()) - { - myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(anIt.Value()))); - } -} - -void GeometrySamples::FreeStyleCurves2dSample() -{ - - // Define points. - gp_Pnt2d aPnt1(0.0, 0.0); - gp_Pnt2d aPnt2(5.0, 5.0); - gp_Pnt2d aPnt3(10.0, 5.0); - gp_Pnt2d aPnt4(15.0, 0.0); - - // Add points to the curve poles array. - TColgp_Array1OfPnt2d aBSplinePoles(1, 4); - aBSplinePoles.SetValue(1, aPnt1); - aBSplinePoles.SetValue(2, aPnt2); - aBSplinePoles.SetValue(3, aPnt3); - aBSplinePoles.SetValue(4, aPnt4); - - // Define BSpline weights. - TColStd_Array1OfReal aBSplineWeights(1, 4); - aBSplineWeights.SetValue(1, 1.0); - aBSplineWeights.SetValue(2, 0.5); - aBSplineWeights.SetValue(3, 0.5); - aBSplineWeights.SetValue(4, 1.0); - - // Define knots. - TColStd_Array1OfReal aKnots(1, 2); - aKnots.SetValue(1, 0.0); - aKnots.SetValue(2, 1.0); - - // Define multiplicities. - TColStd_Array1OfInteger aMults(1, 2); - aMults.SetValue(1, 4); - aMults.SetValue(2, 4); - - // Define BSpline degree and periodicity. - Standard_Integer aDegree = 3; - Standard_Boolean aPeriodic = Standard_False; - - // Create a BSpline curve. - Handle(Geom2d_BSplineCurve) aBSplineCurve = - new Geom2d_BSplineCurve(aBSplinePoles, aBSplineWeights, aKnots, aMults, aDegree, aPeriodic); - - - TColgp_Array1OfPnt2d aBezierPoles(1, 4); - gp_Vec2d anUp10Vec(0.0, 10.0); - aBezierPoles.SetValue(1, aPnt1.Translated(anUp10Vec)); - aBezierPoles.SetValue(2, aPnt2.Translated(anUp10Vec)); - aBezierPoles.SetValue(3, aPnt3.Translated(anUp10Vec)); - aBezierPoles.SetValue(4, aPnt4.Translated(anUp10Vec)); - - // Define Bezier weights. - TColStd_Array1OfReal aBezierWeights(1, 4); - aBezierWeights.SetValue(1, 0.5); - aBezierWeights.SetValue(2, 1.5); - aBezierWeights.SetValue(3, 1.5); - aBezierWeights.SetValue(4, 0.5); - - // Create Bezier curve. - Handle(Geom2d_BezierCurve) aBezierCurve = new Geom2d_BezierCurve(aBezierPoles, aBezierWeights); - - Handle(AdaptorCurve2d_AIS) anAisBSpline = new AdaptorCurve2d_AIS(aBSplineCurve); - myObject2d.Append(anAisBSpline); - Handle(AdaptorCurve2d_AIS) anAisBezier = new AdaptorCurve2d_AIS(aBezierCurve); - myObject2d.Append(anAisBezier); - - DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt2, "2", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 0.5); - DisplayPnt(aPnt4, "4", Aspect_TOM_PLUS, 0.5); -} - -void GeometrySamples::TrimmedCurve3dSample() -{ - // Define a circle placed in the origin of XY coordinate - // plane and with the radius equal to 5. - gp_Circ aCirc(gp::XOY(), 5.0); - // Create a closed circular curve. - Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc); - myResult << "Geom_Circle was created in yellow" << std::endl; - - // Cut off a quarter of the circle. - Handle(Geom_TrimmedCurve) aCircQuater = new Geom_TrimmedCurve(aCircCurve, 0.0, M_PI_2); - myResult << "Geom_TrimmedCurve was created in red" << std::endl; - - Handle(AIS_ColoredShape) anAisCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircCurve).Shape()); - Handle(AIS_ColoredShape) anAisCircQuater = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircQuater).Shape()); - anAisCirc->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisCircQuater->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisCircQuater->SetWidth(2.5); - myObject3d.Append(anAisCirc); - myObject3d.Append(anAisCircQuater); -} - -void GeometrySamples::OffsetCurve3dSample() -{ - // Define a circle placed in the origin of XY coordinate - // plane and with the radius equal to 5. - gp_Circ aCirc(gp::XOY(), 5.0); - // Create a closed circular curve. - Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc); - myResult << "Geom_Circle was created in yellow" << std::endl; - - // An offset curve is a curve at constant distance (Offset) from - // a basis curve in a reference direction V. - // The offset curve takes its parametrization from the basis curve. - // The Offset curve is in the direction of the normal N - // defined with the cross product T^V, where the vector T - // is given by the first derivative on the basis curve with non zero length. - // The distance offset may be positive or negative to indicate the - // preferred side of the curve: - // . distance offset >0 => the curve is in the direction of N - // . distance offset <0 => the curve is in the direction of - N - // On the Offset curve: - // Value (U) = BasisCurve.Value(U) + (Offset * (T ^ V)) / ||T ^ V|| - // At any point the Offset direction V must not be parallel to the - // vector T and the vector T must not have null length else the - // offset curve is not defined. - - // Expand the circle by Offset equal to a quarter of the radius - // with direction V equal to Z. - Standard_Real anExpandOffset = +aCirc.Radius() / 4.0; - gp_Dir anExpandDir = gp::DZ(); - Handle(Geom_OffsetCurve) anExpandCircCurve = new Geom_OffsetCurve( - aCircCurve, anExpandOffset, anExpandDir); - myResult << "Geom_OffsetCurve (expanded circle) was created in red" << std::endl; - - // Collapse the circle by Offset equal to a half of the radius with direction V equal to Z. - Standard_Real anCollapseOffset = -aCirc.Radius() / 2.0; - gp_Dir anCollapseDir = gp::DZ(); - Handle(Geom_OffsetCurve) anCollapseCircCurve = new Geom_OffsetCurve (aCircCurve, anCollapseOffset, anCollapseDir); - myResult << "Geom_OffsetCurve (collapsed circle) was created in green" << std::endl; - - Handle(AIS_ColoredShape) anAisCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircCurve).Shape()); - Handle(AIS_ColoredShape) anAisExpandCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(anExpandCircCurve).Shape()); - Handle(AIS_ColoredShape) anAisCpllapsedCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(anCollapseCircCurve).Shape()); - anAisCirc->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisExpandCirc->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisCpllapsedCirc->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisCirc); - myObject3d.Append(anAisExpandCirc); - myObject3d.Append(anAisCpllapsedCirc); -} - -void GeometrySamples::BSplineFromCircle3dSample() -{ - // Define a circle placed in the origin of XY coordinate - // plane and with the radius equal to 5. - gp_Circ aCirc(gp::XOY(), 5.0); - // Create a closed circular curve. - Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc); - myResult << "Geom_Circle was created in yellow" << std::endl; - - // Convert the circle curve to a BSpline one. - Handle(Geom_BSplineCurve) aBSplineFromCirc = GeomConvert::CurveToBSplineCurve(aCircCurve); - myResult << "Geom_BSplineCurve was created in red:" << std::endl; - myResult << "Degree: " << aBSplineFromCirc->Degree() << std::endl; - myResult << "Periodic: " << (aBSplineFromCirc->IsPeriodic() ? "Yes" : "No") << std::endl; - myResult << "Poles: [" << aBSplineFromCirc->Poles().Size() << "]" << std::endl; - for (TColgp_Array1OfPnt::Iterator anIt(aBSplineFromCirc->Poles()); anIt.More(); anIt.Next()) - { - myResult << " (" << anIt.Value().X() << ", " << anIt.Value().Y() << ", " << anIt.Value().Z() << ")" << std::endl; - } - - Handle(AIS_ColoredShape) anAisCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircCurve).Shape()); - Handle(AIS_ColoredShape) anAisBSpline = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aBSplineFromCirc).Shape()); - anAisCirc->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisBSpline->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisCirc); - myObject3d.Append(anAisBSpline); -} - -void GeometrySamples::TrimmedSurface3dSample() -{ - // Define a XY plane. - gp_Pln aPln(gp::XOY()); - // Create a plane surface. - Handle(Geom_Plane) aPlaneSurf = new Geom_Plane(aPln); - myResult << "Geom_Plane was created" << std::endl; - - // Trim [0 ... 30 X 0 ... 50] rectangular range. - Standard_Real aUMin = 0.0; - Standard_Real aUMax = 30.0; - Standard_Real aVMin = 0.0; - Standard_Real aVMax = 50.0; - Handle(Geom_RectangularTrimmedSurface) aTrimmedPlaneSurf - = new Geom_RectangularTrimmedSurface(aPlaneSurf, aUMin, aUMax, aVMin, aVMax); - myResult << "Geom_RectangularTrimmedSurface was created in red" << std::endl; - - Handle(AIS_Plane) anAisPlane = new AIS_Plane(aPlaneSurf); - Handle(AIS_ColoredShape) anAisTimmedPlane = new AIS_ColoredShape (BRepBuilderAPI_MakeFace (aTrimmedPlaneSurf, 0.001).Shape()); - anAisTimmedPlane->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisPlane); - myObject3d.Append(anAisTimmedPlane); -} - -void GeometrySamples::OffsetSurface3dSample() -{ - // Define a XY plane. - gp_Pln aPln(gp::XOY()); - // Create a plane surface. - Handle(Geom_Plane) aPlaneSurf = new Geom_Plane(aPln); - myResult << "Geom_Plane was created" << std::endl; - - // An offset surface is defined by: - // - the basis surface to which it is parallel, and - // - the distance between the offset surface and its basis surface. - // A point on the offset surface is built by measuring the - // offset value along the normal vector at a point on the - // basis surface. This normal vector is given by the cross - // product D1u^D1v, where D1u and D1v are the - // vectors tangential to the basis surface in the u and v - // parametric directions at this point. The side of the - // basis surface on which the offset is measured - // depends on the sign of the offset value. - - // Offset the plane in the normal direction. - Standard_Real aPosOffset = 10.0; - Handle(Geom_OffsetSurface) aPosOffsetSurf = new Geom_OffsetSurface(aPlaneSurf, aPosOffset); - myResult << "Geom_OffsetSurface with " << aPosOffset << " was created in red" << std::endl; - - // Offset the plane in direction opposite to the normal one. - Standard_Real aNegOffset = -15.0; - Handle(Geom_OffsetSurface) aNegOffsetSurf = new Geom_OffsetSurface(aPlaneSurf, aNegOffset); - myResult << "Geom_OffsetSurface with " << aNegOffset << " was created in green" << std::endl; - - Handle(AIS_ColoredShape) anAisPlane = new AIS_ColoredShape( - BRepBuilderAPI_MakeFace(aPlaneSurf, 0.0, 10.0, 0.0, 10.0, Precision::Confusion()).Shape()); - Handle(AIS_ColoredShape) anAisPosOffsetPlane = new AIS_ColoredShape( - BRepBuilderAPI_MakeFace(aPosOffsetSurf, 0.0, 10.0, 0.0, 10.0, Precision::Confusion()).Shape()); - Handle(AIS_ColoredShape) anAisNegOffsetPlane = new AIS_ColoredShape( - BRepBuilderAPI_MakeFace(aNegOffsetSurf, 0.0, 10.0, 0.0, 10.0, Precision::Confusion()).Shape()); - anAisPosOffsetPlane->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisNegOffsetPlane->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisPlane); - myObject3d.Append(anAisPosOffsetPlane); - myObject3d.Append(anAisNegOffsetPlane); -} - -void GeometrySamples::ExtrusionSurface3dSample() -{ - // Create an ellipse curve in XY plane. - Standard_Real aMinorRadius = 10.0; - Standard_Real aMajorRadius = 20.0; - Handle(Geom_Ellipse) anEllipseCurve = new Geom_Ellipse(gp::XOY(), aMajorRadius, aMinorRadius); - myResult << "Geom_Ellipse was created in yellow" << std::endl; - - // Make a linear extrusion of the ellipse at 45 degrees to Z axis - gp_Dir aDirOfExtr = gp::DZ(); - Handle(Geom_SurfaceOfLinearExtrusion) aLinExtrSurf - = new Geom_SurfaceOfLinearExtrusion(anEllipseCurve, aDirOfExtr); - myResult << "Geom_SurfaceOfLinearExtrusion was created in red" << std::endl; - - Handle(AIS_ColoredShape) anAisEllipse = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(anEllipseCurve).Shape()); - Handle(AIS_ColoredShape) anAisExtrSurf = new AIS_ColoredShape( - BRepBuilderAPI_MakeFace(aLinExtrSurf, 0.0, 2.0 * M_PI, 0.0, 30.0, - Precision::Confusion()).Shape()); - anAisEllipse->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisEllipse->SetWidth(2.5); - anAisExtrSurf->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisEllipse); - myObject3d.Append(anAisExtrSurf); -} - -void GeometrySamples::RevolutionSurface3dSample() -{ - // Create an ellipse curve in XY plane with - // the center at (-10, 0, 0). - Standard_Real aMinorRadius = 5.0; - Standard_Real aMajorRadius = 10.0; - gp_Pnt aCenter(-30.0, 0.0, 0.0); - Handle(Geom_Ellipse) anEllipseCurve = new Geom_Ellipse(gp_Ax2(aCenter, gp::DZ()), - aMajorRadius, aMinorRadius); - myResult << "Geom_Ellipse was created in yellow" << std::endl; - - // Make a revolution of the ellipse around Y axis - Handle(Geom_SurfaceOfRevolution) aRevolSurf = new Geom_SurfaceOfRevolution(anEllipseCurve, gp::OY()); - myResult << "Geom_SurfaceOfRevolution was created in red" << std::endl; - - Handle(AIS_ColoredShape) anAisEllipse = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(anEllipseCurve).Shape()); - Handle(AIS_ColoredShape) anAisRevolSurf = new AIS_ColoredShape( - BRepBuilderAPI_MakeFace(aRevolSurf, Precision::Confusion()).Shape()); - anAisEllipse->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisEllipse->SetWidth(2.5); - anAisRevolSurf->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisEllipse); - myObject3d.Append(anAisRevolSurf); -} - -void GeometrySamples::TrimmedCurve2dSample() -{ - // Create a closed circular curve. - Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(), gp_Vec2d(1.0, 0.0)), 5.0); - Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle); - myObject2d.Append(anAisCirc); - - // Cut off a quarter of the circle. - Handle(Geom2d_TrimmedCurve) aCircQuater = new Geom2d_TrimmedCurve(aGeomCircle, 0.0, M_PI_2); - aCircQuater->Translate(gp_Vec2d(15.0, 0.0)); - Handle(AdaptorCurve2d_AIS) anAisCircQuater = new AdaptorCurve2d_AIS(aCircQuater); - myObject2d.Append(anAisCircQuater); -} - -void GeometrySamples::OffsetCurve2dSample() -{ - Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(), gp_Vec2d(1.0, 0.0)), 5.0); - - Standard_Real anExpandOffset = aGeomCircle->Radius() / 4.0; - Handle(Geom2d_OffsetCurve) anExpandCircCurve = new Geom2d_OffsetCurve(aGeomCircle, anExpandOffset); - - Standard_Real anCollapseOffset = -aGeomCircle->Radius() / 2.0; - Handle(Geom2d_OffsetCurve) anCollapseCircCurve = new Geom2d_OffsetCurve(aGeomCircle, anCollapseOffset); - - Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle); - myObject2d.Append(anAisCirc); - Handle(AdaptorCurve2d_AIS) anAisExpand = new AdaptorCurve2d_AIS(anExpandCircCurve); - myObject2d.Append(anAisExpand); - Handle(AdaptorCurve2d_AIS) anAisCollapse = new AdaptorCurve2d_AIS(anCollapseCircCurve); - myObject2d.Append(anAisCollapse); -} - -void GeometrySamples::BoundingBoxOfSurface3dSample() -{ - // Define a 4x4 grid of points for BSpline surface. - TColgp_Array2OfPnt aPoints(1, 4, 1, 4); - for (Standard_Integer i = 1; i <= 4; ++i) - { - gp_Pnt aPnt; - aPnt.SetX(5.0 * i); - for (Standard_Integer j = 1; j <= 4; ++j) - { - aPnt.SetY(5.0 * j); - if (1 < i && i < 4 && 1 < j && j < 4) - { - aPnt.SetZ(5.0); - } - else - { - aPnt.SetZ(0.0); - } - aPoints.SetValue(i, j, aPnt); - } - } - - // Make a BSpline surface from the points array. - Handle(Geom_BSplineSurface) aBSplineSurf = GeomAPI_PointsToBSplineSurface(aPoints).Surface(); - myResult << "Geom_BSplineSurface was created" << std::endl; - - // Compute BSpline surface bounding box. - Bnd_Box aBndBox; - BndLib_AddSurface::AddOptimal(GeomAdaptor_Surface(aBSplineSurf), Precision::Confusion(), aBndBox); - myResult << "Bounding box:" << std::endl; - myResult << " Min corner = [ " - << aBndBox.CornerMin().X() << ", " - << aBndBox.CornerMin().Y() << ", " - << aBndBox.CornerMin().Z() << " ]" << std::endl; - myResult << " Max corner = [ " - << aBndBox.CornerMax().X() << ", " - << aBndBox.CornerMax().Y() << ", " - << aBndBox.CornerMax().Z() << " ]" << std::endl; - - Handle(AIS_ColoredShape) anAisBSplineSurf = new AIS_ColoredShape( - BRepBuilderAPI_MakeFace(aBSplineSurf, Precision::Confusion()).Shape()); - Handle(AIS_ColoredShape) anAisBndBox = new AIS_ColoredShape( - BRepPrimAPI_MakeBox(aBndBox.CornerMin(), aBndBox.CornerMax()).Shell()); - myObject3d.Append(anAisBSplineSurf); - myObject3d.Append(anAisBndBox); - myContext->SetDisplayMode(anAisBndBox, 0, Standard_True); -} - -void GeometrySamples::BoundingBoxOfCurves3dSample() -{ - // Define points. - gp_Pnt aPnt1(0.0, 0.0, 10.0); - gp_Pnt aPnt2(5.0, 5.0, 5.0); - gp_Pnt aPnt3(10.0, 10.0, 15.0); - gp_Pnt aPnt4(15.0, 5.0, 20.0); - - // Add points to the curve poles array. - TColgp_Array1OfPnt aPoles(1, 4); - aPoles.SetValue(1, aPnt1); - aPoles.SetValue(2, aPnt2); - aPoles.SetValue(3, aPnt3); - aPoles.SetValue(4, aPnt4); - - // Make a BSpline curve from the points array. - Handle(Geom_BSplineCurve) aBSplineCurve = GeomAPI_PointsToBSpline(aPoles).Curve(); - myResult << "aBSplineCurve was created" << std::endl; - - // Compute BSpline curve bounding box. - Bnd_Box aBndBox; - BndLib_Add3dCurve::AddOptimal(GeomAdaptor_Curve(aBSplineCurve), Precision::Confusion(), aBndBox); - myResult << "Bounding box:" << std::endl; - myResult << " Min corner = [ " - << aBndBox.CornerMin().X() << ", " - << aBndBox.CornerMin().Y() << ", " - << aBndBox.CornerMin().Z() << " ]" << std::endl; - myResult << " Max corner = [ " - << aBndBox.CornerMax().X() << ", " - << aBndBox.CornerMax().Y() << ", " - << aBndBox.CornerMax().Z() << " ]" << std::endl; - - Handle(AIS_ColoredShape) anAisBSplineCurve = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aBSplineCurve).Shape()); - Handle(AIS_ColoredShape) anAisBndBox = new AIS_ColoredShape (BRepPrimAPI_MakeBox(aBndBox.CornerMin(), aBndBox.CornerMax()).Shell()); - myObject3d.Append(anAisBSplineCurve); - myObject3d.Append(anAisBndBox); - myContext->SetDisplayMode(anAisBndBox, 0, Standard_True); -} - -void GeometrySamples::BoundingBoxOfCurves2dSample() -{ - // Define points. - gp_Pnt2d aPnt1(0.0, 0.0); - gp_Pnt2d aPnt2(5.0, 5.0); - gp_Pnt2d aPnt3(10.0, 10.0); - gp_Pnt2d aPnt4(15.0, 5.0); - - // Add points to the curve poles array. - TColgp_Array1OfPnt2d aPoles(1, 4); - aPoles.SetValue(1, aPnt1); - aPoles.SetValue(2, aPnt2); - aPoles.SetValue(3, aPnt3); - aPoles.SetValue(4, aPnt4); - - // Make a BSpline curve from the points array. - Handle(Geom2d_BSplineCurve) aBSplineCurve = Geom2dAPI_PointsToBSpline(aPoles).Curve(); - - // Compute BSpline curve bounding box. - Bnd_Box2d aBndBox; - BndLib_Add2dCurve::AddOptimal(aBSplineCurve, 0.0, 1.0, Precision::PConfusion(), aBndBox); - Standard_Real aXmin, aYmin, aXmax, aYmax; - aBndBox.Get(aXmin, aYmin, aXmax, aYmax); - - myResult << "Bounding box:" << std::endl; - myResult << " Min corner = [ " << aXmin << ", " << aYmin << " ]" << std::endl; - myResult << " Max corner = [ " << aXmax << ", " << aYmax << " ]" << std::endl; - - Handle(AdaptorCurve2d_AIS) anAisBSpline = new AdaptorCurve2d_AIS(aBSplineCurve); - - Handle(AdaptorVec_AIS) anAisVec1 = new AdaptorVec_AIS(gp_Pnt2d(aXmin, aYmin), gp_Pnt2d(aXmin, aYmax)); - Handle(AdaptorVec_AIS) anAisVec2 = new AdaptorVec_AIS(gp_Pnt2d(aXmin, aYmax), gp_Pnt2d(aXmax, aYmax)); - Handle(AdaptorVec_AIS) anAisVec3 = new AdaptorVec_AIS(gp_Pnt2d(aXmax, aYmax), gp_Pnt2d(aXmax, aYmin)); - Handle(AdaptorVec_AIS) anAisVec4 = new AdaptorVec_AIS(gp_Pnt2d(aXmax, aYmin), gp_Pnt2d(aXmin, aYmin)); - - myObject2d.Append(anAisBSpline); - myObject2d.Append(anAisVec1); - myObject2d.Append(anAisVec2); - myObject2d.Append(anAisVec3); - myObject2d.Append(anAisVec4); -} - -void GeometrySamples::DumpCircleInfoSample() -{ - // Define a circle placed in the origin of XY coordinate - // plane and with the radius equal to 0.5. - gp_Circ aCirc(gp::XOY(), 0.5); - // Create a closed circular curve. - Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc); - myResult << "Geom_Circle was created:" << std::endl; - myResult << " Center = [ " - << aCircCurve->Position().Location().X() << ", " - << aCircCurve->Position().Location().Y() << ", " - << aCircCurve->Position().Location().Z() << " ]" - << std::endl; - myResult << " Radius = " << aCircCurve->Radius() << std::endl; - myResult << " Plane normal = [ " - << aCircCurve->Position().Direction().X() << ", " - << aCircCurve->Position().Direction().Y() << ", " - << aCircCurve->Position().Direction().Z() << " ]" - << std::endl; - - Handle(AIS_Circle) anAisCircle = new AIS_Circle(aCircCurve); - Handle(AIS_TextLabel) anAisCenterLabel = new AIS_TextLabel(); - anAisCenterLabel->SetText(" Center"); - anAisCenterLabel->SetPosition(aCircCurve->Position().Location()); - Handle(AIS_Point) anAisCenter = new AIS_Point(new Geom_CartesianPoint(aCirc.Location())); - Handle(AIS_Axis) anAisAxis = new AIS_Axis(new Geom_Axis2Placement(aCircCurve->Position()), AIS_TOAX_ZAxis); - myObject3d.Append(anAisCircle); - myObject3d.Append(anAisCenterLabel); - myObject3d.Append(anAisAxis); -} - -void GeometrySamples::DumpBSplineCurveInfoSample() -{ - // Define points. - gp_Pnt aPnt1(0.0, 0.0, 10.0); - gp_Pnt aPnt2(5.0, 5.0, 5.0); - gp_Pnt aPnt3(10.0, 10.0, 15.0); - gp_Pnt aPnt4(15.0, 5.0, 20.0); - - // Add points to the curve poles array. - TColgp_Array1OfPnt aPoles(1, 4); - aPoles.SetValue(1, aPnt1); - aPoles.SetValue(2, aPnt2); - aPoles.SetValue(3, aPnt3); - aPoles.SetValue(4, aPnt4); - - // Make a BSpline curve from the points array - Handle(Geom_BSplineCurve) aBSplineCurve = GeomAPI_PointsToBSpline(aPoles).Curve(); - myResult << "aBSplineCurve was created:" << std::endl; - myResult << " Degree = " << aBSplineCurve->Degree() << std::endl; - myResult << " Parameter range = [ " - << aBSplineCurve->FirstParameter() << ", " - << aBSplineCurve->LastParameter() << " ]" - << std::endl; - NCollection_List aParams; - aParams.Append(0.75 * aBSplineCurve->FirstParameter() + 0.25 * aBSplineCurve->LastParameter()); - aParams.Append(0.50 * aBSplineCurve->FirstParameter() + 0.50 * aBSplineCurve->LastParameter()); - aParams.Append(0.25 * aBSplineCurve->FirstParameter() + 0.75 * aBSplineCurve->LastParameter()); - myResult << " Curve info:" << std::endl; - for (NCollection_List::Iterator anIt(aParams); anIt.More(); anIt.Next()) - { - Standard_Real aParam = anIt.Value(); - gp_Pnt aPnt; - gp_Vec aVec; - aBSplineCurve->D1(aParam, aPnt, aVec); - myResult << " Param = " << aParam << std::endl; - myResult << " P = [ " << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl; - myResult << " D = [ " << aVec.X() << ", " << aVec.Y() << ", " << aVec.Z() << " ]" << std::endl; - myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt))); - Handle(AIS_TextLabel) anAisCenterLabel = new AIS_TextLabel(); - Standard_SStream aSS; - aSS << "P [" << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << "]" << std::endl; - aSS << "D [" << aVec.X() << ", " << aVec.Y() << ", " << aVec.Z() << "]" << std::endl; - anAisCenterLabel->SetText(aSS.str().c_str()); - anAisCenterLabel->SetPosition(aPnt); - myObject3d.Append(anAisCenterLabel); - Handle(AIS_Axis) anAisD = new AIS_Axis(new Geom_Axis1Placement(gp_Ax1(aPnt, aVec))); - myObject3d.Append(anAisD); - } - - Handle(AIS_ColoredShape) anAisBSplineCurve = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aBSplineCurve).Shape()); - anAisBSplineCurve->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisBSplineCurve); -} diff --git a/samples/OCCTOverview/code/GeometrySamples.h b/samples/OCCTOverview/code/GeometrySamples.h deleted file mode 100644 index 7da4ad7645..0000000000 --- a/samples/OCCTOverview/code/GeometrySamples.h +++ /dev/null @@ -1,102 +0,0 @@ -// 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 diff --git a/samples/OCCTOverview/code/MakeBottle.cxx b/samples/OCCTOverview/code/MakeBottle.cxx deleted file mode 100644 index 44307e0759..0000000000 --- a/samples/OCCTOverview/code/MakeBottle.cxx +++ /dev/null @@ -1,218 +0,0 @@ -// 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 - -#include - -#include -#include -#include -#include - -#include - -#include - -#include -#include - -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include - -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 is the top face of the bottleÂ’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; -} diff --git a/samples/OCCTOverview/code/MakeBottle.h b/samples/OCCTOverview/code/MakeBottle.h deleted file mode 100644 index ad1e783064..0000000000 --- a/samples/OCCTOverview/code/MakeBottle.h +++ /dev/null @@ -1,33 +0,0 @@ -// 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 -#include - -//! Returns sample bottle TopoDS_Shape -TopoDS_Shape MakeBottle(const Standard_Real theWidth, - const Standard_Real theyHeight, - const Standard_Real theThickness); - -#endif // MAKEBOTTLE_H diff --git a/samples/OCCTOverview/code/Ocaf.xml b/samples/OCCTOverview/code/Ocaf.xml deleted file mode 100644 index ea269c4b19..0000000000 --- a/samples/OCCTOverview/code/Ocaf.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/OCCTOverview/code/OcafSamples.cxx b/samples/OCCTOverview/code/OcafSamples.cxx deleted file mode 100644 index 0154f48d35..0000000000 --- a/samples/OCCTOverview/code/OcafSamples.cxx +++ /dev/null @@ -1,629 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - - // 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 modified."; - 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(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - // 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 modified."; - 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_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_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_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(); -} diff --git a/samples/OCCTOverview/code/OcafSamples.h b/samples/OCCTOverview/code/OcafSamples.h deleted file mode 100644 index 96116efccf..0000000000 --- a/samples/OCCTOverview/code/OcafSamples.h +++ /dev/null @@ -1,81 +0,0 @@ -// 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 -#include -#include - -//! 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) - { - // - } - - 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: - - TCollection_AsciiString myFileName; - Handle(V3d_Viewer) myViewer; - Handle(TDocStd_Document) myOcafDoc; -}; - -#endif //OCAFSAMPLES_H diff --git a/samples/OCCTOverview/code/Sample2D_Face.cxx b/samples/OCCTOverview/code/Sample2D_Face.cxx deleted file mode 100644 index 462ec01f9a..0000000000 --- a/samples/OCCTOverview/code/Sample2D_Face.cxx +++ /dev/null @@ -1,486 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include -#include -#include - -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_PresentationManager)& , - 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_PresentationManager)& 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_PresentationManager)& 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); -} diff --git a/samples/OCCTOverview/code/Sample2D_Face.h b/samples/OCCTOverview/code/Sample2D_Face.h deleted file mode 100644 index 8222593f9a..0000000000 --- a/samples/OCCTOverview/code/Sample2D_Face.h +++ /dev/null @@ -1,108 +0,0 @@ -// 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 -#include -#include -#include -#include -#include - -//! 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_PresentationManager)& 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_PresentationManager)& thePrsMgr, - const SelectMgr_SequenceOfOwner& theOwners) Standard_OVERRIDE; - - //! Method for advanced customizable highlighting of picked object. - virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager)& 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 diff --git a/samples/OCCTOverview/code/Sample2D_Image.cxx b/samples/OCCTOverview/code/Sample2D_Image.cxx deleted file mode 100644 index e86f849365..0000000000 --- a/samples/OCCTOverview/code/Sample2D_Image.cxx +++ /dev/null @@ -1,86 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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_Texture2D) aTexture = new Graphic3d_Texture2D (myFilename); - aTexture->DisableModulate(); - myDrawer->ShadingAspect()->Aspect()->SetTextureMap (aTexture); - myDrawer->ShadingAspect()->Aspect()->SetTextureMapOn(); -} diff --git a/samples/OCCTOverview/code/Sample2D_Image.h b/samples/OCCTOverview/code/Sample2D_Image.h deleted file mode 100644 index c3b9a886b4..0000000000 --- a/samples/OCCTOverview/code/Sample2D_Image.h +++ /dev/null @@ -1,86 +0,0 @@ -// 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 -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//! 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 diff --git a/samples/OCCTOverview/code/Sample2D_Markers.cxx b/samples/OCCTOverview/code/Sample2D_Markers.cxx deleted file mode 100644 index a564bdcca7..0000000000 --- a/samples/OCCTOverview/code/Sample2D_Markers.cxx +++ /dev/null @@ -1,80 +0,0 @@ -// 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 - -// 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_PresentationManager)& , - 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); - } -} diff --git a/samples/OCCTOverview/code/Sample2D_Markers.h b/samples/OCCTOverview/code/Sample2D_Markers.h deleted file mode 100644 index f0252669f4..0000000000 --- a/samples/OCCTOverview/code/Sample2D_Markers.h +++ /dev/null @@ -1,89 +0,0 @@ -// 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 -#include -#include - -//! 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_PresentationManager)& /*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 diff --git a/samples/OCCTOverview/code/Samples.qrc b/samples/OCCTOverview/code/Samples.qrc deleted file mode 100644 index 5bc1783345..0000000000 --- a/samples/OCCTOverview/code/Samples.qrc +++ /dev/null @@ -1,11 +0,0 @@ - - - Geometry.xml - Topology.xml - Triangulation.xml - DataExchange.xml - Viewer3d.xml - Viewer2d.xml - Ocaf.xml - - diff --git a/samples/OCCTOverview/code/TOcafFunction_BoxDriver.cxx b/samples/OCCTOverview/code/TOcafFunction_BoxDriver.cxx deleted file mode 100644 index 6589efab1f..0000000000 --- a/samples/OCCTOverview/code/TOcafFunction_BoxDriver.cxx +++ /dev/null @@ -1,148 +0,0 @@ -// 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 -#include -#include -#include - -//======================================================================= -//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; -} diff --git a/samples/OCCTOverview/code/TOcafFunction_BoxDriver.h b/samples/OCCTOverview/code/TOcafFunction_BoxDriver.h deleted file mode 100644 index bbeed55506..0000000000 --- a/samples/OCCTOverview/code/TOcafFunction_BoxDriver.h +++ /dev/null @@ -1,57 +0,0 @@ -// 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 -#include - -//! 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 diff --git a/samples/OCCTOverview/code/TOcafFunction_CutDriver.cxx b/samples/OCCTOverview/code/TOcafFunction_CutDriver.cxx deleted file mode 100644 index cbbaca349b..0000000000 --- a/samples/OCCTOverview/code/TOcafFunction_CutDriver.cxx +++ /dev/null @@ -1,152 +0,0 @@ -// 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 -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -//======================================================================= -//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; -} diff --git a/samples/OCCTOverview/code/TOcafFunction_CutDriver.h b/samples/OCCTOverview/code/TOcafFunction_CutDriver.h deleted file mode 100644 index 9b25cecf95..0000000000 --- a/samples/OCCTOverview/code/TOcafFunction_CutDriver.h +++ /dev/null @@ -1,57 +0,0 @@ -// 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 -#include - -//! 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 diff --git a/samples/OCCTOverview/code/TOcafFunction_CylDriver.cxx b/samples/OCCTOverview/code/TOcafFunction_CylDriver.cxx deleted file mode 100644 index 3b687e5172..0000000000 --- a/samples/OCCTOverview/code/TOcafFunction_CylDriver.cxx +++ /dev/null @@ -1,147 +0,0 @@ -// 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 -#include -#include -#include -#include -#include - -//======================================================================= -//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; -} diff --git a/samples/OCCTOverview/code/TOcafFunction_CylDriver.h b/samples/OCCTOverview/code/TOcafFunction_CylDriver.h deleted file mode 100644 index e6d2534b71..0000000000 --- a/samples/OCCTOverview/code/TOcafFunction_CylDriver.h +++ /dev/null @@ -1,59 +0,0 @@ -// 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 -#include - -//! 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 diff --git a/samples/OCCTOverview/code/TOcaf_Application.cxx b/samples/OCCTOverview/code/TOcaf_Application.cxx deleted file mode 100644 index ceea5843f0..0000000000 --- a/samples/OCCTOverview/code/TOcaf_Application.cxx +++ /dev/null @@ -1,52 +0,0 @@ -// 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 -#include -#include -#include -#include - -#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()); -} diff --git a/samples/OCCTOverview/code/TOcaf_Application.h b/samples/OCCTOverview/code/TOcaf_Application.h deleted file mode 100644 index bcaaf03a06..0000000000 --- a/samples/OCCTOverview/code/TOcaf_Application.h +++ /dev/null @@ -1,37 +0,0 @@ -// 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 -#include - -//! Sample OCAF application -class TOcaf_Application : public TDocStd_Application -{ - DEFINE_STANDARD_RTTI_INLINE(TOcaf_Application, TDocStd_Application) -public: - - Standard_EXPORT TOcaf_Application(); -}; - -#endif diff --git a/samples/OCCTOverview/code/Topology.xml b/samples/OCCTOverview/code/Topology.xml deleted file mode 100644 index a49a69e84a..0000000000 --- a/samples/OCCTOverview/code/Topology.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/OCCTOverview/code/TopologySamples.cxx b/samples/OCCTOverview/code/TopologySamples.cxx deleted file mode 100644 index 65f0e38a2d..0000000000 --- a/samples/OCCTOverview/code/TopologySamples.cxx +++ /dev/null @@ -1,1884 +0,0 @@ -// 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 "TopologySamples.h" - -#include "AdaptorVec_AIS.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -void TopologySamples::ExecuteSample (const TCollection_AsciiString& theSampleName) -{ - Standard_Boolean anIsSamplePresent = Standard_True; - FindSourceCode(theSampleName); - if (theSampleName == "Vertex3dSample") - Vertex3dSample(); - else if (theSampleName == "Edge3dSample") - Edge3dSample(); - else if (theSampleName == "Face3dSample") - Face3dSample(); - else if (theSampleName == "Wire3dSample") - Wire3dSample(); - else if (theSampleName == "Shell3dSample") - Shell3dSample(); - else if (theSampleName == "Solid3dSample") - Solid3dSample(); - else if (theSampleName == "Edge2dSample") - Edge2dSample(); - else if (theSampleName == "Box3dSample") - Box3dSample(); - else if (theSampleName == "Cylinder3dSample") - Cylinder3dSample(); - else if (theSampleName == "Revolution3dSample") - Revolution3dSample(); - else if (theSampleName == "TopologyIterator3dSample") - TopologyIterator3dSample(); - else if (theSampleName == "TopologyExplorer3dSample") - TopologyExplorer3dSample(); - else if (theSampleName == "AssessToCurve3dSample") - AssessToCurve3dSample(); - else if (theSampleName == "AssessToCompositeCurve3dSample") - AssessToCompositeCurve3dSample(); - else if (theSampleName == "AssessToSurface3dSample") - AssessToSurface3dSample(); - else if (theSampleName == "Common3dSample") - Common3dSample(); - else if (theSampleName == "Cut3dSample") - Cut3dSample(); - else if (theSampleName == "Cut3dSample") - Cut3dSample(); - else if (theSampleName == "Fuse3dSample") - Fuse3dSample(); - else if (theSampleName == "Section3dSample") - Section3dSample(); - else if (theSampleName == "Splitter3dSample") - Splitter3dSample(); - else if (theSampleName == "Defeaturing3dSample") - Defeaturing3dSample(); - else if (theSampleName == "Fillet3dSample") - Fillet3dSample(); - else if (theSampleName == "Chamfer3dSample") - Chamfer3dSample(); - else if (theSampleName == "Offset3dSample") - Offset3dSample(); - else if (theSampleName == "Evolved3dSample") - Evolved3dSample(); - else if (theSampleName == "Copy3dSample") - Copy3dSample(); - else if (theSampleName == "Transform3dSample") - Transform3dSample(); - else if (theSampleName == "ConvertToNurbs3dSample") - ConvertToNurbs3dSample(); - else if (theSampleName == "SewContiguousFaces3dSample") - SewContiguousFaces3dSample(); - else if (theSampleName == "CheckValidity3dSample") - CheckValidity3dSample(); - else if (theSampleName == "ComputeLinearProperties3dSample") - ComputeLinearProperties3dSample(); - else if (theSampleName == "ComputeSurfaceProperties3dSample") - ComputeSurfaceProperties3dSample(); - else if (theSampleName == "ComputeVolumeProperties3dSample") - ComputeVolumeProperties3dSample(); - else - { - myResult << "No function found: " << theSampleName; - myCode += TCollection_AsciiString("No function found: ") + theSampleName; - anIsSamplePresent = Standard_False; - } - myIsProcessed = anIsSamplePresent; -} - -void TopologySamples::Vertex3dSample() -{ - // Make a vertex from a 3D point. - gp_Pnt aPnt(0.0, 0.0, 10.0); - TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(aPnt); - myResult << "TopoDS_Vertex was created at [ " - << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() - << " ]" << std::endl; - - Handle(AIS_Shape) aAisVertex = new AIS_Shape(aVertex); - Handle(AIS_TextLabel) anAisLabel = new AIS_TextLabel(); - Standard_SStream aSS; - aSS << "TopoDS_Vertex [" << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << "]" << std::endl; - anAisLabel->SetText(aSS.str().c_str()); - anAisLabel->SetPosition(aPnt); - myObject3d.Append(aAisVertex); - myObject3d.Append(anAisLabel); -} - -void TopologySamples::Edge3dSample() -{ - // Make an edge from two 3D points. - gp_Pnt aPnt1(0.0, 10.0, 0.0); - gp_Pnt aPnt2(10.0, 10.0, 0.0); - TopoDS_Edge anEdgeP12 = BRepBuilderAPI_MakeEdge(aPnt1, aPnt2); - myResult << "TopoDS_Edge between [ " - << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() - << " ] and [ " - << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() - << " ] was created in yellow" << std::endl - << std::endl; - - // Make an edge from a circular segment. - // Create a circle in XY plane of the radius 5.0. - gp_Circ aCirc(gp::XOY(), 5.0); - // Make a circular edge from the 1st quoter in the parametric space. - TopoDS_Edge anEdgeCirc = BRepBuilderAPI_MakeEdge(aCirc, 0.0, M_PI_2); - myResult << "TopoDS_Edge on the circle's 1st quoter" << std::endl - << "with the center at [ " - << aCirc.Location().X() << ", " << aCirc.Location().Y() << ", " << aCirc.Location().Z() - << " ] and R = " << aCirc.Radius() << " was created in red" << std::endl - << std::endl; - - // Make an edge from a 3D curve (BSpline). - // Define points. - gp_Pnt aPole1(0.0, 0.0, 10.0); - gp_Pnt aPole2(5.0, 5.0, 5.0); - gp_Pnt aPole3(10.0, 10.0, 15.0); - gp_Pnt aPole4(15.0, 5.0, 20.0); - // Add points to the curve poles array. - TColgp_Array1OfPnt aPoles(1, 4); - aPoles.SetValue(1, aPole1); - aPoles.SetValue(2, aPole2); - aPoles.SetValue(3, aPole3); - aPoles.SetValue(4, aPole4); - // Make a BSpline curve from the points array - Handle(Geom_BSplineCurve) aBSplineCurve = GeomAPI_PointsToBSpline(aPoles).Curve(); - // Make an edge between two point on the BSpline curve. - gp_Pnt aPntOnCurve1, aPntOnCurve2; - aBSplineCurve->D0 (0.75 * aBSplineCurve->FirstParameter() - + 0.25 * aBSplineCurve->LastParameter(), - aPntOnCurve1); - aBSplineCurve->D0 (0.25 * aBSplineCurve->FirstParameter() - + 0.75 * aBSplineCurve->LastParameter(), - aPntOnCurve2); - TopoDS_Edge anEdgeBSpline = BRepBuilderAPI_MakeEdge(aBSplineCurve, aPntOnCurve1, aPntOnCurve2); - myResult << "TopoDS_Edge on the BSpline curve" << std::endl - << "between [ " - << aPntOnCurve1.X() << ", " << aPntOnCurve1.Y() << ", " << aPntOnCurve1.Z() - << " ] and [ " - << aPntOnCurve2.X() << ", " << aPntOnCurve2.Y() << ", " << aPntOnCurve2.Z() - << " ]" << std::endl - << "was created in green" << std::endl; - - Handle(AIS_ColoredShape) anAisEdgeP12 = new AIS_ColoredShape(anEdgeP12); - Handle(AIS_ColoredShape) anAisEdgeCirc = new AIS_ColoredShape(anEdgeCirc); - Handle(AIS_ColoredShape) anAisEdgeBSpline = new AIS_ColoredShape(anEdgeBSpline); - anAisEdgeP12->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisEdgeCirc->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisEdgeBSpline->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisEdgeP12); - myObject3d.Append(anAisEdgeCirc); - myObject3d.Append(anAisEdgeBSpline); - Handle(AIS_TextLabel) anAisEdgeP12Label = new AIS_TextLabel(); - anAisEdgeP12Label->SetText("Edge between two points"); - anAisEdgeP12Label->SetPosition(0.5 * (aPnt1.XYZ() + aPnt2.XYZ())); - anAisEdgeP12Label->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - myObject3d.Append(anAisEdgeP12Label); - Handle(AIS_TextLabel) anAisEdgeCircLabel = new AIS_TextLabel(); - anAisEdgeCircLabel->SetText("Circular edge"); - anAisEdgeCircLabel->SetPosition(aCirc.Location()); - anAisEdgeCircLabel->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisEdgeCircLabel); - Handle(AIS_TextLabel) anAisEdgeBSplineLabel = new AIS_TextLabel(); - anAisEdgeBSplineLabel->SetText("BSpline edge"); - anAisEdgeBSplineLabel->SetPosition(aPole3); - anAisEdgeBSplineLabel->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisEdgeBSplineLabel); - TopoDS_Vertex anEdgeP12_V1, anEdgeP12_V2; - TopExp::Vertices(anEdgeP12, anEdgeP12_V1, anEdgeP12_V2); - myObject3d.Append(new AIS_Shape(anEdgeP12_V1)); - myObject3d.Append(new AIS_Shape(anEdgeP12_V2)); - TopoDS_Vertex anEdgeCirc_V1, anEdgeCirc_V2; - TopExp::Vertices(anEdgeCirc, anEdgeCirc_V1, anEdgeCirc_V2); - myObject3d.Append(new AIS_Shape(anEdgeCirc_V1)); - myObject3d.Append(new AIS_Shape(anEdgeCirc_V2)); - TopoDS_Vertex anEdgeBSpline_V1, anEdgeBSpline_V2; - TopExp::Vertices(anEdgeBSpline, anEdgeBSpline_V1, anEdgeBSpline_V2); - myObject3d.Append(new AIS_Shape(anEdgeBSpline_V1)); - myObject3d.Append(new AIS_Shape(anEdgeBSpline_V2)); -} - -void TopologySamples::Face3dSample() -{ - // Make a face from a sphere with the center - // at [0.0, 0.0, 10.0] and R = 5. - gp_Sphere aSphere(gp_Ax3(gp_Pnt(0.0, 0.0, 10.0), gp::DZ()), 5.0); - TopoDS_Face aFaceSphere = BRepBuilderAPI_MakeFace(aSphere); - myResult << "TopoDS_Face on the sphere with" << std::endl - << "the center at [ " - << aSphere.Location().X() << ", " << aSphere.Location().Y() << ", " << aSphere.Location().Z() - << " ] and R = " << aSphere.Radius() << " was created in yellow" << std::endl - << std::endl; - - // 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); - myResult << "TopoDS_Face on the rectangle was created in red" << std::endl - << std::endl; - - // Make a face from a BSpline surface. - // Define a 4x4 grid of points for BSpline surface. - TColgp_Array2OfPnt aPoints(1, 4, 1, 4); - for (Standard_Integer i = 1; i <= 4; ++i) - { - gp_Pnt aPnt; - aPnt.SetX(5.0 * i); - for (Standard_Integer j = 1; j <= 4; ++j) - { - aPnt.SetY(5.0 * j); - if (1 < i && i < 4 && 1 < j && j < 4) - { - aPnt.SetZ(15.0); - } - else - { - aPnt.SetZ(10.0); - } - aPoints.SetValue(i, j, aPnt); - } - } - // Make a BSpline surface from the points array. - Handle(Geom_BSplineSurface) aBSplineSurf = GeomAPI_PointsToBSplineSurface(aPoints).Surface(); - Standard_Real aU1, aU2, aV1, aV2; - aBSplineSurf->Bounds(aU1, aU2, aV1, aV2); - TopoDS_Face aFaceBSpline = BRepBuilderAPI_MakeFace(aBSplineSurf, aU1, aU2, aV1, aV2, Precision::Confusion()); - myResult << "TopoDS_Face on the BSpline surface was created in green" << std::endl << std::endl; - - Handle(AIS_ColoredShape) anAisFaceSphere = new AIS_ColoredShape(aFaceSphere); - Handle(AIS_ColoredShape) anAisFaceRect = new AIS_ColoredShape(aFaceRect); - Handle(AIS_ColoredShape) anAisFaceBSpline = new AIS_ColoredShape(aFaceBSpline); - anAisFaceSphere->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisFaceRect->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisFaceBSpline->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisFaceSphere); - myObject3d.Append(anAisFaceRect); - myObject3d.Append(anAisFaceBSpline); - Handle(AIS_TextLabel) anAisFaceSphereLabel = new AIS_TextLabel(); - anAisFaceSphereLabel->SetText("Spherical face"); - anAisFaceSphereLabel->SetPosition(aSphere.Location().XYZ() + aSphere.Radius() * gp::DZ().XYZ()); - anAisFaceSphereLabel->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - myObject3d.Append(anAisFaceSphereLabel); - Handle(AIS_TextLabel) anAisFaceRectLabel = new AIS_TextLabel(); - anAisFaceRectLabel->SetText("Flat rectangular face"); - anAisFaceRectLabel->SetPosition(aPln.Location().XYZ() + 2.5 * gp::DZ().XYZ()); - anAisFaceRectLabel->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisFaceRectLabel); - Handle(AIS_TextLabel) anAisFaceBSplineLabel = new AIS_TextLabel(); - anAisFaceBSplineLabel->SetText("BSpline face"); - anAisFaceBSplineLabel->SetPosition(aPoints(4, 4)); - anAisFaceBSplineLabel->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisFaceBSplineLabel); -} - -void TopologySamples::Wire3dSample() -{ - // Make a wire from edges created on a set of points. - // Add points to the curve poles array. - TColgp_Array1OfPnt aPoints(1, 4); - aPoints.SetValue(1, gp_Pnt(0.0, 0.0, 0.0)); - aPoints.SetValue(2, gp_Pnt(20.0, 0.0, 0.0)); - aPoints.SetValue(3, gp_Pnt(20.0, 10.0, 0.0)); - aPoints.SetValue(4, gp_Pnt(0.0, 10.0, 0.0)); - // A wire maker contains an empty wire. - BRepBuilderAPI_MakeWire aMakeWire; - for (Standard_Integer i = 1; i <= 4; ++i) - { - Standard_Integer i1 = i; - Standard_Integer i2 = i1 < 4 ? i1 + 1 : 1; - const gp_Pnt& aPnt1 = aPoints.Value(i1); - const gp_Pnt& aPnt2 = aPoints.Value(i2); - TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aPnt1, aPnt2); - // Add an edge to the wire under construction. - // The edge must be connectible to the wire under construction, and, - // unless it is the first edge of the wire, must satisfy the following - // condition: one of its vertices must be geometrically coincident - // with one of the vertices of the wire (provided that the highest - // tolerance factor is assigned to the two vertices). - // It could also be the same vertex. - // Warning - // If the edge is not connectible to the wire under construction it is not added. - // The function IsDone will return false and the function - // Wire will raise an error, until a new connectible edge is added. - aMakeWire.Add(anEdge); - Standard_ASSERT_VOID(aMakeWire.IsDone(), "Added edge isn't connectible!"); - } - // Retrieve a constructed wire. - TopoDS_Wire aWire = aMakeWire.Wire(); - myResult << "TopoDS_Wire was created. Vertices :" << std::endl; - // Retrieve wire vertices. 4 vertices are expected, because of - // edges connecting during wire constructing. - TopTools_IndexedMapOfShape aVertices; - TopExp::MapShapes(aWire, TopAbs_VERTEX, aVertices); - for (TopTools_IndexedMapOfShape::Iterator anIt(aVertices); anIt.More(); anIt.Next()) - { - TopoDS_Vertex aVertex = TopoDS::Vertex(anIt.Value()); - gp_Pnt aPnt = BRep_Tool::Pnt(aVertex); - myResult << "[ " << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl; - Handle(AIS_Shape) anAisVertex = new AIS_Shape(aVertex); - myObject3d.Append(anAisVertex); - } - - Handle(AIS_Shape) anAisWire = new AIS_Shape(aWire); - myObject3d.Append(anAisWire); -} - -void TopologySamples::Shell3dSample() -{ - // Make a shell from a cylinder with R = 5 and directed along Z axis - gp_Cylinder aCyl(gp::XOY(), 5.0); - Handle(Geom_Surface) aCylSurf = new Geom_CylindricalSurface(aCyl); - TopoDS_Shell aCylShell = BRepBuilderAPI_MakeShell(aCylSurf, 0.0, 2.0 * M_PI, -10.0, +10.0); - myResult << "TopoDS_Shell on the cylinder R = " << aCyl.Radius() << std::endl - << "with axis [ " - << aCyl.Position().Direction().X() << ", " - << aCyl.Position().Direction().Y() << ", " - << aCyl.Position().Direction().Z() << " ]" << std::endl - << "limited in length [-10 ... +10] was created" << std::endl; - - Handle(AIS_Shape) anAisShell = new AIS_Shape(aCylShell); - myObject3d.Append(anAisShell); -} - -void TopologySamples::Solid3dSample() -{ - // Make a torus from a shell. - gp_Torus aTorus(gp::XOY(), 20.0, 7.5); - Handle(Geom_Surface) aTorusSurf = new Geom_ToroidalSurface(aTorus); - TopoDS_Shell aTorusShell = BRepBuilderAPI_MakeShell(aTorusSurf, 0.0, 2.0 * M_PI, 0.0, 2.0 * M_PI); - // Make a solid on the torus shell. - TopoDS_Solid aTorusSolid = BRepBuilderAPI_MakeSolid(aTorusShell); - myResult << "TopoDS_Solid on the torus with" << std::endl - << "R major = " << aTorus.MajorRadius() << std::endl - << "R minor = " << aTorus.MinorRadius() << std::endl - << "was created" << std::endl; - - Handle(AIS_Shape) anAisSolid = new AIS_Shape(aTorusSolid); - myObject3d.Append(anAisSolid); -} - -void TopologySamples::Edge2dSample() -{ - // Make an edge from two 2D points. - gp_Pnt2d aPnt1(0.0, 10.0); - gp_Pnt2d aPnt2(10.0, 10.0); - TopoDS_Edge anEdgeP12 = BRepBuilderAPI_MakeEdge2d(aPnt1, aPnt2); - myResult << "TopoDS_Edge between [ " - << aPnt1.X() << ", " << aPnt1.Y() << " ] and [ " - << aPnt2.X() << ", " << aPnt2.Y() << " ] was created in yellow" << std::endl - << std::endl; - - // Make an edge from a circular segment. - // Create a circle of the radius 5.0. - gp_Circ2d aCirc(gp::OX2d(), 5.0); - // Make a circular edge from the 1st quoter in the parametric space. - TopoDS_Edge anEdgeCirc = BRepBuilderAPI_MakeEdge2d(aCirc, 0.0, M_PI_2); - myResult << "TopoDS_Edge on the 2D circle's 1st quoter" << std::endl - << "with the center at [ " << aCirc.Location().X() << ", " << aCirc.Location().Y() - << " ] and R = " << aCirc.Radius() << " was created in red" << std::endl - << std::endl; - - // Make an edge from a 2D curve (BSpline). - // Define points. - gp_Pnt2d aPole1(0.0, 0.0); - gp_Pnt2d aPole2(5.0, 5.0); - gp_Pnt2d aPole3(10.0, 10.0); - gp_Pnt2d aPole4(15.0, 5.0); - // Add points to the curve poles array. - TColgp_Array1OfPnt2d aPoles(1, 4); - aPoles.SetValue(1, aPole1); - aPoles.SetValue(2, aPole2); - aPoles.SetValue(3, aPole3); - aPoles.SetValue(4, aPole4); - // Make a BSpline curve from the points array - Handle(Geom2d_BSplineCurve) aBSplineCurve = Geom2dAPI_PointsToBSpline(aPoles).Curve(); - // Make an edge between two point on the BSpline curve. - gp_Pnt2d aPntOnCurve1, aPntOnCurve2; - aBSplineCurve->D0 (0.75 * aBSplineCurve->FirstParameter() - + 0.25 * aBSplineCurve->LastParameter(), - aPntOnCurve1); - aBSplineCurve->D0 (0.25 * aBSplineCurve->FirstParameter() - + 0.75 * aBSplineCurve->LastParameter(), - aPntOnCurve2); - TopoDS_Edge anEdgeBSpline = BRepBuilderAPI_MakeEdge2d(aBSplineCurve, aPntOnCurve1, aPntOnCurve2); - myResult << "TopoDS_Edge on the 2D BSpline curve" << std::endl - << "between [ " << aPntOnCurve1.X() << ", " << aPntOnCurve1.Y() - << " ] and [ " << aPntOnCurve2.X() << ", " << aPntOnCurve2.Y() << " ]" << std::endl - << "was created in green" << std::endl; - - Handle(AIS_ColoredShape) anAisEdgeP12 = new AIS_ColoredShape(anEdgeP12); - Handle(AIS_ColoredShape) anAisEdgeCirc = new AIS_ColoredShape(anEdgeCirc); - Handle(AIS_ColoredShape) anAisEdgeBSpline = new AIS_ColoredShape(anEdgeBSpline); - anAisEdgeP12->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisEdgeCirc->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisEdgeBSpline->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject2d.Append(anAisEdgeP12); - myObject2d.Append(anAisEdgeCirc); - myObject2d.Append(anAisEdgeBSpline); - Handle(AIS_TextLabel) anAisEdgeP12Label = new AIS_TextLabel(); - anAisEdgeP12Label->SetText("Edge between two 2d points"); - anAisEdgeP12Label->SetPosition(0.5 * (gp_XYZ(aPnt1.X(), aPnt1.Y() + 0.5, 0.0) + gp_XYZ(aPnt2.X(), aPnt2.Y() + 0.5, 0.0))); - anAisEdgeP12Label->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - myObject2d.Append(anAisEdgeP12Label); - Handle(AIS_TextLabel) anAisEdgeCircLabel = new AIS_TextLabel(); - anAisEdgeCircLabel->SetText("Circular edge"); - anAisEdgeCircLabel->SetPosition(gp_XYZ(aCirc.Location().X(), aCirc.Location().Y() + 0.5, 0.0)); - anAisEdgeCircLabel->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject2d.Append(anAisEdgeCircLabel); - Handle(AIS_TextLabel) anAisEdgeBSplineLabel = new AIS_TextLabel(); - anAisEdgeBSplineLabel->SetText("BSpline edge"); - anAisEdgeBSplineLabel->SetPosition(gp_XYZ(aPole3.X(), aPole3.Y() + 0.5, 0.0)); - anAisEdgeBSplineLabel->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject2d.Append(anAisEdgeBSplineLabel); - TopoDS_Vertex anEdgeP12_V1, anEdgeP12_V2; - TopExp::Vertices(anEdgeP12, anEdgeP12_V1, anEdgeP12_V2); - myObject2d.Append(new AIS_Shape(anEdgeP12_V1)); - myObject2d.Append(new AIS_Shape(anEdgeP12_V2)); - TopoDS_Vertex anEdgeCirc_V1, anEdgeCirc_V2; - TopExp::Vertices(anEdgeCirc, anEdgeCirc_V1, anEdgeCirc_V2); - myObject2d.Append(new AIS_Shape(anEdgeCirc_V1)); - myObject2d.Append(new AIS_Shape(anEdgeCirc_V2)); - TopoDS_Vertex anEdgeBSpline_V1, anEdgeBSpline_V2; - TopExp::Vertices(anEdgeBSpline, anEdgeBSpline_V1, anEdgeBSpline_V2); - myObject2d.Append(new AIS_Shape(anEdgeBSpline_V1)); - myObject2d.Append(new AIS_Shape(anEdgeBSpline_V2)); -} - -void TopologySamples::Box3dSample() -{ - // Make a box with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 5.0; - Standard_Real aSizeY = 10.0; - Standard_Real aSizeZ = 15.0; - TopoDS_Shape aBox1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow" << std::endl; - - // Make a box by two points. - gp_Pnt aPnt1(10.0, 0.0, 0.0); - gp_Pnt aPnt2(20.0, 10.0, 15.0); - TopoDS_Shape aBox2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2); - myResult << "Box with corners [" - << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() - << "] and [" - << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() - << "] was created in red" << std::endl; - - Handle(AIS_ColoredShape) anAisBox1 = new AIS_ColoredShape(aBox1); - Handle(AIS_ColoredShape) anAisBox2 = new AIS_ColoredShape(aBox2); - anAisBox1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisBox2->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisBox1); - myObject3d.Append(anAisBox2); -} - -void TopologySamples::Cylinder3dSample() -{ - // Make a cylinder of the specified radius and length. - Standard_Real aRadius1 = 5.0; - Standard_Real aLength1 = 15.0; - TopoDS_Shape aCyl1 = BRepPrimAPI_MakeCylinder(aRadius1, aLength1); - myResult << "Cylinder with Radius = " << aRadius1 - << " and Length = " << aLength1 - << " was created in yellow" << std::endl; - - // Make a cylinder of the specified radius, length and sector angle. - Standard_Real aRadius2 = 8.0; - Standard_Real aLength2 = 25.0; - Standard_Real anAngle = M_PI_2; - TopoDS_Shape aCyl2 = BRepPrimAPI_MakeCylinder(aRadius2, aLength2, anAngle); - myResult << "Cylinder with Radius = " << aRadius2 - << " , Length = " << aLength2 - << " and Angle = " << anAngle - << " was created in red" << std::endl; - - Handle(AIS_ColoredShape) anAisCyl1 = new AIS_ColoredShape(aCyl1); - Handle(AIS_ColoredShape) anAisCyl2 = new AIS_ColoredShape(aCyl2); - anAisCyl1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisCyl2->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisCyl1); - myObject3d.Append(anAisCyl2); -} - -void TopologySamples::Revolution3dSample() -{ - // Make a toroidal face by a series of shape revolves. - // Make a starting vertex at [-1.0, 0, 0]. - TopoDS_Shape aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(-1.0, 0.0, 0.0)); - - // Make a circular edge by revolting aVertex around - // an axis Y positioned at [-1.5, 0.0, 0.0] on 2*Pi angle - gp_Ax1 anAxis1(gp_Pnt(-1.5, 0.0, 0.0), gp::DY()); - TopoDS_Shape anEdge = BRepPrimAPI_MakeRevol(aVertex, anAxis1); - myResult << "Circular edge was created in yellow" << std::endl; - - // Make a toroidal face by revolting anEdge around - // Z axis on 2*Pi angle. - TopoDS_Shape aFace = BRepPrimAPI_MakeRevol(anEdge, gp::OZ()); - myResult << "Toroidal face was created in red" << std::endl; - - Handle(AIS_Axis) anAisAxis1 = new AIS_Axis(new Geom_Axis1Placement(anAxis1)); - Handle(AIS_Axis) anAisAxis2 = new AIS_Axis(new Geom_Axis1Placement(gp::OZ())); - Handle(AIS_Shape) anAisVertex = new AIS_Shape(aVertex); - Handle(AIS_ColoredShape) anAisEdge = new AIS_ColoredShape(anEdge); - Handle(AIS_ColoredShape) anAisFace = new AIS_ColoredShape(aFace); - anAisEdge->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - anAisEdge->SetWidth(1.5); - anAisAxis1->SetColor(Quantity_NOC_GREEN); - anAisFace->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisAxis2->SetColor(Quantity_NOC_RED); - myObject3d.Append(anAisVertex); - myObject3d.Append(anAisEdge); - myObject3d.Append(anAisFace); -} - -void TopologySamples::TopologyIterator3dSample() -{ - // Make a compound shape. - TopoDS_Compound aComp; - BRep_Builder aBuilder; - aBuilder.MakeCompound(aComp); - // Add shapes to the compound. - aBuilder.Add(aComp, BRepBuilderAPI_MakeVertex(gp::Origin())); - aBuilder.Add(aComp, BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 0.0, 0.0), gp_Pnt(10.0, 0.0, 0.0))); - aBuilder.Add(aComp, BRepBuilderAPI_MakeFace(gp_Sphere(gp::XOY(), 10.0))); - aBuilder.Add(aComp, BRepBuilderAPI_MakeWire( - BRepBuilderAPI_MakeEdge(gp_Pnt(15.0, 0.0, 0.0), gp_Pnt(20.0, 0.0, 0.0)), - BRepBuilderAPI_MakeEdge(gp_Pnt(20.0, 0.0, 0.0), gp_Pnt(25.0, 10.0, 5.0)) - )); - aBuilder.Add(aComp, BRepPrimAPI_MakeBox(5.0, 6.0, 7.0).Shell()); - aBuilder.Add(aComp, BRepPrimAPI_MakeBox(5.0, 6.0, 7.0).Solid()); - TopoDS_Compound aComp1; - aBuilder.MakeCompound(aComp1); - aBuilder.Add(aComp, aComp1); - - // Iterate over compound components. - myResult << "Compound components:" << std::endl; - Standard_Integer anI = 1; - for (TopoDS_Iterator anIt(aComp); anIt.More(); anIt.Next(), ++anI) - { - const TopoDS_Shape& aShape = anIt.Value(); - myResult << "#" << anI << " : "; - Handle(AIS_ColoredShape) anAisShape; - switch (aShape.ShapeType()) - { - case TopAbs_VERTEX: - myResult << "TopAbs_VERTEX"; - anAisShape = new AIS_ColoredShape(aShape); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - break; - case TopAbs_EDGE: - anAisShape = new AIS_ColoredShape(aShape); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myResult << "TopAbs_EDGE"; - break; - case TopAbs_WIRE: - myResult << "TopAbs_WIRE"; - break; - case TopAbs_FACE: - anAisShape = new AIS_ColoredShape(aShape); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); - myResult << "TopAbs_FACE"; - break; - case TopAbs_SHELL: - myResult << "TopAbs_SHELL"; - break; - case TopAbs_SOLID: - myResult << "TopAbs_SOLID"; - break; - case TopAbs_COMPOUND: - myResult << "TopAbs_COMPOUND"; - break; - case TopAbs_COMPSOLID: - myResult << "TopAbs_COMPSOLID"; - break; - case TopAbs_SHAPE: - myResult << "TopAbs_SHAPE"; - break; - } - myResult << std::endl; - if (anAisShape) - { - myObject3d.Append(anAisShape); - } - } -} - -void TopologySamples::TopologyExplorer3dSample() -{ - // Make a box with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 5.0; - Standard_Real aSizeY = 10.0; - Standard_Real aSizeZ = 15.0; - TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); - - // Explore vertex references. - myResult << "Vertex refs. : "; - Standard_Integer nbVertices = 0; - for (TopExp_Explorer anExp(aBox, TopAbs_VERTEX); anExp.More(); anExp.Next(), ++nbVertices) - { - const TopoDS_Shape& aShape = anExp.Current(); - Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - myObject3d.Append(anAisShape); - } - myResult << nbVertices << std::endl; - - // Explore edge references. - myResult << "Edge refs. : "; - Standard_Integer nbEdges = 0; - for (TopExp_Explorer anExp(aBox, TopAbs_EDGE); anExp.More(); anExp.Next(), ++nbEdges) - { - const TopoDS_Shape& aShape = anExp.Current(); - Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - anAisShape->SetWidth(2.5); - myObject3d.Append(anAisShape); - } - myResult << nbEdges << std::endl; - - // Explore face references. - myResult << "Face refs. : "; - Standard_Integer nbFaces = 0; - for (TopExp_Explorer anExp(aBox, TopAbs_FACE); anExp.More(); anExp.Next(), ++nbFaces) - { - const TopoDS_Shape& aShape = anExp.Current(); - Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - anAisShape->SetWidth(2.5); - myObject3d.Append(anAisShape); - } - myResult << nbFaces << std::endl; - - // Explore shell references. - myResult << "Wire refs. : "; - Standard_Integer nbWires = 0; - for (TopExp_Explorer anExp(aBox, TopAbs_WIRE); anExp.More(); anExp.Next(), ++nbWires) - { - } - myResult << nbWires << std::endl; - - // Explore shell references. - myResult << "Shell refs. : "; - Standard_Integer nbShells = 0; - for (TopExp_Explorer anExp(aBox, TopAbs_SHELL); anExp.More(); anExp.Next(), ++nbShells) - { - } - myResult << nbShells << std::endl; - - // Explore solid references. - myResult << "Solid refs. : "; - Standard_Integer nbSolids = 0; - for (TopExp_Explorer anExp(aBox, TopAbs_SOLID); anExp.More(); anExp.Next(), ++nbSolids) - { - } - myResult << nbSolids << std::endl; -} - -void TopologySamples::AssessToCurve3dSample() -{ - // Make a face from a sphere. - gp_Sphere aSphere(gp::XOY(), 1.0); - TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aSphere); - myResult << "TopoDS_Face on the sphere with" << std::endl - << "the center at [ " - << aSphere.Location().X() << ", " << aSphere.Location().Y() << ", " << aSphere.Location().Z() - << " ] and R = " << aSphere.Radius() << " was created in yellow" << std::endl - << std::endl; - - Handle(AIS_ColoredShape) anAisFace = new AIS_ColoredShape(aFace); - anAisFace->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - myObject3d.Append(anAisFace); - - // Retrieve the first not degenerated edge. - TopoDS_Edge aCurveEdge; - for (TopExp_Explorer anExp(aFace, TopAbs_EDGE); anExp.More(); anExp.Next()) - { - TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current()); - if (!BRep_Tool::Degenerated(anEdge)) - { - aCurveEdge = anEdge; - break; - } - } - if (!aCurveEdge.IsNull()) - { - // Make a curve on edge adaptor. - BRepAdaptor_Curve aCurveAdaptor(aCurveEdge); - myResult << "Curve adaptor for edge was built in red" << std::endl; - - Handle(AIS_ColoredShape) anAisCurveEdge = new AIS_ColoredShape(aCurveEdge); - anAisCurveEdge->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisCurveEdge->SetWidth(1.5); - myObject3d.Append(anAisCurveEdge); - - // Use the curve adaptor for some calculations, e.g. compute - // a set of points using GCPnts_QuasiUniformDeflection algo. - Standard_Real aDeflection = 0.1; - GCPnts_QuasiUniformDeflection anAlgo(aCurveAdaptor, aDeflection); - Standard_ASSERT_VOID(anAlgo.IsDone(), "Success is expected!"); - myResult << "Distribution of point on the curve with " << aDeflection - << " deflection was performed:" << std::endl; - for (Standard_Integer i = 1; i <= anAlgo.NbPoints(); ++i) - { - gp_Pnt aPnt = anAlgo.Value(i); - myResult << "Point #" << i << " : [ " - << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl; - Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt)); - myObject3d.Append(anAisPnt); - } - } -} - -void TopologySamples::AssessToCompositeCurve3dSample() -{ - // Make a wire containing two BSpline curves. - // Define points. - gp_Pnt aPole1(0.0, 0.0, 10.0); - gp_Pnt aPole2(5.0, 5.0, 5.0); - gp_Pnt aPole3(10.0, 10.0, 15.0); - gp_Pnt aPole4(15.0, 5.0, 20.0); - gp_Pnt aPole5(25.0, 15.0, 20.0); - gp_Pnt aPole6(35.0, 15.0, 15.0); - gp_Pnt aPole7(45.0, 25.0, 10.0); - // Add points to the curve poles array. - TColgp_Array1OfPnt aPoles1(1, 4), aPoles2(1, 4); - aPoles1.SetValue(1, aPole1); - aPoles1.SetValue(2, aPole2); - aPoles1.SetValue(3, aPole3); - aPoles1.SetValue(4, aPole4); - aPoles2.SetValue(1, aPole4); - aPoles2.SetValue(2, aPole5); - aPoles2.SetValue(3, aPole6); - aPoles2.SetValue(4, aPole7); - // Make a BSpline curves from the point arrays - Handle(Geom_BSplineCurve) aBSplineCurve1 = GeomAPI_PointsToBSpline(aPoles1).Curve(); - Handle(Geom_BSplineCurve) aBSplineCurve2 = GeomAPI_PointsToBSpline(aPoles2).Curve(); - // Make edges - TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aBSplineCurve1); - TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(aBSplineCurve2); - // Make a wire - BRepBuilderAPI_MakeWire aMakeWire; - aMakeWire.Add(anEdge1); - aMakeWire.Add(anEdge2); - Standard_ASSERT_VOID(aMakeWire.IsDone(), "Added edge isn't connectible!"); - TopoDS_Wire aWire = aMakeWire.Wire(); - myResult << "Wire of two BSpline curves was created" << std::endl; - - Handle(AIS_ColoredShape) anAisWire = new AIS_ColoredShape(aWire); - myObject3d.Append(anAisWire); - - // Make an adaptor. - BRepAdaptor_CompCurve aCurveAdaptor(aWire); - - // Use the curve adaptor for some calculations, e.g. compute - // a set of points using GCPnts_QuasiUniformDeflection algo. - Standard_Real aDeflection = 0.5; - GCPnts_QuasiUniformDeflection anAlgo(aCurveAdaptor, aDeflection); - Standard_ASSERT_VOID(anAlgo.IsDone(), "Success is expected!"); - myResult << "Distribution of point on the curve with " << aDeflection - << " deflection was performed:" << std::endl; - for (Standard_Integer i = 1; i <= anAlgo.NbPoints(); ++i) - { - gp_Pnt aPnt = anAlgo.Value(i); - myResult << "Point #" << i << " : [ " - << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl; - Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt)); - myObject3d.Append(anAisPnt); - } -} - -void TopologySamples::AssessToSurface3dSample() -{ - // Make a face from a sphere. - gp_Sphere aSphere(gp::XOY(), 4.0); - TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aSphere); - myResult << "TopoDS_Face on the sphere with" << std::endl - << "the center at [ " - << aSphere.Location().X() << ", " << aSphere.Location().Y() << ", " << aSphere.Location().Z() - << " ] and R = " << aSphere.Radius() << " was created in yellow" << std::endl - << std::endl; - - // Make a surface adaptor. - BRepAdaptor_Surface aSurfAdaptor(aFace); - - // Use the surface adaptor for some calculations, e.g. compute - // a normal vector at a surface point. - Standard_Real anU = 0.0, aV = 0.0; - gp_Pnt aPnt; - gp_Vec aDU, aDV; - aSurfAdaptor.D1(anU, aV, aPnt, aDU, aDV); - gp_Vec aNorm = aDU.Crossed(aDV); - Standard_ASSERT_VOID(aNorm.Magnitude() > Precision::Confusion(), "Non zero vector is expected!"); - aNorm.Normalize(); - myResult << "Normal vector at ( " << anU << ", " << aV << " )" << std::endl - << " = " << aNorm.X() << ", " << aNorm.Y() << ", " << aNorm.Z() << " ] is in red" << std::endl; - - Handle(AIS_ColoredShape) anAisFace = new AIS_ColoredShape(aFace); - anAisFace->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt)); - Handle(AIS_ColoredShape) anAisNorm = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aPnt, aPnt.XYZ() + aNorm.XYZ())); - myObject3d.Append(anAisFace); - myObject3d.Append(anAisNorm); - myObject3d.Append(anAisPnt); -} - -void TopologySamples::Common3dSample() -{ - // Make a box #1 with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 10.0; - Standard_Real aSizeY = 15.0; - Standard_Real aSizeZ = 20.0; - TopoDS_Shape aShape1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow wireframe" << std::endl; - - // Make a box #2 by two points. - gp_Pnt aPnt1(5.0, 7.5, 10.0); - gp_Pnt aPnt2(20.0, 25.0, 30.0); - TopoDS_Shape aShape2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2); - myResult << "Box with corners [" - << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() - << "] and [" - << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() - << "] was created in green wirefreme" << std::endl; - - // Create a boolean algo. - BRepAlgoAPI_Common anAlgo(aShape1, aShape2); - - // Make operation. - anAlgo.Build(); - - if (!anAlgo.IsDone()) // Process errors - { - myResult << "Errors : " << std::endl; - anAlgo.DumpErrors(myResult); - } - if (anAlgo.HasWarnings()) // Process warnings - { - myResult << "Warnings : " << std::endl; - anAlgo.DumpErrors(myResult); - } - - if (anAlgo.IsDone()) - { - // Get result. - TopoDS_Shape aResultShape = anAlgo.Shape(); - myResult << "Result shape was created in red shading" << std::endl; - - Handle(AIS_ColoredShape) anAisShape1 = new AIS_ColoredShape(aShape1); - Handle(AIS_ColoredShape) anAisShape2 = new AIS_ColoredShape(aShape2); - anAisShape1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisShape2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape); - anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisShape1); - myObject3d.Append(anAisShape2); - myObject3d.Append(anAisResult); - myContext->SetDisplayMode(anAisShape1, 0, Standard_True); - myContext->SetDisplayMode(anAisShape2, 0, Standard_True); - myContext->SetDisplayMode(anAisResult, 1, Standard_True); - } -} - -void TopologySamples::Cut3dSample() -{ - // Make a box #1 with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 10.0; - Standard_Real aSizeY = 15.0; - Standard_Real aSizeZ = 20.0; - TopoDS_Shape aShape1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow wireframe" << std::endl; - - // Make a box #2 by two points as a cutting tool. - gp_Pnt aPnt1(5.0, 7.5, 10.0); - gp_Pnt aPnt2(20.0, 25.0, 30.0); - TopoDS_Shape aShape2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2); - myResult << "Box with corners [" - << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() - << "] and [" - << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() - << "] was created in green wireframe" << std::endl; - - // Create a boolean algo. - BRepAlgoAPI_Cut anAlgo(aShape1, aShape2); - - // Make operation. - anAlgo.Build(); - - if (!anAlgo.IsDone()) // Process errors - { - myResult << "Errors : " << std::endl; - anAlgo.DumpErrors(myResult); - } - if (anAlgo.HasWarnings()) // Process warnings - { - myResult << "Warnings : " << std::endl; - anAlgo.DumpErrors(myResult); - } - - if (anAlgo.IsDone()) - { - // Get result. - TopoDS_Shape aResultShape = anAlgo.Shape(); - myResult << "Result shape was created in red shading" << std::endl; - Handle(AIS_ColoredShape) anAisShape1 = new AIS_ColoredShape(aShape1); - Handle(AIS_ColoredShape) anAisShape2 = new AIS_ColoredShape(aShape2); - anAisShape1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisShape2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape); - anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisShape1); - myObject3d.Append(anAisShape2); - myObject3d.Append(anAisResult); - myContext->SetDisplayMode(anAisShape1, 0, Standard_True); - myContext->SetDisplayMode(anAisShape2, 0, Standard_True); - myContext->SetDisplayMode(anAisResult, 1, Standard_True); - } -} - -void TopologySamples::Fuse3dSample() -{ - // Make a box #1 with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 10.0; - Standard_Real aSizeY = 15.0; - Standard_Real aSizeZ = 20.0; - TopoDS_Shape aShape1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow wireframe" << std::endl; - - // Make a box #2 by two points. - gp_Pnt aPnt1(5.0, 7.5, 10.0); - gp_Pnt aPnt2(20.0, 25.0, 30.0); - TopoDS_Shape aShape2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2); - myResult << "Box with corners [" - << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() - << "] and [" - << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() - << "] was created in green wireframe" << std::endl; - - // Create a boolean algo. - BRepAlgoAPI_Fuse anAlgo(aShape1, aShape2); - - // Make operation. - anAlgo.Build(); - - if (!anAlgo.IsDone()) // Process errors - { - myResult << "Errors : " << std::endl; - anAlgo.DumpErrors(myResult); - } - if (anAlgo.HasWarnings()) // Process warnings - { - myResult << "Warnings : " << std::endl; - anAlgo.DumpErrors(myResult); - } - - if (anAlgo.IsDone()) - { - // Get result. - TopoDS_Shape aResultShape = anAlgo.Shape(); - myResult << "Result shape was created in red shading" << std::endl; - Handle(AIS_ColoredShape) anAisShape1 = new AIS_ColoredShape(aShape1); - Handle(AIS_ColoredShape) anAisShape2 = new AIS_ColoredShape(aShape2); - anAisShape1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisShape2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape); - anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisShape1); - myObject3d.Append(anAisShape2); - myObject3d.Append(anAisResult); - myContext->SetDisplayMode(anAisShape1, 0, Standard_True); - myContext->SetDisplayMode(anAisShape2, 0, Standard_True); - myContext->SetDisplayMode(anAisResult, 1, Standard_True); - } -} - -void TopologySamples::Section3dSample() -{ - // Make a box #1 with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 10.0; - Standard_Real aSizeY = 15.0; - Standard_Real aSizeZ = 20.0; - TopoDS_Shape aShape = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow wireframe" << std::endl; - - // Create a boolean algo. - // Make a section by a plane. - gp_Pln aPln(gp_Pnt(aSizeX / 2.0, aSizeY / 2.0, aSizeZ / 2.0), gp::DZ()); - BRepAlgoAPI_Section anAlgo(aShape, aPln, Standard_False); - - // Make operation. - anAlgo.Build(); - - if (!anAlgo.IsDone()) // Process errors - { - myResult << "Errors : " << std::endl; - anAlgo.DumpErrors(myResult); - } - if (anAlgo.HasWarnings()) // Process warnings - { - myResult << "Warnings : " << std::endl; - anAlgo.DumpErrors(myResult); - } - - if (anAlgo.IsDone()) - { - // Get result. - TopoDS_Shape aResultShape = anAlgo.Shape(); - myResult << "Result shape was created in red" << std::endl; - Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); - Handle(AIS_Plane) anAisPlane = new AIS_Plane(new Geom_Plane(aPln)); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape); - anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisShape); - myObject3d.Append(anAisPlane); - myObject3d.Append(anAisResult); - myContext->SetDisplayMode(anAisShape, 0, Standard_True); - } -} - -void TopologySamples::Splitter3dSample() -{ - // Make a box by two points. - gp_Pnt aPnt1(-5.0, -7.5, -10.0); - gp_Pnt aPnt2(10.0, 15.0, 10.0); - TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aPnt1, aPnt2); - myResult << "Box with corners [" - << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() - << "] and [" - << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() - << "] was created in yellow" << std::endl; - - // Make a splitting tool as XY plane. - TopoDS_Shape aTool = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY())); - - // Create a splitter algo. - BRepAlgoAPI_Splitter aSplitter; - - // Add shapes to be split. - TopTools_ListOfShape anArguments; - anArguments.Append(aBox); - aSplitter.SetArguments(anArguments); - - // Add tool shapes. - TopTools_ListOfShape aTools; - aTools.Append(aTool); - aSplitter.SetTools(aTools); - - // Perform splitting. - aSplitter.Build(); - - if (!aSplitter.IsDone()) // Process errors - { - myResult << "Errors : " << std::endl; - aSplitter.DumpErrors(myResult); - } - if (aSplitter.HasWarnings()) // Process warnings - { - myResult << "Warnings : " << std::endl; - aSplitter.DumpErrors(myResult); - } - - Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); - anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - myObject3d.Append(anAisBox); - - if (aSplitter.IsDone()) // Process results - { - // Simplification of the result shape is performed by the means of - // ShapeUpgrade_UnifySameDomain algorithm. The result of the operation will - // be overwritten with the simplified result. - // The simplification is performed without creation of the Internal shapes, - // i.e. shapes connections will never be broken. - // Simplification is performed on the whole result shape. Thus, if the input - // shapes contained connected tangent edges or faces unmodified during the operation - // they will also be unified. - aSplitter.SimplifyResult(); - - // Get result of splitting. - TopoDS_Shape aResult = aSplitter.Shape(); - myResult << "Splitting result (shapes are moved apart for illustativeness) is in red" << std::endl; - - // In this particular sample two shapes in the result are expected. - // Lets move apart them for illustrative purposes. - TopoDS_Iterator anIt(aResult); - Standard_ASSERT_VOID(anIt.More(), "Not empty result is expected!"); - TopoDS_Shape aBox1 = anIt.Value(); anIt.Next(); - Standard_ASSERT_VOID(anIt.More(), "Two shapes in the result are expected!"); - TopoDS_Shape aBox2 = anIt.Value(); - gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(0.0, 0.0, -15.0)); - aBox1.Move(aTrsf1); - gp_Trsf aTrsf2; aTrsf2.SetTranslation(gp_Vec(0.0, 0.0, +15.0)); - aBox2.Move(aTrsf2); - - Handle(AIS_ColoredShape) anAisBox1 = new AIS_ColoredShape(aBox1); - Handle(AIS_ColoredShape) anAisBox2 = new AIS_ColoredShape(aBox2); - anAisBox1->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisBox2->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisBox1); - myObject3d.Append(anAisBox2); - } -} - -void TopologySamples::Defeaturing3dSample() -{ - // Prepare a box with a chamfer. - // Make a box with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 8.0; - Standard_Real aSizeY = 10.0; - Standard_Real aSizeZ = 15.0; - TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); - // Initialize chamfer algo. - BRepFilletAPI_MakeChamfer anAlgo(aBox); - // Set edge to apply a chamfer with specified distance from it. - // Select the 5th edge in the map returned by TopExp::MapShapes method. - TopTools_IndexedMapOfShape anEdges; - TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges); - TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(5)); - Standard_Real aDist = 4.0; - anAlgo.Add(aDist, anEdge); - // Make a chamfer. - anAlgo.Build(); - Standard_ASSERT_VOID(anAlgo.IsDone(), "Couldn't prepare a box with a chamfer!"); - // Get a box with a chamfer. - TopoDS_Shape aBoxWithChamfer = anAlgo.Shape(); - myResult << "Box with a chamfer is in yellow shading" << std::endl; - - Handle(AIS_ColoredShape) anAisBoxWithChamfer = new AIS_ColoredShape(aBoxWithChamfer); - anAisBoxWithChamfer->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - myObject3d.Append(anAisBoxWithChamfer); - myContext->SetDisplayMode(anAisBoxWithChamfer, 1, Standard_True); - - // Retrieve chamfer faces generated from the edge - const TopTools_ListOfShape& aGenShapes = anAlgo.Generated(anEdge); - Standard_ASSERT_VOID(!aGenShapes.IsEmpty(), "Chamfer face is expected!"); - for (TopTools_ListOfShape::Iterator anIt(aGenShapes); anIt.More(); anIt.Next()) - { - Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(anIt.Value()); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - anAisShape->SetWidth(2.5); - myObject3d.Append(anAisShape); - myContext->SetDisplayMode(anAisBoxWithChamfer, 1, Standard_True); - } - myResult << "Chamfer faces : " << aGenShapes.Size() << std::endl; - myResult << "The first one is using to remove" << std::endl; - myResult << "The removed face is in green" << std::endl; - - // Initialize defeaturing algo. - BRepAlgoAPI_Defeaturing aDefeatAlgo; - aDefeatAlgo.SetShape(aBoxWithChamfer); - aDefeatAlgo.AddFaceToRemove(aGenShapes.First()); - - // Remove the chamfer. - aDefeatAlgo.Build(); - - if (aDefeatAlgo.IsDone()) - { - // Get result. - TopoDS_Shape aResult = aDefeatAlgo.Shape(); - myResult << "Defeatured box is in red wireframe" << std::endl; - - Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); - anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisResult); - myContext->SetDisplayMode(anAisResult, 0, Standard_True); - } -} - -void TopologySamples::Fillet3dSample() -{ - // Make a box with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 8.0; - Standard_Real aSizeY = 10.0; - Standard_Real aSizeZ = 15.0; - TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow wireframe" << std::endl; - - // Initialize fillet algo. - BRepFilletAPI_MakeFillet anAlgo(aBox); - - // Set edge to apply a fillet with specified radius. - // Select the first edge in the map returned by TopExp::MapShapes method. - TopTools_IndexedMapOfShape anEdges; - TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges); - TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(1)); - Standard_Real aRadius = 3.0; - anAlgo.Add(aRadius, anEdge); - myResult << "Make a fillet of " << aRadius << " radius on an edge in green" << std::endl; - - Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); - Handle(AIS_ColoredShape) anAisEdge = new AIS_ColoredShape(anEdge); - anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisEdge->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - anAisEdge->SetWidth(2.5); - myObject3d.Append(anAisBox); - myObject3d.Append(anAisEdge); - myContext->SetDisplayMode(anAisBox, 0, Standard_True); - - // Make a fillet. - anAlgo.Build(); - - if (anAlgo.IsDone()) - { - // Get result. - TopoDS_Shape aResult = anAlgo.Shape(); - myResult << "Fillet was built. Result shape is in red shading" << std::endl; - - Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); - anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisResult); - myContext->SetDisplayMode(anAisResult, 1, Standard_True); - } -} - -void TopologySamples::Chamfer3dSample() -{ - // Make a box with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 8.0; - Standard_Real aSizeY = 10.0; - Standard_Real aSizeZ = 15.0; - TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow wirewrame" << std::endl; - - // Initialize chamfer algo. - BRepFilletAPI_MakeChamfer anAlgo(aBox); - - // Set edge to apply a chamfer with specified distance from it. - // Select the 5th edge in the map returned by TopExp::MapShapes method. - TopTools_IndexedMapOfShape anEdges; - TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges); - TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(5)); - Standard_Real aDist = 4.0; - anAlgo.Add(aDist, anEdge); - myResult << "Make a chamfer of " << aDist << " size on an edge in green" << std::endl; - - Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); - Handle(AIS_ColoredShape) anAisEdge = new AIS_ColoredShape(anEdge); - anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisEdge->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - anAisEdge->SetWidth(2.5); - myObject3d.Append(anAisBox); - myObject3d.Append(anAisEdge); - myContext->SetDisplayMode(anAisBox, 0, Standard_True); - - // Make a chamfer. - anAlgo.Build(); - if (anAlgo.IsDone()) - { - // Get result. - TopoDS_Shape aResult = anAlgo.Shape(); - myResult << "Fillet was built. Result shape is in red shading" << std::endl; - - Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); - anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisResult); - myContext->SetDisplayMode(anAisResult, 1, Standard_True); - - const TopTools_ListOfShape& aGenShapes = anAlgo.Generated(anEdge); - for (TopTools_ListOfShape::Iterator anIt(aGenShapes); anIt.More(); anIt.Next()) - { - Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(anIt.Value()); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); - anAisShape->SetWidth(2.5); - myObject3d.Append(anAisShape); - } - } -} - -void TopologySamples::Offset3dSample() -{ - // Make a triangle wire. - BRepBuilderAPI_MakePolygon aTria; - TopoDS_Vertex aVertA = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0)); - TopoDS_Vertex aVertB = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 0.0, +1.0)); - TopoDS_Vertex aVertC = BRepBuilderAPI_MakeVertex(gp_Pnt(+0.5, 0.0, 0.0)); - aTria.Add(aVertA); - aTria.Add(aVertB); - aTria.Add(aVertC); - aTria.Close(); - TopoDS_Wire aWire = aTria.Wire(); - myResult << "Triangular wire was created in yellow" << std::endl; - - Handle(AIS_ColoredShape) anAisWire = new AIS_ColoredShape(aWire); - anAisWire->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - myObject3d.Append(anAisWire); - - // Initialize offset algo. - BRepOffsetAPI_MakeOffset anAlgo(aWire); - - // Perform a series of offsets with linearly increasing value and altitude. - Standard_Real anOffsetStep = 0.2; - Standard_Real anAltitudeStep = 0.1; - for (Standard_Integer i = 1; i <= 4; ++i) - { - Standard_Real anOffset = anOffsetStep * i; - Standard_Real anAltitude = anAltitudeStep * i; - anAlgo.Perform(anOffset, anAltitude); - if (anAlgo.IsDone()) - { - // Get result. - TopoDS_Shape aResult = anAlgo.Shape(); - myResult << "#" << i << " : Offset = " << anOffset << " Altitude = " << anAltitude - << ". Result is in red." << std::endl; - - Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); - anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisResult); - } - } -} - -void TopologySamples::Evolved3dSample() -{ - // Make a triangle wire as a spine. - BRepBuilderAPI_MakePolygon aTria; - TopoDS_Vertex aVertA = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0)); - TopoDS_Vertex aVertB = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, +1.0, 0.0)); - TopoDS_Vertex aVertC = BRepBuilderAPI_MakeVertex(gp_Pnt(+0.5, 0.0, 0.0)); - aTria.Add(aVertA); - aTria.Add(aVertB); - aTria.Add(aVertC); - aTria.Close(); - TopoDS_Wire aSpine = aTria.Wire(); - myResult << "Profile wire was created in yellow" << std::endl; - - // Make a wire as a profile. - BRepBuilderAPI_MakePolygon aPoly; - TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0)); - TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, -0.1, 0.5)); - TopoDS_Vertex aVert3 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, -0.2, 1.0)); - aPoly.Add(aVert1); - aPoly.Add(aVert2); - aPoly.Add(aVert3); - TopoDS_Wire aProfile = aPoly.Wire(); - myResult << "Spine wire was created in greed" << std::endl; - - Handle(AIS_ColoredShape) anAisSpine = new AIS_ColoredShape(aSpine); - Handle(AIS_ColoredShape) anAisProfile = new AIS_ColoredShape(aProfile); - anAisSpine->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisSpine->SetWidth(2.5); - anAisProfile->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - anAisProfile->SetWidth(2.5); - myObject3d.Append(anAisSpine); - myObject3d.Append(anAisProfile); - - // Initialize evolving algo. - GeomAbs_JoinType aJoinType = GeomAbs_Arc; - Standard_Boolean aIsGlobalCS = Standard_False; - Standard_Boolean aIsSolid = Standard_True; - BRepOffsetAPI_MakeEvolved anAlgo(aSpine, aProfile, aJoinType, aIsGlobalCS, aIsSolid); - - // Perform evolving. - anAlgo.Build(); - - if (anAlgo.IsDone()) - { - // Get result. - TopoDS_Shape aResult = anAlgo.Shape(); - myResult << "Evolving result is in red" << std::endl; - - Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); - anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisResult); - } -} - -void TopologySamples::Copy3dSample() -{ - // Make a box with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 10.0; - Standard_Real aSizeY = 15.0; - Standard_Real aSizeZ = 20.0; - BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ); - TopoDS_Shape aBox = aBoxMake.Shape(); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow" << std::endl; - - // Make a box copy. - TopoDS_Shape aBoxCopy = BRepBuilderAPI_Copy(aBox); - myResult << "Box copy was created in red" << std::endl; - - gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(15.0, 0.0, 0.0)); - aBoxCopy.Move(aTrsf1); - myResult << "Box copy shape is moved apart for illustativeness" << std::endl; - - Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); - anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisBox->SetWidth(2.5); - Handle(AIS_ColoredShape) anAisBoxCopy = new AIS_ColoredShape(aBoxCopy); - anAisBoxCopy->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisBox); - myObject3d.Append(anAisBoxCopy); -} - -void TopologySamples::Transform3dSample() -{ - // Make a box with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 10.0; - Standard_Real aSizeY = 15.0; - Standard_Real aSizeZ = 20.0; - BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ); - TopoDS_Shape aBox = aBoxMake.Shape(); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow" << std::endl; - - // Move the box. - gp_Trsf aTrMove; aTrMove.SetTranslation(gp_Vec(15.0, 20.0, 25.0)); - TopoDS_Shape aMovedBox = BRepBuilderAPI_Transform(aBox, aTrMove, Standard_True); - myResult << "Moved box in green" << std::endl; - - // Rotate the moved box - gp_Trsf aTrRot; aTrRot.SetRotation(gp_Ax1(gp_Pnt(15.0, 20.0, 25.0), gp::DZ()), 3.0*M_PI_4); - TopoDS_Shape aRotatedBox = BRepBuilderAPI_Transform(aBox, aTrRot, Standard_True); - myResult << "Rotated box in red" << std::endl; - - Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); - Handle(AIS_ColoredShape) anAisMovedBox = new AIS_ColoredShape(aMovedBox); - Handle(AIS_ColoredShape) anAisRotatedBox = new AIS_ColoredShape(aRotatedBox); - anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisMovedBox->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - anAisRotatedBox->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisBox); - myObject3d.Append(anAisMovedBox); - myObject3d.Append(anAisRotatedBox); -} - -void TopologySamples::ConvertToNurbs3dSample() -{ - // Make a torus face. - gp_Torus aTorus(gp::XOY(), 20.0, 7.5); - TopoDS_Shape aTorusFace = BRepBuilderAPI_MakeFace(aTorus); - myResult << "TopoDS_Solid on the torus with" << std::endl - << "R major = " << aTorus.MajorRadius() << std::endl - << "R minor = " << aTorus.MinorRadius() << std::endl - << "was created in yellow" << std::endl; - - // Convert faces/edges from analytic to NURBS geometry. - TopoDS_Shape aNurbsFace = BRepBuilderAPI_NurbsConvert(aTorusFace); - myResult << "Converted torus in red" << std::endl; - gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(60.0, 0.0, 0.0)); - aNurbsFace.Move(aTrsf1); - myResult << "Converted torus is moved apart for illustativeness" << std::endl; - - Handle(AIS_ColoredShape) anAisTorus = new AIS_ColoredShape(aTorusFace); - Handle(AIS_ColoredShape) anAisNurbs = new AIS_ColoredShape(aNurbsFace); - anAisTorus->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisTorus->SetWidth(2.5); - anAisNurbs->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisTorus); - myObject3d.Append(anAisNurbs); -} - -void TopologySamples::SewContiguousFaces3dSample() -{ - // Make a sphere. - gp_Sphere aSphere(gp::XOY(), 1.0); - // South hemisphere. - TopoDS_Face aFace1 = BRepBuilderAPI_MakeFace(aSphere, 0.0, 2.0 * M_PI, -M_PI_2, 0.0); - // North hemisphere. - TopoDS_Face aFace2 = BRepBuilderAPI_MakeFace(aSphere, 0.0, 2.0 * M_PI, 0.0, +M_PI_2); - - // Make a default tailor. - BRepBuilderAPI_Sewing aTailor; - - // Add hemisphere faces. - aTailor.Add(aFace1); - aTailor.Add(aFace2); - - // Perform sewing. - aTailor.Perform(); - - // Get result. - const TopoDS_Shape& aSewedSphere = aTailor.SewedShape(); - myResult << "Two hemispheres were sewed : " << aTailor.NbFreeEdges() << " free edges" << std::endl; - - Handle(AIS_ColoredShape) anAisSewedSphere = new AIS_ColoredShape(aSewedSphere); - anAisSewedSphere->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisSewedSphere); -} - -void TopologySamples::CheckValidity3dSample() -{ - // Make a box with a corner at [0, 0, 0] and the specified sizes. - Standard_Real aSizeX = 10.0; - Standard_Real aSizeY = 15.0; - Standard_Real aSizeZ = 20.0; - BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ); - TopoDS_Shape aBox = aBoxMake.Shape(); - myResult << "Box at corner [0, 0, 0] and sizes [" - << aSizeX << ", " << aSizeY << ", " << aSizeZ - << "] was created in yellow" << std::endl; - - // Analyze the box. - BRepCheck_Analyzer anAnalyzer(aBox); - myResult << "Box is " << (anAnalyzer.IsValid() ? "valid" : "invalid") << std::endl; - - // Make the box invalid manually. - Handle(BRepTools_ReShape) aReShape = new BRepTools_ReShape(); - myResult << "Remove the top face from the box (red)" << std::endl; - aReShape->Remove(aBoxMake.TopFace()); - TopoDS_Shape aBox1 = aReShape->Apply(aBox); - myResult << "The top face was removed" << std::endl; - - // Analyze the modified box. - BRepCheck_Analyzer anAnalyzer1(aBox1); - myResult << "Modified box is " << (anAnalyzer1.IsValid() ? "valid" : "invalid") << std::endl; - - Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); - Handle(AIS_ColoredShape) anAisTopFace = new AIS_ColoredShape(aBoxMake.TopFace()); - anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); - anAisTopFace->SetColor(Quantity_Color(Quantity_NOC_RED)); - myObject3d.Append(anAisBox); - myObject3d.Append(anAisTopFace); -} - -void TopologySamples::ComputeLinearProperties3dSample() -{ - // Make an edge from a circular segment. - // Create a circle in XY plane of the radius 1.0. - gp_Circ aCirc(gp::XOY(), 1.0); - // Make a circular edge from the 1st quoter in the parametric space. - TopoDS_Edge aShape = BRepBuilderAPI_MakeEdge(aCirc, 0.0, M_PI); - myResult << "TopoDS_Edge on the circle's 1st quoter" << std::endl - << "with the center at [ " - << aCirc.Location().X() << ", " << aCirc.Location().Y() << ", " << aCirc.Location().Z() - << " ] and R = " << aCirc.Radius() << " was created in red" << std::endl - << std::endl; - - // Retrieve linear properties from the edge. - GProp_GProps aGProps; - BRepGProp::LinearProperties(aShape, aGProps); - Standard_Real aLength = aGProps.Mass(); - gp_Pnt aCOM = aGProps.CentreOfMass(); - Standard_Real anIx, anIy, anIz; - aGProps.StaticMoments(anIx, anIy, anIz); - gp_Mat aMOI = aGProps.MatrixOfInertia(); - myResult << "Linear properties:" << std::endl - << " Length = " << aLength << std::endl - << " Center of mass = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl - << " Static moments = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl - << " Matrix of inertia = [ " - << aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl - << std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl - << std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl; - GProp_PrincipalProps aPProps = aGProps.PrincipalProperties(); - Standard_Real anIxx, anIyy, anIzz; - aPProps.Moments(anIxx, anIyy, anIzz); - Standard_Real aRxx, aRyy, aRzz; - aPProps.RadiusOfGyration(aRxx, aRyy, aRzz); - myResult << "Principal properties:" << std::endl - << " Has symmetric axis : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl - << " Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl - << " Moments of inertia = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl - << " Radius of gyration = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl; - if (!aPProps.HasSymmetryPoint()) - { - const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia(); - myResult << " 1st axis of inertia = [ " << anAxis1.X() << ", " << anAxis1.Y() << ", " << anAxis1.Z() << " ]" << std::endl; - Handle(AIS_ColoredShape) anAisAxis1 = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis1.XYZ())); - anAisAxis1->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisAxis1); - if (!aPProps.HasSymmetryPoint()) - { - const gp_Vec& anAxis2 = aPProps.SecondAxisOfInertia(); - myResult << " 2nd axis of inertia = [ " << anAxis2.X() << ", " << anAxis2.Y() << ", " << anAxis2.Z() << " ]" << std::endl; - Handle(AIS_ColoredShape) anAisAxis2 = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis2.XYZ())); - anAisAxis2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisAxis2); - const gp_Vec& anAxis3 = aPProps.ThirdAxisOfInertia(); - myResult << " 3rd axis of inertia = [ " << anAxis3.X() << ", " << anAxis3.Y() << ", " << anAxis3.Z() << " ]" << std::endl; - Handle(AIS_ColoredShape) anAisAxis3 = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis3.XYZ())); - anAisAxis3->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisAxis3); - } - } - - Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); - Handle(AIS_Point) anAisCOM = new AIS_Point(new Geom_CartesianPoint(aCOM)); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); - Handle(AIS_TextLabel) aCOMLabel = new AIS_TextLabel(); - aCOMLabel->SetText("Center of mass"); - aCOMLabel->SetPosition(aCOM); - Handle(AIS_Axis) anAisAxisX = new AIS_Axis(new Geom_Axis2Placement(gp::YOZ()), AIS_TOAX_XAxis); - Handle(AIS_Axis) anAisAxisY = new AIS_Axis(new Geom_Axis2Placement(gp::ZOX()), AIS_TOAX_YAxis); - Handle(AIS_Axis) anAisAxisZ = new AIS_Axis(new Geom_Axis2Placement(gp::XOY()), AIS_TOAX_ZAxis); - myObject3d.Append(anAisAxisX); - myObject3d.Append(anAisAxisY); - myObject3d.Append(anAisAxisZ); - myObject3d.Append(anAisShape); - myObject3d.Append(anAisCOM); - myObject3d.Append(aCOMLabel); -} - -void TopologySamples::ComputeSurfaceProperties3dSample() -{ - // Make a face from a cylinder with R = 1 - // and directed along Z axis - gp_Cylinder aCyl(gp::XOY(), 1.0); - TopoDS_Face aShape = BRepBuilderAPI_MakeFace(aCyl, 0.0, M_PI, -1.0, +1.0).Face(); - myResult << "TopoDS_Face on the cylinder R = " << aCyl.Radius() << std::endl - << "with axis [ " << aCyl.Position().Direction().X() << ", " << aCyl.Position().Direction().Y() << ", " << aCyl.Position().Direction().Z() << " ]" << std::endl - << "limited in length [-1 ... +1] was created in red" << std::endl; - - // Retrieve surface properties from the face. - GProp_GProps aGProps; - BRepGProp::SurfaceProperties(aShape, aGProps); - Standard_Real aArea = aGProps.Mass(); - gp_Pnt aCOM = aGProps.CentreOfMass(); - Standard_Real anIx, anIy, anIz; - aGProps.StaticMoments(anIx, anIy, anIz); - gp_Mat aMOI = aGProps.MatrixOfInertia(); - myResult << "Linear properties:" << std::endl - << " Area = " << aArea << std::endl - << " Center of mass = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl - << " Static moments = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl - << " Matrix of inertia = [ " - << aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl - << std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl - << std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl; - GProp_PrincipalProps aPProps = aGProps.PrincipalProperties(); - Standard_Real anIxx, anIyy, anIzz; - aPProps.Moments(anIxx, anIyy, anIzz); - Standard_Real aRxx, aRyy, aRzz; - aPProps.RadiusOfGyration(aRxx, aRyy, aRzz); - myResult << "Principal properties:" << std::endl - << " Has symmetric axis : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl - << " Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl - << " Moments of inertia = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl - << " Radius of gyration = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl; - if (!aPProps.HasSymmetryPoint()) - { - const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia(); - myResult << " 1st axis of inertia = [ " << anAxis1.X() << ", " << anAxis1.Y() << ", " << anAxis1.Z() << " ]" << std::endl; - Handle(AIS_ColoredShape) anAisAxis1 = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis1.XYZ())); - anAisAxis1->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisAxis1); - if (!aPProps.HasSymmetryPoint()) - { - const gp_Vec& anAxis2 = aPProps.SecondAxisOfInertia(); - myResult << " 2nd axis of inertia = [ " << anAxis2.X() << ", " << anAxis2.Y() << ", " << anAxis2.Z() << " ]" << std::endl; - Handle(AIS_ColoredShape) anAisAxis2 = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis2.XYZ())); - anAisAxis2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisAxis2); - const gp_Vec& anAxis3 = aPProps.ThirdAxisOfInertia(); - myResult << " 3rd axis of inertia = [ " << anAxis3.X() << ", " << anAxis3.Y() << ", " << anAxis3.Z() << " ]" << std::endl; - Handle(AIS_ColoredShape) anAisAxis3 = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis3.XYZ())); - anAisAxis3->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisAxis3); - } - } - - Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); - Handle(AIS_Point) anAisCOM = new AIS_Point(new Geom_CartesianPoint(aCOM)); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); - Handle(AIS_TextLabel) aCOMLabel = new AIS_TextLabel(); - aCOMLabel->SetText("Center of mass"); - aCOMLabel->SetPosition(aCOM); - Handle(AIS_Axis) anAisAxisX = new AIS_Axis(new Geom_Axis2Placement(gp::YOZ()), AIS_TOAX_XAxis); - Handle(AIS_Axis) anAisAxisY = new AIS_Axis(new Geom_Axis2Placement(gp::ZOX()), AIS_TOAX_YAxis); - Handle(AIS_Axis) anAisAxisZ = new AIS_Axis(new Geom_Axis2Placement(gp::XOY()), AIS_TOAX_ZAxis); - myObject3d.Append(anAisAxisX); - myObject3d.Append(anAisAxisY); - myObject3d.Append(anAisAxisZ); - myObject3d.Append(anAisShape); - myObject3d.Append(anAisCOM); - myObject3d.Append(aCOMLabel); -} - -void TopologySamples::ComputeVolumeProperties3dSample() -{ - // Make a box by two points. - gp_Pnt aPnt1(-0.5, -0.6, -0.7); - gp_Pnt aPnt2(+0.8, +0.9, +1.0); - TopoDS_Shape aShape = BRepPrimAPI_MakeBox(aPnt1, aPnt2); - myResult << "Box with corners [" << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() - << "] and [" << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() - << "] was created in red" << std::endl; - - // Retrieve volume properties from the face. - GProp_GProps aGProps; - BRepGProp::VolumeProperties(aShape, aGProps); - Standard_Real aVolume = aGProps.Mass(); - gp_Pnt aCOM = aGProps.CentreOfMass(); - Standard_Real anIx, anIy, anIz; - aGProps.StaticMoments(anIx, anIy, anIz); - gp_Mat aMOI = aGProps.MatrixOfInertia(); - myResult << "Linear properties:" << std::endl - << " Volume = " << aVolume << std::endl - << " Center of mass = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl - << " Static moments = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl - << " Matrix of inertia = [ " - << aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl - << std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl - << std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl; - GProp_PrincipalProps aPProps = aGProps.PrincipalProperties(); - Standard_Real anIxx, anIyy, anIzz; - aPProps.Moments(anIxx, anIyy, anIzz); - Standard_Real aRxx, aRyy, aRzz; - aPProps.RadiusOfGyration(aRxx, aRyy, aRzz); - myResult << "Principal properties:" << std::endl - << " Has symmetric axis : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl - << " Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl - << " Moments of inertia = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl - << " Radius of gyration = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl; - if (!aPProps.HasSymmetryPoint()) - { - const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia(); - myResult << " 1st axis of inertia = [ " << anAxis1.X() << ", " << anAxis1.Y() << ", " << anAxis1.Z() << " ]" << std::endl; - Handle(AIS_ColoredShape) anAisAxis1 = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis1.XYZ())); - anAisAxis1->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisAxis1); - if (!aPProps.HasSymmetryPoint()) - { - const gp_Vec& anAxis2 = aPProps.SecondAxisOfInertia(); - myResult << " 2nd axis of inertia = [ " << anAxis2.X() << ", " << anAxis2.Y() << ", " << anAxis2.Z() << " ]" << std::endl; - Handle(AIS_ColoredShape) anAisAxis2 = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis2.XYZ())); - anAisAxis2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisAxis2); - const gp_Vec& anAxis3 = aPProps.ThirdAxisOfInertia(); - myResult << " 3rd axis of inertia = [ " << anAxis3.X() << ", " << anAxis3.Y() << ", " << anAxis3.Z() << " ]" << std::endl; - Handle(AIS_ColoredShape) anAisAxis3 = new AIS_ColoredShape( - BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis3.XYZ())); - anAisAxis3->SetColor(Quantity_Color(Quantity_NOC_GREEN)); - myObject3d.Append(anAisAxis3); - } - } - - Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); - Handle(AIS_Point) anAisCOM = new AIS_Point(new Geom_CartesianPoint(aCOM)); - anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); - Handle(AIS_TextLabel) aCOMLabel = new AIS_TextLabel(); - aCOMLabel->SetText("Center of mass"); - aCOMLabel->SetPosition(aCOM); - Handle(AIS_Axis) anAisAxisX = new AIS_Axis(new Geom_Axis2Placement(gp::YOZ()), AIS_TOAX_XAxis); - Handle(AIS_Axis) anAisAxisY = new AIS_Axis(new Geom_Axis2Placement(gp::ZOX()), AIS_TOAX_YAxis); - Handle(AIS_Axis) anAisAxisZ = new AIS_Axis(new Geom_Axis2Placement(gp::XOY()), AIS_TOAX_ZAxis); - myObject3d.Append(anAisAxisX); - myObject3d.Append(anAisAxisY); - myObject3d.Append(anAisAxisZ); - myObject3d.Append(anAisShape); - myObject3d.Append(anAisCOM); - myObject3d.Append(aCOMLabel); -} diff --git a/samples/OCCTOverview/code/TopologySamples.h b/samples/OCCTOverview/code/TopologySamples.h deleted file mode 100644 index ecb6ca51ac..0000000000 --- a/samples/OCCTOverview/code/TopologySamples.h +++ /dev/null @@ -1,80 +0,0 @@ -// 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 - -//! 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 diff --git a/samples/OCCTOverview/code/Triangulation.xml b/samples/OCCTOverview/code/Triangulation.xml deleted file mode 100644 index 04d37b3db0..0000000000 --- a/samples/OCCTOverview/code/Triangulation.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/samples/OCCTOverview/code/TriangulationSamples.cxx b/samples/OCCTOverview/code/TriangulationSamples.cxx deleted file mode 100644 index 1635ef7c7e..0000000000 --- a/samples/OCCTOverview/code/TriangulationSamples.cxx +++ /dev/null @@ -1,113 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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); - - for (Standard_Integer i = 1; i <= aTriangulation->NbTriangles(); i++) - { - const Poly_Triangle trian = aTriangulation->Triangle (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(aTriangulation->Node (M), aTriangulation->Node (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; -} diff --git a/samples/OCCTOverview/code/TriangulationSamples.h b/samples/OCCTOverview/code/TriangulationSamples.h deleted file mode 100644 index aaab1fc070..0000000000 --- a/samples/OCCTOverview/code/TriangulationSamples.h +++ /dev/null @@ -1,49 +0,0 @@ -// 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 diff --git a/samples/OCCTOverview/code/Viewer2d.xml b/samples/OCCTOverview/code/Viewer2d.xml deleted file mode 100644 index 3b890519ef..0000000000 --- a/samples/OCCTOverview/code/Viewer2d.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/OCCTOverview/code/Viewer2dSamples.cxx b/samples/OCCTOverview/code/Viewer2dSamples.cxx deleted file mode 100644 index 624881da34..0000000000 --- a/samples/OCCTOverview/code/Viewer2dSamples.cxx +++ /dev/null @@ -1,282 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include -#include -#include - -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_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); -} diff --git a/samples/OCCTOverview/code/Viewer2dSamples.h b/samples/OCCTOverview/code/Viewer2dSamples.h deleted file mode 100644 index 66deb43b70..0000000000 --- a/samples/OCCTOverview/code/Viewer2dSamples.h +++ /dev/null @@ -1,76 +0,0 @@ -// 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 -#include - -//! 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 diff --git a/samples/OCCTOverview/code/Viewer3d.xml b/samples/OCCTOverview/code/Viewer3d.xml deleted file mode 100644 index 2c504e5dc6..0000000000 --- a/samples/OCCTOverview/code/Viewer3d.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/OCCTOverview/code/Viewer3dSamples.cxx b/samples/OCCTOverview/code/Viewer3dSamples.cxx deleted file mode 100644 index 5cb2b76380..0000000000 --- a/samples/OCCTOverview/code/Viewer3dSamples.cxx +++ /dev/null @@ -1,342 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include - -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(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - myContext->SetDisplayMode(anAisObject, 0, false); // set wireframe - } - myContext->UpdateCurrentViewer(); -} - -void Viewer3dSamples::ShadingPresentation3dSample() -{ - AIS_ListOfInteractive anAisObjectsList; - myContext->DisplayedObjects(anAisObjectsList); - for(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - myContext->SetDisplayMode(anAisObject, 1, false); // set shading - } - myContext->UpdateCurrentViewer(); -} - -void Viewer3dSamples::RedColorPresentation3dSample() -{ - AIS_ListOfInteractive anAisObjectsList; - myContext->DisplayedObjects(anAisObjectsList); - for(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - 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(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - 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(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - myContext->SetMaterial(anAisObject, aMaterial, Standard_False); - } - myContext->UpdateCurrentViewer(); -} - -void Viewer3dSamples::BronzePresentation3dSample() -{ - AIS_ListOfInteractive anAisObjectsList; - myContext->DisplayedObjects(anAisObjectsList); - Graphic3d_NameOfMaterial aMaterial = Graphic3d_NOM_BRONZE; - for(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - myContext->SetMaterial(anAisObject, aMaterial, Standard_False); - } - myContext->UpdateCurrentViewer(); -} - -void Viewer3dSamples::OpaquePresentation3dSample() -{ - AIS_ListOfInteractive anAisObjectsList; - myContext->DisplayedObjects(anAisObjectsList); - for(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - myContext->SetTransparency(anAisObject, 0.0, Standard_False); - } - myContext->UpdateCurrentViewer(); -} - -void Viewer3dSamples::HalfTransparencyPresentation3dSample() -{ - AIS_ListOfInteractive anAisObjectsList; - myContext->DisplayedObjects(anAisObjectsList); - for(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); - anIter.More(); anIter.Next()) - { - const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); - 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; - } -} diff --git a/samples/OCCTOverview/code/Viewer3dSamples.h b/samples/OCCTOverview/code/Viewer3dSamples.h deleted file mode 100644 index 1691736b30..0000000000 --- a/samples/OCCTOverview/code/Viewer3dSamples.h +++ /dev/null @@ -1,78 +0,0 @@ -// 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 -#include - -//! 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 diff --git a/samples/qt/AndroidQt/CMakeLists.txt b/samples/qt/AndroidQt/CMakeLists.txt index 126582e8e2..ba43a22a39 100644 --- a/samples/qt/AndroidQt/CMakeLists.txt +++ b/samples/qt/AndroidQt/CMakeLists.txt @@ -1,9 +1,16 @@ project(AndroidQt) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) +# Sample configuration +set (EXECUTABLE_PROJECT ON) +set (USE_QT ON) +set (RELATIVE_DIR "samples/qt") +set (TARGET_FOLDER "Samples") + +include_directories("${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE}/${RELATIVE_DIR}") + OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) -ADD_DEFINITIONS(-DNO_Common_EXPORTS) +# Target-specific definitions +target_compile_definitions(AndroidQt PRIVATE -DNO_Common_EXPORTS) diff --git a/samples/qt/AndroidQt/EXTERNLIB b/samples/qt/AndroidQt/EXTERNLIB deleted file mode 100644 index fb5edc8d1d..0000000000 --- a/samples/qt/AndroidQt/EXTERNLIB +++ /dev/null @@ -1,17 +0,0 @@ -TKernel -TKMath -TKG2d -TKG3d -TKGeomBase -TKBRep -TKGeomAlgo -TKTopAlgo -TKShHealing -TKService -TKMesh -TKHLR -TKV3d -TKOpenGl -CSF_FreeImagePlus -CSF_FREETYPE -CSF_OpenGlLibs diff --git a/samples/qt/AndroidQt/EXTERNLIB.cmake b/samples/qt/AndroidQt/EXTERNLIB.cmake new file mode 100644 index 0000000000..e69a75f041 --- /dev/null +++ b/samples/qt/AndroidQt/EXTERNLIB.cmake @@ -0,0 +1,20 @@ +# External dependencies for AndroidQt sample +set(OCCT_AndroidQt_EXTERNAL_LIBS + TKernel + TKMath + TKG2d + TKG3d + TKGeomBase + TKBRep + TKGeomAlgo + TKTopAlgo + TKShHealing + TKService + TKMesh + TKHLR + TKV3d + TKOpenGl + CSF_FreeImagePlus + CSF_FREETYPE + CSF_OpenGlLibs +) \ No newline at end of file diff --git a/samples/qt/AndroidQt/FILES b/samples/qt/AndroidQt/FILES deleted file mode 100644 index ca4f0e567b..0000000000 --- a/samples/qt/AndroidQt/FILES +++ /dev/null @@ -1,2 +0,0 @@ -EXTERNLIB -PACKAGES diff --git a/samples/qt/AndroidQt/FILES.cmake b/samples/qt/AndroidQt/FILES.cmake new file mode 100644 index 0000000000..71d1823196 --- /dev/null +++ b/samples/qt/AndroidQt/FILES.cmake @@ -0,0 +1,14 @@ +# Source files for AndroidQt sample +set(OCCT_AndroidQt_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}") + +set(OCCT_AndroidQt_FILES + src/AndroidQt.cxx + src/AndroidQt.h + src/AndroidQt.qrc + src/AndroidQt_TouchParameters.cxx + src/AndroidQt_TouchParameters.h + src/AndroidQt_UserInteractionParameters.h + src/AndroidQt_Window.cxx + src/AndroidQt_Window.h + src/Main.cxx +) \ No newline at end of file diff --git a/samples/qt/AndroidQt/PACKAGES b/samples/qt/AndroidQt/PACKAGES deleted file mode 100644 index 089247b96e..0000000000 --- a/samples/qt/AndroidQt/PACKAGES +++ /dev/null @@ -1 +0,0 @@ -AndroidQt/src diff --git a/samples/qt/AndroidQt/PACKAGES.cmake b/samples/qt/AndroidQt/PACKAGES.cmake new file mode 100644 index 0000000000..68a4cffcbe --- /dev/null +++ b/samples/qt/AndroidQt/PACKAGES.cmake @@ -0,0 +1,4 @@ +# Packages for AndroidQt sample +set(OCCT_AndroidQt_LIST_OF_PACKAGES + AndroidQt +) \ No newline at end of file diff --git a/samples/qt/AndroidQt/src/FILES b/samples/qt/AndroidQt/src/FILES deleted file mode 100644 index 0bb880c9b3..0000000000 --- a/samples/qt/AndroidQt/src/FILES +++ /dev/null @@ -1,9 +0,0 @@ -AndroidQt.cxx -AndroidQt.h -AndroidQt.qrc -AndroidQt_TouchParameters.cxx -AndroidQt_TouchParameters.h -AndroidQt_UserInteractionParameters.h -AndroidQt_Window.cxx -AndroidQt_Window.h -Main.cxx diff --git a/samples/qt/Common/src/FILES b/samples/qt/Common/src/FILES deleted file mode 100644 index 12ba2818f3..0000000000 --- a/samples/qt/Common/src/FILES +++ /dev/null @@ -1,17 +0,0 @@ -ApplicationCommon.cxx -ApplicationCommon.h -Common-icon.ts -Common-string.ts -CommonSample.h -DocumentCommon.cxx -DocumentCommon.h -Material.cxx -Material.h -MDIWindow.cxx -MDIWindow.h -OcctWindow.cxx -OcctWindow.h -Transparency.cxx -Transparency.h -View.cxx -View.h diff --git a/samples/qt/FuncDemo/CMakeLists.txt b/samples/qt/FuncDemo/CMakeLists.txt index 1ea39b5fe2..afa0ec7fea 100644 --- a/samples/qt/FuncDemo/CMakeLists.txt +++ b/samples/qt/FuncDemo/CMakeLists.txt @@ -1,8 +1,14 @@ project(FuncDemo) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) +# Sample configuration +set (EXECUTABLE_PROJECT ON) +set (USE_QT ON) +set (RELATIVE_DIR "samples/qt") +set (TARGET_FOLDER "Samples") + +include_directories("${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE}/${RELATIVE_DIR}") + OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) if (BUILD_Inspector) target_link_libraries (FuncDemo TKTInspector) diff --git a/samples/qt/FuncDemo/EXTERNLIB b/samples/qt/FuncDemo/EXTERNLIB deleted file mode 100644 index 7ced3fdd54..0000000000 --- a/samples/qt/FuncDemo/EXTERNLIB +++ /dev/null @@ -1,14 +0,0 @@ -TKBO -TKBRep -TKCAF -TKCDF -TKG2d -TKG3d -TKGeomAlgo -TKGeomBase -TKernel -TKLCAF -TKMath -TKMesh -TKPrim -TKTopAlgo diff --git a/samples/qt/FuncDemo/EXTERNLIB.cmake b/samples/qt/FuncDemo/EXTERNLIB.cmake new file mode 100644 index 0000000000..d34ba941be --- /dev/null +++ b/samples/qt/FuncDemo/EXTERNLIB.cmake @@ -0,0 +1,17 @@ +# External dependencies for FuncDemo sample +set(OCCT_FuncDemo_EXTERNAL_LIBS + TKBO + TKBRep + TKCAF + TKCDF + TKG2d + TKG3d + TKGeomAlgo + TKGeomBase + TKernel + TKLCAF + TKMath + TKMesh + TKPrim + TKTopAlgo +) \ No newline at end of file diff --git a/samples/qt/FuncDemo/FILES b/samples/qt/FuncDemo/FILES deleted file mode 100644 index ca4f0e567b..0000000000 --- a/samples/qt/FuncDemo/FILES +++ /dev/null @@ -1,2 +0,0 @@ -EXTERNLIB -PACKAGES diff --git a/samples/qt/FuncDemo/FILES.cmake b/samples/qt/FuncDemo/FILES.cmake new file mode 100644 index 0000000000..ed56eb76c0 --- /dev/null +++ b/samples/qt/FuncDemo/FILES.cmake @@ -0,0 +1,33 @@ +# Source files for FuncDemo sample +set(OCCT_FuncDemo_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}") + +set(OCCT_FuncDemo_FILES + src/BaseDriver.cpp + src/BaseDriver.h + src/CircleDriver.cpp + src/CircleDriver.h + src/ConeDriver.cpp + src/ConeDriver.h + src/CylinderDriver.cpp + src/CylinderDriver.h + src/edge.cpp + src/edge.h + src/FThread.cpp + src/FThread.h + src/FuncDemo.qrc + src/graphwidget.cpp + src/graphwidget.h + src/main.cpp + src/mainwindow.cpp + src/mainwindow.h + src/node.cpp + src/node.h + src/PointDriver.cpp + src/PointDriver.h + src/PrismDriver.cpp + src/PrismDriver.h + src/ShapeSaverDriver.cpp + src/ShapeSaverDriver.h + src/SimpleDriver.cpp + src/SimpleDriver.h +) \ No newline at end of file diff --git a/samples/qt/FuncDemo/PACKAGES b/samples/qt/FuncDemo/PACKAGES deleted file mode 100644 index 6417933607..0000000000 --- a/samples/qt/FuncDemo/PACKAGES +++ /dev/null @@ -1 +0,0 @@ -FuncDemo/src \ No newline at end of file diff --git a/samples/qt/FuncDemo/PACKAGES.cmake b/samples/qt/FuncDemo/PACKAGES.cmake new file mode 100644 index 0000000000..310092e7a4 --- /dev/null +++ b/samples/qt/FuncDemo/PACKAGES.cmake @@ -0,0 +1,4 @@ +# Packages for FuncDemo sample +set(OCCT_FuncDemo_LIST_OF_PACKAGES + FuncDemo +) \ No newline at end of file diff --git a/samples/qt/FuncDemo/src/FILES b/samples/qt/FuncDemo/src/FILES deleted file mode 100644 index 07ace65e6e..0000000000 --- a/samples/qt/FuncDemo/src/FILES +++ /dev/null @@ -1,28 +0,0 @@ -BaseDriver.cpp -BaseDriver.h -CircleDriver.cpp -CircleDriver.h -ConeDriver.cpp -ConeDriver.h -CylinderDriver.cpp -CylinderDriver.h -edge.cpp -edge.h -FILES -FThread.cpp -FThread.h -graphwidget.cpp -graphwidget.h -main.cpp -mainwindow.cpp -mainwindow.h -node.cpp -node.h -PointDriver.cpp -PointDriver.h -PrismDriver.cpp -PrismDriver.h -ShapeSaverDriver.cpp -ShapeSaverDriver.h -SimpleDriver.cpp -SimpleDriver.h diff --git a/samples/qt/IESample/CMakeLists.txt b/samples/qt/IESample/CMakeLists.txt index a8dffeedcb..395352abcd 100644 --- a/samples/qt/IESample/CMakeLists.txt +++ b/samples/qt/IESample/CMakeLists.txt @@ -1,11 +1,18 @@ project(IESample) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) +# Sample configuration +set (EXECUTABLE_PROJECT ON) +set (USE_QT ON) +set (RELATIVE_DIR "samples/qt") +set (TARGET_FOLDER "Samples") + +include_directories("${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE}/${RELATIVE_DIR}") include_directories("${OCCT_ROOT_DIR}/${RELATIVE_DIR}/Interface/src") include_directories("${OCCT_ROOT_DIR}/${RELATIVE_DIR}/Common/src") + OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) -ADD_DEFINITIONS(-DNO_COMMONSAMPLE_EXPORTS -DNO_IESAMPLE_EXPORTS) +# Target-specific definitions +target_compile_definitions(IESample PRIVATE -DNO_COMMONSAMPLE_EXPORTS -DNO_IESAMPLE_EXPORTS) diff --git a/samples/qt/IESample/EXTERNLIB b/samples/qt/IESample/EXTERNLIB deleted file mode 100644 index 77612e08d9..0000000000 --- a/samples/qt/IESample/EXTERNLIB +++ /dev/null @@ -1,26 +0,0 @@ -TKBRep -TKBool -TKBO -TKCDF -TKFillet -TKG2d -TKG3d -TKGeomAlgo -TKGeomBase -TKHLR -TKDEIGES -TKernel -TKMath -TKMesh -TKOffset -TKOpenGl -TKPrim -TKShHealing -TKService -TKDESTEP -TKDESTL -TKTopAlgo -TKV3d -TKDEVRML -TKXSBase - diff --git a/samples/qt/IESample/EXTERNLIB.cmake b/samples/qt/IESample/EXTERNLIB.cmake new file mode 100644 index 0000000000..6751415686 --- /dev/null +++ b/samples/qt/IESample/EXTERNLIB.cmake @@ -0,0 +1,28 @@ +# External dependencies for IESample sample +set(OCCT_IESample_EXTERNAL_LIBS + TKBRep + TKBool + TKBO + TKCDF + TKFillet + TKG2d + TKG3d + TKGeomAlgo + TKGeomBase + TKHLR + TKDEIGES + TKernel + TKMath + TKMesh + TKOffset + TKOpenGl + TKPrim + TKShHealing + TKService + TKDESTEP + TKDESTL + TKTopAlgo + TKV3d + TKDEVRML + TKXSBase +) \ No newline at end of file diff --git a/samples/qt/IESample/FILES b/samples/qt/IESample/FILES deleted file mode 100644 index ca4f0e567b..0000000000 --- a/samples/qt/IESample/FILES +++ /dev/null @@ -1,2 +0,0 @@ -EXTERNLIB -PACKAGES diff --git a/samples/qt/IESample/FILES.cmake b/samples/qt/IESample/FILES.cmake new file mode 100644 index 0000000000..fb6b460229 --- /dev/null +++ b/samples/qt/IESample/FILES.cmake @@ -0,0 +1,29 @@ +# Source files for IESample sample +set(OCCT_IESample_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}") + +set(OCCT_IESample_FILES + src/Main.cxx + ../Common/src/ApplicationCommon.cxx + ../Common/src/ApplicationCommon.h + ../Common/src/Common-icon.ts + ../Common/src/Common-string.ts + ../Common/src/CommonSample.h + ../Common/src/DocumentCommon.cxx + ../Common/src/DocumentCommon.h + ../Common/src/Material.cxx + ../Common/src/Material.h + ../Common/src/MDIWindow.cxx + ../Common/src/MDIWindow.h + ../Common/src/OcctWindow.cxx + ../Common/src/OcctWindow.h + ../Common/src/Transparency.cxx + ../Common/src/Transparency.h + ../Common/src/View.cxx + ../Common/src/View.h + ../Interface/src/Application.cxx + ../Interface/src/Application.h + ../Interface/src/IESample.h + ../Interface/src/Interface-string.ts + ../Interface/src/Translate.cxx + ../Interface/src/Translate.h +) \ No newline at end of file diff --git a/samples/qt/IESample/PACKAGES b/samples/qt/IESample/PACKAGES deleted file mode 100644 index aa9aa1a3ca..0000000000 --- a/samples/qt/IESample/PACKAGES +++ /dev/null @@ -1,3 +0,0 @@ -IESample/src -Common/src -Interface/src \ No newline at end of file diff --git a/samples/qt/IESample/PACKAGES.cmake b/samples/qt/IESample/PACKAGES.cmake new file mode 100644 index 0000000000..812f8bb892 --- /dev/null +++ b/samples/qt/IESample/PACKAGES.cmake @@ -0,0 +1,4 @@ +# Packages for IESample sample +set(OCCT_IESample_LIST_OF_PACKAGES + IESample +) \ No newline at end of file diff --git a/samples/qt/IESample/src/FILES b/samples/qt/IESample/src/FILES deleted file mode 100644 index f9dea79a18..0000000000 --- a/samples/qt/IESample/src/FILES +++ /dev/null @@ -1 +0,0 @@ -Main.cxx \ No newline at end of file diff --git a/samples/qt/Interface/src/FILES b/samples/qt/Interface/src/FILES deleted file mode 100644 index c338ab41f5..0000000000 --- a/samples/qt/Interface/src/FILES +++ /dev/null @@ -1,6 +0,0 @@ -Application.cxx -Application.h -IESample.h -Interface-string.ts -Translate.cxx -Translate.h diff --git a/samples/qt/OCCTOverview/.DS_Store b/samples/qt/OCCTOverview/.DS_Store new file mode 100644 index 0000000000..0d4b91b9ba Binary files /dev/null and b/samples/qt/OCCTOverview/.DS_Store differ diff --git a/samples/qt/OCCTOverview/CMakeLists.txt b/samples/qt/OCCTOverview/CMakeLists.txt index 27a029d8d1..684d14eba7 100644 --- a/samples/qt/OCCTOverview/CMakeLists.txt +++ b/samples/qt/OCCTOverview/CMakeLists.txt @@ -1,8 +1,18 @@ project(OCCTOverview) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) -include_directories("${OCCT_ROOT_DIR}/${RELATIVE_DIR}/../OCCTOverview/code") +# Sample configuration +set (EXECUTABLE_PROJECT ON) +set (USE_QT ON) +set (RELATIVE_DIR "samples/qt") +set (TARGET_FOLDER "Samples") + +include_directories("${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE}/${RELATIVE_DIR}") +include_directories("${OCCT_ROOT_DIR}/${RELATIVE_DIR}/Common/src") +include_directories("${OCCT_ROOT_DIR}/${RELATIVE_DIR}/Interface/src") +include_directories("${OCCT_ROOT_DIR}/${RELATIVE_DIR}/OCCTOverview/src") +include_directories("${OCCT_ROOT_DIR}/${RELATIVE_DIR}/OCCTOverview/code") + OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) -ADD_DEFINITIONS(-DNO_COMMONSAMPLE_EXPORTS -DNO_IESAMPLE_EXPORTS) +# Target-specific definitions +target_compile_definitions(OCCTOverview PRIVATE -DNO_COMMONSAMPLE_EXPORTS -DNO_IESAMPLE_EXPORTS) diff --git a/samples/qt/OCCTOverview/EXTERNLIB b/samples/qt/OCCTOverview/EXTERNLIB deleted file mode 100644 index 8c5944480a..0000000000 --- a/samples/qt/OCCTOverview/EXTERNLIB +++ /dev/null @@ -1,30 +0,0 @@ -TKBRep -TKBin -TKBool -TKBO -TKCDF -TKFillet -TKG2d -TKG3d -TKGeomAlgo -TKGeomBase -TKernel -TKHLR -TKDEIGES -TKMath -TKMesh -TKOffset -TKOpenGl -TKPrim -TKService -TKShHealing -TKDESTEP -TKDESTL -TKTopAlgo -TKV3d -TKDEVRML -TKXSBase -TKLCAF -TKCAF -TKVCAF -TKXml diff --git a/samples/qt/OCCTOverview/EXTERNLIB.cmake b/samples/qt/OCCTOverview/EXTERNLIB.cmake new file mode 100644 index 0000000000..abc4786b0a --- /dev/null +++ b/samples/qt/OCCTOverview/EXTERNLIB.cmake @@ -0,0 +1,33 @@ +# External dependencies for OCCTOverview sample +set(OCCT_OCCTOverview_EXTERNAL_LIBS + TKBRep + TKBin + TKBool + TKBO + TKCDF + TKFillet + TKG2d + TKG3d + TKGeomAlgo + TKGeomBase + TKernel + TKHLR + TKDEIGES + TKMath + TKMesh + TKOffset + TKOpenGl + TKPrim + TKService + TKShHealing + TKDESTEP + TKDESTL + TKTopAlgo + TKV3d + TKDEVRML + TKXSBase + TKLCAF + TKCAF + TKVCAF + TKXml +) \ No newline at end of file diff --git a/samples/qt/OCCTOverview/FILES b/samples/qt/OCCTOverview/FILES deleted file mode 100644 index ca4f0e567b..0000000000 --- a/samples/qt/OCCTOverview/FILES +++ /dev/null @@ -1,2 +0,0 @@ -EXTERNLIB -PACKAGES diff --git a/samples/qt/OCCTOverview/FILES.cmake b/samples/qt/OCCTOverview/FILES.cmake new file mode 100644 index 0000000000..b705149010 --- /dev/null +++ b/samples/qt/OCCTOverview/FILES.cmake @@ -0,0 +1,72 @@ +# Source files for OCCTOverview sample +set(OCCT_OCCTOverview_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}") + +set(OCCT_OCCTOverview_FILES + src/ApplicationCommon.cxx + src/ApplicationCommon.h + src/CommonSample.h + src/DocumentCommon.cxx + src/DocumentCommon.h + src/GeomWidget.cxx + src/GeomWidget.h + src/Main.cxx + src/OcctHighlighter.cxx + src/OcctHighlighter.h + src/OcctWindow.cxx + src/OcctWindow.h + src/OCCTOverview.qrc + src/TranslateDialog.h + src/TranslateDialog.cxx + src/Transparency.cxx + src/Transparency.h + src/View.cxx + src/View.h + code/AdaptorCurve2d_AIS.cxx + code/AdaptorCurve2d_AIS.h + code/AdaptorCurve_AIS.cxx + code/AdaptorCurve_AIS.h + code/AdaptorPnt2d_AIS.cxx + code/AdaptorPnt2d_AIS.h + code/AdaptorVec_AIS.cxx + code/AdaptorVec_AIS.h + code/BaseSample.cxx + code/BaseSample.h + code/DataExchange.xml + code/DataExchangeSamples.cxx + code/DataExchangeSamples.h + code/Geometry.xml + code/GeometrySamples.cxx + code/GeometrySamples.h + code/MakeBottle.cxx + code/MakeBottle.h + code/Ocaf.xml + code/OcafSamples.cxx + code/OcafSamples.h + code/Sample2D_Face.cxx + code/Sample2D_Face.h + code/Sample2D_Image.cxx + code/Sample2D_Image.h + code/Sample2D_Markers.cxx + code/Sample2D_Markers.h + code/Samples.qrc + code/TOcafFunction_BoxDriver.cxx + code/TOcafFunction_BoxDriver.h + code/TOcafFunction_CutDriver.cxx + code/TOcafFunction_CutDriver.h + code/TOcafFunction_CylDriver.cxx + code/TOcafFunction_CylDriver.h + code/TOcaf_Application.cxx + code/TOcaf_Application.h + code/Topology.xml + code/TopologySamples.cxx + code/TopologySamples.h + code/Triangulation.xml + code/TriangulationSamples.cxx + code/TriangulationSamples.h + code/Viewer2d.xml + code/Viewer2dSamples.cxx + code/Viewer2dSamples.h + code/Viewer3d.xml + code/Viewer3dSamples.cxx + code/Viewer3dSamples.h +) diff --git a/samples/qt/OCCTOverview/OCCTOverview.pro b/samples/qt/OCCTOverview/OCCTOverview.pro index b75bab5f91..c3587324a6 100644 --- a/samples/qt/OCCTOverview/OCCTOverview.pro +++ b/samples/qt/OCCTOverview/OCCTOverview.pro @@ -17,19 +17,19 @@ isEmpty(CSF_OCCTSamplesPath) { HEADERS = ./src/*.h \ - $${SAMPLESROOT}/../OCCTOverview/code/*.h + ./code/*.h SOURCES = ./src/*.cxx \ - $${SAMPLESROOT}/../OCCTOverview/code/*.cxx + ./code/*.cxx -RESOURCES += $${SAMPLESROOT}/../OCCTOverview/code/Samples.qrc +RESOURCES += ./code/Samples.qrc RESOURCES += ./src/OCCTOverview.qrc RES_DIR = $$quote($$(RES_DIR)) INCLUDEPATH += $$quote($$(CSF_SampleSources)) INCLUDEPATH += $$quote($$(CSF_OCCTIncludePath)) \ - $${SAMPLESROOT}/../OCCTOverview/code + $${SAMPLESROOT}/qt/OCCTOverview/code OCCT_DEFINES = $$(CSF_DEFINES) diff --git a/samples/qt/OCCTOverview/PACKAGES b/samples/qt/OCCTOverview/PACKAGES deleted file mode 100644 index 0d40a31f87..0000000000 --- a/samples/qt/OCCTOverview/PACKAGES +++ /dev/null @@ -1,2 +0,0 @@ -OCCTOverview/src -/../OCCTOverview/code diff --git a/samples/qt/OCCTOverview/PACKAGES.cmake b/samples/qt/OCCTOverview/PACKAGES.cmake new file mode 100644 index 0000000000..9771c42ac5 --- /dev/null +++ b/samples/qt/OCCTOverview/PACKAGES.cmake @@ -0,0 +1,4 @@ +# Packages for OCCTOverview sample +set(OCCT_OCCTOverview_LIST_OF_PACKAGES + OCCTOverview +) \ No newline at end of file diff --git a/samples/qt/OCCTOverview/code/AdaptorCurve2d_AIS.cxx b/samples/qt/OCCTOverview/code/AdaptorCurve2d_AIS.cxx new file mode 100644 index 0000000000..0fa262ba39 --- /dev/null +++ b/samples/qt/OCCTOverview/code/AdaptorCurve2d_AIS.cxx @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +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_PresentationManager)&, + 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; + } + } + } +} diff --git a/samples/qt/OCCTOverview/code/AdaptorCurve2d_AIS.h b/samples/qt/OCCTOverview/code/AdaptorCurve2d_AIS.h new file mode 100644 index 0000000000..ad66bb4d13 --- /dev/null +++ b/samples/qt/OCCTOverview/code/AdaptorCurve2d_AIS.h @@ -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 +#include +#include +#include + +//! 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_PresentationManager)& 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 diff --git a/samples/qt/OCCTOverview/code/AdaptorCurve_AIS.cxx b/samples/qt/OCCTOverview/code/AdaptorCurve_AIS.cxx new file mode 100644 index 0000000000..18ef438ba3 --- /dev/null +++ b/samples/qt/OCCTOverview/code/AdaptorCurve_AIS.cxx @@ -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 +#include +#include +#include + +void AdaptorCurve_AIS::Compute (const Handle(PrsMgr_PresentationManager)&, + 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; + } + } +} diff --git a/samples/qt/OCCTOverview/code/AdaptorCurve_AIS.h b/samples/qt/OCCTOverview/code/AdaptorCurve_AIS.h new file mode 100644 index 0000000000..f4f377c5b8 --- /dev/null +++ b/samples/qt/OCCTOverview/code/AdaptorCurve_AIS.h @@ -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 +#include + +//! 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_PresentationManager)& 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 diff --git a/samples/qt/OCCTOverview/code/AdaptorPnt2d_AIS.cxx b/samples/qt/OCCTOverview/code/AdaptorPnt2d_AIS.cxx new file mode 100644 index 0000000000..5159a34545 --- /dev/null +++ b/samples/qt/OCCTOverview/code/AdaptorPnt2d_AIS.cxx @@ -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 +#include + +void AdaptorPnt2d_AIS::Compute (const Handle(PrsMgr_PresentationManager)& , + 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); +} diff --git a/samples/qt/OCCTOverview/code/AdaptorPnt2d_AIS.h b/samples/qt/OCCTOverview/code/AdaptorPnt2d_AIS.h new file mode 100644 index 0000000000..e37a2bd672 --- /dev/null +++ b/samples/qt/OCCTOverview/code/AdaptorPnt2d_AIS.h @@ -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 +#include + +//! 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_PresentationManager)& 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 diff --git a/samples/qt/OCCTOverview/code/AdaptorVec_AIS.cxx b/samples/qt/OCCTOverview/code/AdaptorVec_AIS.cxx new file mode 100644 index 0000000000..725e2a53ea --- /dev/null +++ b/samples/qt/OCCTOverview/code/AdaptorVec_AIS.cxx @@ -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 +#include +#include +#include +#include + +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_PresentationManager)& , + 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); + } +} diff --git a/samples/qt/OCCTOverview/code/AdaptorVec_AIS.h b/samples/qt/OCCTOverview/code/AdaptorVec_AIS.h new file mode 100644 index 0000000000..e04711c11b --- /dev/null +++ b/samples/qt/OCCTOverview/code/AdaptorVec_AIS.h @@ -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 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_PresentationManager)& 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 diff --git a/samples/qt/OCCTOverview/code/BaseSample.cxx b/samples/qt/OCCTOverview/code/BaseSample.cxx new file mode 100644 index 0000000000..b0aa8d2ce5 --- /dev/null +++ b/samples/qt/OCCTOverview/code/BaseSample.cxx @@ -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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +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(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; +} diff --git a/samples/qt/OCCTOverview/code/BaseSample.h b/samples/qt/OCCTOverview/code/BaseSample.h new file mode 100644 index 0000000000..20c2470af6 --- /dev/null +++ b/samples/qt/OCCTOverview/code/BaseSample.h @@ -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 + +#include +#include +#include + +//! 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& Get2dObjects() const { return myObject2d; } + + const NCollection_Vector& 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 myObject2d; + NCollection_Vector 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 diff --git a/samples/qt/OCCTOverview/code/DataExchange.xml b/samples/qt/OCCTOverview/code/DataExchange.xml new file mode 100644 index 0000000000..a664a7a3f7 --- /dev/null +++ b/samples/qt/OCCTOverview/code/DataExchange.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/qt/OCCTOverview/code/DataExchangeSamples.cxx b/samples/qt/OCCTOverview/code/DataExchangeSamples.cxx new file mode 100644 index 0000000000..81abc8aad7 --- /dev/null +++ b/samples/qt/OCCTOverview/code/DataExchangeSamples.cxx @@ -0,0 +1,422 @@ +// 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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(NCollection_Vector::Iterator anIter(myObject3d); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); + 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(NCollection_Vector::Iterator anIter(myObject3d); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); + 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(NCollection_Vector::Iterator anIter(myObject3d); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); + 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(NCollection_Vector::Iterator anIter(myObject3d); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); + 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(NCollection_Vector::Iterator anIter(myObject3d); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); + 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(NCollection_Vector::Iterator anIter (myObject3d); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anObject = anIter.Value(); + 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; +} diff --git a/samples/qt/OCCTOverview/code/DataExchangeSamples.h b/samples/qt/OCCTOverview/code/DataExchangeSamples.h new file mode 100644 index 0000000000..5925065717 --- /dev/null +++ b/samples/qt/OCCTOverview/code/DataExchangeSamples.h @@ -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 +#include + +//! 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_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 diff --git a/samples/qt/OCCTOverview/code/Geometry.xml b/samples/qt/OCCTOverview/code/Geometry.xml new file mode 100644 index 0000000000..75133644bb --- /dev/null +++ b/samples/qt/OCCTOverview/code/Geometry.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/qt/OCCTOverview/code/GeometrySamples.cxx b/samples/qt/OCCTOverview/code/GeometrySamples.cxx new file mode 100644 index 0000000000..278e5e1089 --- /dev/null +++ b/samples/qt/OCCTOverview/code/GeometrySamples.cxx @@ -0,0 +1,2027 @@ +// 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 "GeometrySamples.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "AdaptorPnt2d_AIS.h" +#include "AdaptorVec_AIS.h" +#include "AdaptorCurve_AIS.h" +#include "AdaptorCurve2d_AIS.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +void GeometrySamples::ExecuteSample (const TCollection_AsciiString& theSampleName) +{ + Standard_Boolean anIsSamplePresent = Standard_True; + FindSourceCode(theSampleName); + if (theSampleName == "ZeroDimensionObjects3dSample") + ZeroDimensionObjects3dSample(); + else if (theSampleName == "Vectors3dSample") + Vectors3dSample(); + else if (theSampleName == "InfinityLines3dSample") + InfinityLines3dSample(); + else if (theSampleName == "SecondOrderCurves3dSample") + SecondOrderCurves3dSample(); + else if (theSampleName == "PlaneSurfaces3dSample") + PlaneSurfaces3dSample(); + else if (theSampleName == "SecondOrderSurfaces3dSample") + SecondOrderSurfaces3dSample(); + else if (theSampleName == "ZeroDimensionObjects2dSample") + ZeroDimensionObjects2dSample(); + else if (theSampleName == "Vectors2dSample") + Vectors2dSample(); + else if (theSampleName == "InfinityLines2dSample") + InfinityLines2dSample(); + else if (theSampleName == "SecondOrderCurves2dSample") + SecondOrderCurves2dSample(); + else if (theSampleName == "BarycenterPoint3dSample") + BarycenterPoint3dSample(); + else if (theSampleName == "RotatedVector3dSample") + RotatedVector3dSample(); + else if (theSampleName == "MirroredLine3dSample") + MirroredLine3dSample(); + else if (theSampleName == "ScaledEllipse3dSample") + ScaledEllipse3dSample(); + else if (theSampleName == "TransformedCylinder3dSample") + TransformedCylinder3dSample(); + else if (theSampleName == "TranslatedTorus3dSample") + TranslatedTorus3dSample(); + else if (theSampleName == "ConjugateObjects3dSample") + ConjugateObjects3dSample(); + else if (theSampleName == "ProjectionOfPoint3dSample") + ProjectionOfPoint3dSample(); + else if (theSampleName == "MinimalDistance3dSample") + MinimalDistance3dSample(); + else if (theSampleName == "MirroredAxis2dSample") + MirroredAxis2dSample(); + else if (theSampleName == "TransformedEllipse2dSample") + TransformedEllipse2dSample(); + else if (theSampleName == "ConjugateObjects2dSample") + ConjugateObjects2dSample(); + else if (theSampleName == "Intersection3dSample") + Intersection3dSample(); + else if (theSampleName == "TranslatedPoint2dSample") + TranslatedPoint2dSample(); + else if (theSampleName == "RotatedDirection2dSample") + RotatedDirection2dSample(); + else if (theSampleName == "Tangent2dSample") + Tangent2dSample(); + else if (theSampleName == "ProjectionOfPoint2dSample") + ProjectionOfPoint2dSample(); + else if (theSampleName == "MinimalDistance2dSample") + MinimalDistance2dSample(); + else if (theSampleName == "Intersection2dSample") + Intersection2dSample(); + else if (theSampleName == "PointInfo3dSample") + PointInfo3dSample(); + else if (theSampleName == "EllipseInfo3dSample") + EllipseInfo3dSample(); + else if (theSampleName == "PointInfo2dSample") + PointInfo2dSample(); + else if (theSampleName == "CircleInfo2dSample") + CircleInfo2dSample(); + else if (theSampleName == "SecondOrderCurves3dSample") + SecondOrderCurves3dSample(); + else if (theSampleName == "FreeStyleCurves3dSample") + FreeStyleCurves3dSample(); + else if (theSampleName == "AnalyticalSurfaces3dSample") + AnalyticalSurfaces3dSample(); + else if (theSampleName == "FreeStyleSurfaces3dSample") + FreeStyleSurfaces3dSample(); + else if (theSampleName == "SecondOrderCurves2dSample") + SecondOrderCurves2dSample(); + else if (theSampleName == "FreeStyleCurves2dSample") + FreeStyleCurves2dSample(); + else if (theSampleName == "TrimmedCurve3dSample") + TrimmedCurve3dSample(); + else if (theSampleName == "OffsetCurve3dSample") + OffsetCurve3dSample(); + else if (theSampleName == "BSplineFromCircle3dSample") + BSplineFromCircle3dSample(); + else if (theSampleName == "TrimmedSurface3dSample") + TrimmedSurface3dSample(); + else if (theSampleName == "OffsetSurface3dSample") + OffsetSurface3dSample(); + else if (theSampleName == "ExtrusionSurface3dSample") + ExtrusionSurface3dSample(); + else if (theSampleName == "RevolutionSurface3dSample") + RevolutionSurface3dSample(); + else if (theSampleName == "TrimmedCurve2dSample") + TrimmedCurve2dSample(); + else if (theSampleName == "OffsetCurve2dSample") + OffsetCurve2dSample(); + else if (theSampleName == "BoundingBoxOfSurface3dSample") + BoundingBoxOfSurface3dSample(); + else if (theSampleName == "BoundingBoxOfCurves3dSample") + BoundingBoxOfCurves3dSample(); + else if (theSampleName == "BoundingBoxOfCurves2dSample") + BoundingBoxOfCurves2dSample(); + else if (theSampleName == "DumpCircleInfoSample") + DumpCircleInfoSample(); + else if (theSampleName == "DumpBSplineCurveInfoSample") + DumpBSplineCurveInfoSample(); + else + { + myResult << "No function found: " << theSampleName; + myCode += TCollection_AsciiString("No function found: ") + theSampleName; + anIsSamplePresent = Standard_False; + } + myIsProcessed = anIsSamplePresent; +} + +void GeometrySamples::DisplayPnt (const gp_Pnt2d& thePnt2d, const TCollection_AsciiString& theText, + Aspect_TypeOfMarker theMarker, Standard_Real theDistance) +{ + gp_Pnt aPnt(thePnt2d.X(), thePnt2d.Y(), 0.0); + Handle(Geom_CartesianPoint) aGeomPoint = new Geom_CartesianPoint(aPnt); + Handle(AIS_Point) anAisPoint = new AIS_Point(aGeomPoint); + anAisPoint->SetMarker(theMarker); + myObject2d.Append(anAisPoint); + Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel(); + aPntLabel->SetText(theText); + aPntLabel->SetPosition(gp_Pnt(aPnt.X(), aPnt.Y() + theDistance, aPnt.Z())); + myObject2d.Append(aPntLabel); +} +void GeometrySamples::DisplayPnt (const gp_Pnt& thePnt, const TCollection_AsciiString& theText, + Aspect_TypeOfMarker theMarker, Standard_Real theDistance) +{ + Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(thePnt); + Handle(AIS_Point) anAisPoint = new AIS_Point(aPoint); + anAisPoint->SetMarker(theMarker); + myObject3d.Append(anAisPoint); + Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel(); + aPntLabel->SetText(theText); + aPntLabel->SetPosition(gp_Pnt(thePnt.X(), thePnt.Y(), thePnt.Z() + theDistance)); + myObject3d.Append(aPntLabel); +} + +void GeometrySamples::ZeroDimensionObjects3dSample() +{ + // gp_Pnt describes a point in 3D space. A Geom_CartesianPoint is defined by + // a gp_Pnt point, with its three Cartesian coordinates X, Y and Z. + gp_Pnt aCoordPnt(10.0, 20.0, 30.0); + Handle(Geom_CartesianPoint) aCoordGeomPoint = new Geom_CartesianPoint(aCoordPnt); + Handle(AIS_Point) aCoordAisPoint = new AIS_Point(aCoordGeomPoint); + myObject3d.Append(aCoordAisPoint); + + Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel(); + aPntLabel->SetText(" gp_Pnt"); + aPntLabel->SetPosition(gp_Pnt(aCoordPnt.X(), aCoordPnt.Y(), aCoordPnt.Z() + 5.0)); + myObject3d.Append(aPntLabel); + myResult << "gp_Pnt was created" << std::endl; + + // gp_XYZ class describes a Cartesian coordinate entity in 3D space (X,Y,Z). + // This entity is used for algebraic calculation. + // This entity can be transformed with a "Trsf" or a "GTrsf" from package "gp". + // It is used in vectorial computations or for holding this type of information + // in data structures. + gp_XYZ aXyz1(10.0, 20.0, 30.0); + gp_XYZ aXyz2(20.0, 10.0, 30.0); + gp_XYZ aXyzSum = aXyz1 + aXyz2; + gp_Pnt aSumPnt(aXyzSum); + Handle(Geom_CartesianPoint) aXyzGeomPoint = new Geom_CartesianPoint(aSumPnt); + Handle(AIS_Point) aSumAisPoint = new AIS_Point(aXyzGeomPoint); + myObject3d.Append(aSumAisPoint); + + Handle(AIS_TextLabel) aXyzLabel = new AIS_TextLabel(); + aXyzLabel->SetText(" gp_XYZ"); + aXyzLabel->SetPosition(gp_Pnt(aXyzSum.X(), aXyzSum.Y(), aXyzSum.Z() + 5.0)); + myObject3d.Append(aXyzLabel); + myResult << "gp_XYZ was created" << std::endl; +} + +void GeometrySamples::Vectors3dSample() +{ + gp_Pnt aPnt1(0.0, 0.0, 0.0); + gp_Pnt aPnt2(5.0, 0.0, 0.0); + + // gp_Vec defines a non-persistent vector in 3D space. + gp_Vec aVec(aPnt1, aPnt2); + Handle(AdaptorVec_AIS) aVecAIS = new AdaptorVec_AIS(aPnt1, aVec, 0.5); + aVecAIS->SetText(" gp_Vec"); + myObject3d.Append(aVecAIS); + myResult << "gp_Vec magnitude: " << aVec.Magnitude() << std::endl; + + // Describes a unit vector in 3D space. + // This unit vector is also called "Direction". + // See Also gce_MakeDir which provides functions for more complex unit vector + // constructions Geom_Direction which provides additional functions + // for constructing unit vectors and works, in particular, + // with the parametric equations of unit vectors. + gp_Dir aDir(aVec); + Handle(AdaptorVec_AIS) aDirAIS = new AdaptorVec_AIS(gp_Pnt(0.0, 0.0, 10.0), aDir, 1.0, 0.5); + aDirAIS->SetText(" gp_Dir"); + myObject3d.Append(aDirAIS); + myResult << "gp_Dir coordinates: X: " << aDir.X() << ", Y: " << aDir.Y() << ", Z: " << aDir.Z() << std::endl; +} + +void GeometrySamples::InfinityLines3dSample() +{ + gp_Pnt aBasePoint(0.0, 0.0, 0.0); + gp_Dir aX_Direction(1.0, 0.0, 0.0); + gp_Dir anY_Direction(0.0, 1.0, 0.0); + gp_Dir aZ_Direction(0.0, 0.0, 1.0); + + // Describes an axis in 3D space. + gp_Ax1 anAxis1(aBasePoint, aZ_Direction); + Handle(AdaptorVec_AIS) anAx1Ais = new AdaptorVec_AIS(anAxis1.Location(), anAxis1.Direction(), 1.0, 0.3); + anAx1Ais->SetText(" gp_Ax1"); + myObject3d.Append(anAx1Ais); + myResult << "gp_Ax1 was created" << std::endl << std::endl; + + // Describes a right - handed coordinate system in 3D space. + aBasePoint.SetCoord(0.0, 0.0, 3.0); + gp_Ax2 anAxis2(aBasePoint, aZ_Direction); + Handle(AdaptorVec_AIS) aAx2AisZ = new AdaptorVec_AIS(anAxis2.Location(), anAxis2.Direction(), 1.0, 0.3); + aAx2AisZ->SetText(" gp_Ax2 Z"); + myObject3d.Append(aAx2AisZ); + Handle(AdaptorVec_AIS) aAx2AisX = new AdaptorVec_AIS(anAxis2.Location(), anAxis2.XDirection(), 1.0, 0.3); + aAx2AisX->SetText(" gp_Ax2 X"); + myObject3d.Append(aAx2AisX); + Handle(AdaptorVec_AIS) aAx2AisY = new AdaptorVec_AIS(anAxis2.Location(), anAxis2.YDirection(), 1.0, 0.3); + aAx2AisY->SetText(" gp_Ax2 Y"); + myObject3d.Append(aAx2AisY); + myResult << "gp_Ax2 was created" << std::endl; + + // Describes a coordinate system in 3D space.Unlike a gp_Ax2 coordinate system, + // a gp_Ax3 can be right - handed("direct sense") or left - handed("indirect sense"). + gp_Ax3 anAxis3(gp_XYZ(0.0, 0.0, 6.0), aZ_Direction, aX_Direction); + anAxis3.YReverse(); + Handle(AdaptorVec_AIS) anAx3AisZ = new AdaptorVec_AIS(anAxis3.Location(), anAxis3.Direction(), 1.0, 0.3); + anAx3AisZ->SetText(" gp_Ax3 Z"); + myObject3d.Append(anAx3AisZ); + Handle(AdaptorVec_AIS) anAx3AisX = new AdaptorVec_AIS(anAxis3.Location(), anAxis3.XDirection(), 1.0, 0.3); + anAx3AisX->SetText(" gp_Ax3 X"); + myObject3d.Append(anAx3AisX); + Handle(AdaptorVec_AIS) anAx3AisY = new AdaptorVec_AIS(anAxis3.Location(), anAxis3.YDirection(), 1.0, 0.3); + anAx3AisY->SetText(" gp_Ax3 Y"); + myObject3d.Append(anAx3AisY); + + myResult << "gp_Ax3 was created" << std::endl; + const gp_Dir& anAxis3_xDir = anAxis3.XDirection(); + const gp_Dir& anAxis3_yDir = anAxis3.YDirection(); + myResult << "gp_Ax3 X direction: " << anAxis3_xDir.X() << " " << anAxis3_xDir.Y() << " " << anAxis3_xDir.Z() << std::endl; + myResult << "gp_Ax3 Y direction: " << anAxis3_yDir.X() << " " << anAxis3_yDir.Y() << " " << anAxis3_yDir.Z() << std::endl; + TCollection_AsciiString aDirectionDescription; + if (anAxis3.Direct()) + { + aDirectionDescription = "anAxis3 is a right-handed axis system"; + } + else + { + aDirectionDescription = "anAxis3 is a left-handed axis system"; + } + myResult << aDirectionDescription << std::endl << std::endl; + + // Describes a line in 3D space. A line is positioned in space with an axis + // (a gp_Ax1 object) which gives it an origin and a unit vector. + gp_Lin aLine(gp_Pnt(5.0, 0.0, 0.0), gp_Dir(0.0, 1.0, 0.0)); + Handle(AdaptorVec_AIS) anLineAis = new AdaptorVec_AIS(aLine.Location(), aLine.Direction(), 8.0); + anLineAis->SetText(" gp_Lin"); + myObject3d.Append(anLineAis); + myResult << "gp_Lin was created" << std::endl << std::endl; +} + +void GeometrySamples::SecondOrderCurves3dSample() +{ + gp_Ax2 anAxis2(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)); + gp_Circ aCirc(anAxis2, 10.0); + Handle(Geom_Circle) aGeomCircle = new Geom_Circle(aCirc); + Handle(AIS_Circle) anAisCircle = new AIS_Circle(aGeomCircle); + myObject3d.Append(anAisCircle); + + // Describes an ellipse in 3D space. An ellipse is defined by its major and minor + // radii and positioned in space with a coordinate system (a gp_Ax2 object) + gp_Elips anElips(anAxis2.Translated(gp_Vec(0.0, 0.0, 10.0)), 20.0, 10.0); + Handle(Geom_Ellipse) aGeomEllipse = new Geom_Ellipse(anElips); + Handle(AdaptorCurve_AIS) anAisEllipce = new AdaptorCurve_AIS(aGeomEllipse); + myObject3d.Append(anAisEllipce); + + // Describes a parabola in 3D space. A parabola is defined by its focal length + // (that is, the distance between its focus and apex) and positioned in space with + // a coordinate system (a gp_Ax2 object) + gp_Parab aParab(anAxis2.Translated(gp_Vec(0.0, 0.0, 20.0)), 2.0); + Handle(Geom_Parabola) aGeomParabola = new Geom_Parabola(aParab); + Handle(Geom_TrimmedCurve) aTrimmedParabola = new Geom_TrimmedCurve(aGeomParabola, 20.0, -20.0); + Handle(AdaptorCurve_AIS) anAisParabola = new AdaptorCurve_AIS(aTrimmedParabola); + myObject3d.Append(anAisParabola); + + // Describes a branch of a hyperbola in 3D space. A hyperbola is defined by its major + // and minor radii and positioned in space with a coordinate system (a gp_Ax2 object) + gp_Hypr aHypr(anAxis2.Translated(gp_Vec(0.0, 0.0, 30.0)), 20.0, 10.0); + Handle(Geom_Hyperbola) aGeomHyperbola = new Geom_Hyperbola(aHypr); + Handle(Geom_TrimmedCurve) aTrimmedHyperbola = new Geom_TrimmedCurve(aGeomHyperbola, 2.0, -2.0); + Handle(AdaptorCurve_AIS) anAisHyperbola = new AdaptorCurve_AIS(aTrimmedHyperbola); + myObject3d.Append(anAisHyperbola); +} + +void GeometrySamples::PlaneSurfaces3dSample() +{ + // Describes a plane.A plane is positioned in space with a coordinate system(a gp_Ax3 object), + // such that the plane is defined by the origin, "X Direction" and "Y Direction" of this + // coordinate system, which is the "local coordinate system" of the plane.The "main Direction" + // of the coordinate system is a vector normal to the plane. + gp_Pln aPln(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)); + Handle(Geom_Plane) aPlane = new Geom_Plane(aPln); + Handle(AIS_Plane) anAisPlane = new AIS_Plane(aPlane, aPln.Location(), + gp_Pnt(10.0, 10.0, 0.0), + gp_Pnt(-10.0, -10.0, 0.0), + Standard_False); + myObject3d.Append(anAisPlane); + + // Describes an infinite cylindrical surface.A cylinder is defined by its radius and positioned + // in space with a coordinate system(a gp_Ax3 object), the "main Axis" of which is the axis of + // the cylinder.This coordinate system is the "local coordinate system" of the cylinder. + gp_Cylinder aCylinder(gp_Ax3(gp_Pnt(0.0, 0.0, 10.0), gp_Dir(0.0, 0.0, 1.0)), 10.0); + Handle(Geom_CylindricalSurface) aCylindricalSurface = new Geom_CylindricalSurface(aCylinder); + Handle(AIS_Shape) anAisCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace( + aCylindricalSurface, 0.0, 2.0*M_PI, 0.0, 10.0, Precision::Confusion()).Shape()); + myObject3d.Append(anAisCylinder); + + // Defines an infinite conical surface. A cone is defined by its half-angle (can be negative) at + // the apex and positioned in space with a coordinate system (a gp_Ax3 object) and a "reference radius" + gp_Cone aCone(gp_Ax3(gp_Pnt(0.0, 0.0, 30.0), gp_Dir(0.0, 0.0, 1.0)), 0.25*M_PI, 0.0); + Handle(Geom_ConicalSurface) aConicalSurface = new Geom_ConicalSurface(aCone); + Handle(AIS_Shape) anAisCone = new AIS_Shape(BRepBuilderAPI_MakeFace( + aConicalSurface, 0.0, 2.0*M_PI, 0.0, 20.0, Precision::Confusion()).Shape()); + myObject3d.Append(anAisCone); +} + +void GeometrySamples::SecondOrderSurfaces3dSample() +{ + gp_Sphere aSphere(gp_Ax3(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)), 10.0); + Handle(Geom_SphericalSurface) aSphericalSurface = new Geom_SphericalSurface(aSphere); + Handle(AIS_Shape) anAisSphere = new AIS_Shape(BRepBuilderAPI_MakeFace( + aSphericalSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); + myObject3d.Append(anAisSphere); + + gp_Torus aTorus(gp_Ax3(gp_Pnt(0.0, 0.0, 20.0), gp_Dir(0.0, 0.0, 1.0)), 40.0, 10.0); + Handle(Geom_ToroidalSurface) aToroidalSurface = new Geom_ToroidalSurface(aTorus); + Handle(AIS_Shape) anAisTorus = new AIS_Shape(BRepBuilderAPI_MakeFace( + aToroidalSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); + myObject3d.Append(anAisTorus); +} + +void GeometrySamples::ZeroDimensionObjects2dSample() +{ + // Defines a non-persistent 2D Cartesian point. + gp_Pnt2d aCoordPnt(10.0, 20.0); + Handle(Geom2d_CartesianPoint) aCoordGeomPoint = new Geom2d_CartesianPoint(aCoordPnt); + Handle(AdaptorPnt2d_AIS) aCoordAisPoint = new AdaptorPnt2d_AIS(aCoordGeomPoint); + myObject2d.Append(aCoordAisPoint); + + Handle(AIS_TextLabel) aPntLabel = new AIS_TextLabel(); + aPntLabel->SetText("gp_Pnt2d"); + aPntLabel->SetPosition(gp_Pnt(aCoordPnt.X(), aCoordPnt.Y() + 0.5, 0.0)); + myObject2d.Append(aPntLabel); + myResult << "gp_Pnt was created" << std::endl; + + // This class describes a Cartesian coordinate entity in 2D space{ X,Y }. + // This class is non persistent.This entity used for algebraic calculation. + // An XY can be transformed with a Trsf2d or a GTrsf2d from package gp. + // It is used in vectorial computations or for holding this type of information in data structures. + gp_XY aXy(20.0, 10.0); + Handle(Geom2d_CartesianPoint) aXyGeomPoint = new Geom2d_CartesianPoint(aXy); + Handle(AdaptorPnt2d_AIS) aXyAisPoint = new AdaptorPnt2d_AIS(aXyGeomPoint); + myObject2d.Append(aXyAisPoint); + + Handle(AIS_TextLabel) aXyLabel = new AIS_TextLabel(); + aXyLabel->SetText(" gp_XY"); + aXyLabel->SetPosition(gp_Pnt(aXy.X(), aXy.Y() + 0.5, 0.0)); + myObject2d.Append(aXyLabel); + myResult << "gp_XY was created" << std::endl; +} + +void GeometrySamples::Vectors2dSample() +{ + // Describes a unit vector in the plane (2D space). + // This unit vector is also called "Direction". + gp_Dir2d aDir(3.0, 4.0); + Handle(AdaptorVec_AIS) anAisDir = new AdaptorVec_AIS(gp_Pnt2d(0.0, 0.0), aDir, 1.0, 0.3); + anAisDir->SetText(" gp_Dir2d"); + myObject2d.Append(anAisDir); + myResult << "gp_Dir2d coordinates: X: " << aDir.X() << ", Y: " << aDir.Y() << std::endl; + + // Defines a non-persistent vector in 2D space. + gp_Vec2d aVec(aDir); + aVec = aVec * 2; + Handle(AdaptorVec_AIS) anAisVec = new AdaptorVec_AIS(gp_Pnt2d(0.0, 5.0), aVec, 0.3); + anAisVec->SetText(" gp_Vec2d"); + myObject2d.Append(anAisVec); + myResult << "gp_Vec2d magnitude: " << aVec.Magnitude() << std::endl; +} + +void GeometrySamples::InfinityLines2dSample() +{ + // Describes an axis in the plane (2D space) + gp_Ax2d anAx2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 0.0)); + Handle(AdaptorVec_AIS) anAisAx2d = new AdaptorVec_AIS(anAx2d.Location(), anAx2d.Direction(), 1.0, 0.3); + anAisAx2d->SetText(" gp_Ax2d"); + myObject2d.Append(anAisAx2d); + + // Describes a coordinate system in a plane (2D space). + gp_Ax22d anAx22d(gp_Pnt2d(0.0, 2.0), gp_Dir2d(1.0, 1.0), Standard_False); + Handle(AdaptorVec_AIS) anAisAx2d_X = new AdaptorVec_AIS(anAx22d.Location(), anAx22d.XDirection(), 1.0, 0.3); + anAisAx2d_X->SetText(" gp_Ax2d X"); + myObject2d.Append(anAisAx2d_X); + Handle(AdaptorVec_AIS) anAisAx2d_Y = new AdaptorVec_AIS(anAx22d.Location(), anAx22d.YDirection(), 1.0, 0.3); + anAisAx2d_Y->SetText(" gp_Ax2d Y"); + myObject2d.Append(anAisAx2d_Y); + + // Describes a line in 2D space. A line is positioned in the plane with an axis (a gp_Ax2d object) which gives + // the line its origin and unit vector. A line and an axis are similar objects, thus, + // we can convert one into the other. A line provides direct access to the majority of the edit and query + // functions available on its positioning axis. + gp_Lin2d aLin2d(gp_Pnt2d(2.0, 4.0), gp_Dir2d(0.0, -1.0)); + Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aLin2d.Location(), aLin2d.Direction(), 1.0, 0.3); + anAisLin->SetText(" gp_Lin2d"); + myObject2d.Append(anAisLin); +} + +void GeometrySamples::SecondOrderCurves2dSample() +{ + // Describes a circle in the plane (2D space). A circle is defined by its radius + // and positioned in the plane with a coordinate system (a gp_Ax22d object) + gp_Circ2d aCirc2d; + aCirc2d.SetLocation(gp_Pnt2d(0.0, 0.0)); + aCirc2d.SetRadius(10.0); + Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(aCirc2d); + Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle, Aspect_TOL_SOLID); + myObject2d.Append(anAisCirc); + + // Describes an ellipse in the plane (2D space). An ellipse is defined by its major + // and minor radii and positioned in the plane with a coordinate system (a gp_Ax22d object) + gp_Elips2d anElips(gp_Ax2d(gp_Pnt2d(0.0, 30.0), gp_Dir2d(1.0, 0.0)), 20.0, 10.0); + Handle(Geom2d_Ellipse) aGeomEllipse = new Geom2d_Ellipse(anElips); + Handle(AdaptorCurve2d_AIS) anAisEllipse = new AdaptorCurve2d_AIS(aGeomEllipse, Aspect_TOL_DASH); + myObject2d.Append(anAisEllipse); + + // Describes a parabola in the plane (2D space). A parabola is defined by its focal length + // (that is, the distance between its focus and apex) and positioned in the plane with + // a coordinate system (a gp_Ax22d object) + gp_Parab2d aParab2d(gp_Ax2d(gp_Pnt2d(20.0, 0.0), gp_Dir2d(1.0, 0.0)), 10.0); + Handle(Geom2d_Parabola) aGeomParabola = new Geom2d_Parabola(aParab2d); + Handle(Geom2d_TrimmedCurve) aTrimmedParabola = new Geom2d_TrimmedCurve(aGeomParabola, 40.0, -40.0); + Handle(AdaptorCurve2d_AIS) anAisParabola = new AdaptorCurve2d_AIS(aTrimmedParabola, Aspect_TOL_DOT); + myObject2d.Append(anAisParabola); + + // Describes a branch of a hyperbola in the plane (2D space). A hyperbola is defined by its major and + // minor radii, and positioned in the plane with a coordinate system (a gp_Ax22d object) + gp_Hypr2d aHypr2d(gp_Ax2d(gp_Pnt2d(20.0, 0.0), gp_Dir2d(1.0, 0.0)), 20.0, 10.0); + Handle(Geom2d_Hyperbola) aGeomHyperbola = new Geom2d_Hyperbola(aHypr2d); + Handle(Geom2d_TrimmedCurve) aTrimmedHyperbola = new Geom2d_TrimmedCurve(aGeomHyperbola, 2.0, -2.0); + Handle(AdaptorCurve2d_AIS) anAisHyperbola = new AdaptorCurve2d_AIS(aTrimmedHyperbola, Aspect_TOL_DOTDASH); + myObject2d.Append(anAisHyperbola); +} + +void GeometrySamples::BarycenterPoint3dSample() +{ + // Barycenter of 2 points + gp_Pnt aPnt1(11, 2, 3); + gp_Pnt aPnt2(13, 4, 5); + gp_Pnt aBarycenterPnt2 = aPnt1; + Standard_Real anAlpha = 3; + Standard_Real anBeta = 7; + // Assigns the result of the following expression to this point: + // (Alpha*this + Beta*P) / (Alpha + Beta) + aBarycenterPnt2.BaryCenter(anAlpha, aPnt2, anBeta); + DisplayPnt(aPnt1, "Pnt1", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt2, "Pnt2", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aBarycenterPnt2, "Barycenter Pnt", Aspect_TOM_O_PLUS, 0.5); + + // BaryCenter of an array of point + gp_Pnt aP1(0, 0, 5); + gp_Pnt aP2(1, 2, 3); + gp_Pnt aP3(2, 3, -2); + gp_Pnt aP4(4, 3, 5); + gp_Pnt aP5(5, 5, 4); + TColgp_Array1OfPnt aPntArray(1, 5); + aPntArray.SetValue(1, aP1); + aPntArray.SetValue(2, aP2); + aPntArray.SetValue(3, aP3); + aPntArray.SetValue(4, aP4); + aPntArray.SetValue(5, aP5); + + Standard_Real Tolerance = 8; + GProp_PEquation aPEquation(aPntArray, Tolerance); + + gp_Pnt aBarycenterPnt5; // P declaration + bool isPoint = false; + if (aPEquation.IsPoint()) + { + isPoint = true; + aBarycenterPnt5 = aPEquation.Point(); + myResult << "GProp_PEquation is a point" << std::endl; + } + else + { + isPoint = false; + myResult << "GProp_PEquation is not a point" << std::endl; + } + + if (aPEquation.IsLinear()) + { + /*... */ + } + if (aPEquation.IsPlanar()) + { + /*... */ + } + if (aPEquation.IsSpace()) + { + /*... */ + } + + const TCollection_AsciiString aPointName("P"); + for (Standard_Integer i = aPntArray.Lower(); i <= aPntArray.Upper(); i++) + { + TCollection_AsciiString aString(i); + aString = aPointName + aString; + DisplayPnt(aPntArray(i), aString, Aspect_TOM_STAR, 0.5); + } + + DisplayPnt(aBarycenterPnt5, "Barycenter of 5 points", Aspect_TOM_O_STAR, 0.5); + myResult << " IsPoint = "; + if (isPoint) + { + myResult << "True --> " << " P ( " << aBarycenterPnt5.X() << aBarycenterPnt5.Y() << aBarycenterPnt5.Z() << " );" << std::endl; + } + else + { + myResult << "False"; + } + myResult << std::endl << " IsLinear = " << (aPEquation.IsLinear() ? "True" : "False"); + myResult << std::endl << " IsPlanar = " << (aPEquation.IsPlanar() ? "True" : "False"); + myResult << std::endl << " IsSpace = " << (aPEquation.IsSpace() ? "True" : "False"); +} + +void GeometrySamples::RotatedVector3dSample() +{ + gp_Vec aBaseVec(0.0, 0.0, 10.0); + gp_Pnt aZeroPnt(0.0, 0.0, 0.0); + gp_Vec aRotatedVec = aBaseVec.Rotated(gp_Ax1(aZeroPnt, gp_Dir(1.0, 0.0, 0.0)), M_PI_4); + + Handle(AdaptorVec_AIS) aBaseVecAIS = new AdaptorVec_AIS(aZeroPnt, aBaseVec); + aBaseVecAIS->SetText(" Base vector"); + myObject3d.Append(aBaseVecAIS); + Handle(AdaptorVec_AIS) aRotatedVecAIS = new AdaptorVec_AIS(aZeroPnt, aRotatedVec); + aRotatedVecAIS->SetText(" Rotated vector"); + myObject3d.Append(aRotatedVecAIS); + Standard_Real anAdgle = aBaseVec.Angle(aRotatedVec)*180.0 / M_PI; + myResult << "An angle between vectors = " << anAdgle << std::endl; +} + +void GeometrySamples::MirroredLine3dSample() +{ + gp_Lin aBaseLin(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(1.0, 1.0, 1.0)); + gp_Ax2 aXyzAxis; + gp_Lin aMirroredLin = aBaseLin.Mirrored(aXyzAxis); + + Handle(AdaptorVec_AIS) aBaseLineAis = new AdaptorVec_AIS(aBaseLin.Location(), aBaseLin.Direction(), 8.0); + aBaseLineAis->SetText(" Base Line"); + myObject3d.Append(aBaseLineAis); + Handle(AdaptorVec_AIS) aMirroredLineAis = new AdaptorVec_AIS(aMirroredLin.Location(), aMirroredLin.Direction(), 8.0); + aMirroredLineAis->SetText(" Mirrored Line"); + myObject3d.Append(aMirroredLineAis); + Handle(AIS_Plane) anAisPlane = new AIS_Plane (new Geom_Plane(gp_Ax3(aXyzAxis)), aXyzAxis.Location(), + gp_Pnt(10.0, 10.0, 0.0), gp_Pnt(-10.0, -10.0, 0.0), Standard_False); + myObject3d.Append(anAisPlane); + Standard_Real anAdgle = aBaseLin.Angle(aMirroredLin)*180.0 / M_PI; + myResult << "An angle between lines = " << anAdgle << std::endl; +} + +void GeometrySamples::ScaledEllipse3dSample() +{ + gp_Ax2 anAxis2(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)); + gp_Elips anBaseElips(anAxis2, 20.0, 10.0); + gp_Elips anScaledElips = anBaseElips.Scaled(gp_Pnt(), 2.5); + + Handle(Geom_Ellipse) aBaseGeomEllipse = new Geom_Ellipse(anBaseElips); + Handle(AdaptorCurve_AIS) anAisBaseEllipce = new AdaptorCurve_AIS(aBaseGeomEllipse); + myObject3d.Append(anAisBaseEllipce); + + Handle(Geom_Ellipse) aScaledGeomEllipse = new Geom_Ellipse(anScaledElips); + Handle(AdaptorCurve_AIS) anAisScaledEllipce = new AdaptorCurve_AIS(aScaledGeomEllipse); + myObject3d.Append(anAisScaledEllipce); +} + +void GeometrySamples::TransformedCylinder3dSample() +{ + gp_Cylinder aBaseCylinder(gp_Ax3(), 10.0); + gp_Trsf aRotTrsf; + aRotTrsf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(1.0, 0.0, 0.0)), M_PI_2); + gp_Trsf aScaleTrsf; + aScaleTrsf.SetScale(gp_Pnt(), 1.5); + gp_Trsf aTranslTrsf; + aTranslTrsf.SetTranslation(gp_Vec(30.0, 0.0, 0.0)); + gp_Trsf aComplexTrsf = aRotTrsf * aScaleTrsf * aTranslTrsf; + gp_Cylinder aTransfCylinder = aBaseCylinder.Transformed(aComplexTrsf); + + Handle(Geom_CylindricalSurface) aBaseCylinderSurface = new Geom_CylindricalSurface(aBaseCylinder); + Handle(AIS_Shape) anAisBaseCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace( + aBaseCylinderSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); + myObject3d.Append(anAisBaseCylinder); + Handle(Geom_CylindricalSurface) aTransfCylinderSurface = new Geom_CylindricalSurface(aTransfCylinder); + Handle(AIS_Shape) anAisTransfCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace( + aTransfCylinderSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); + myObject3d.Append(anAisTransfCylinder); +} + +void GeometrySamples::TranslatedTorus3dSample() +{ + gp_Torus aBaseTorus(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 40.0, 10.0); + gp_Torus aTranslatedTorus = aBaseTorus.Translated(gp_Vec(70.0, 70.0, 70.0)); + + Handle(Geom_ToroidalSurface) aBaseSurface = new Geom_ToroidalSurface(aBaseTorus); + Handle(AIS_Shape) anAisBaseShape = new AIS_Shape(BRepBuilderAPI_MakeFace( + aBaseSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); + myObject3d.Append(anAisBaseShape); + Handle(Geom_ToroidalSurface) aTranslSurface = new Geom_ToroidalSurface(aTranslatedTorus); + Handle(AIS_Shape) anAisTranslShape = new AIS_Shape(BRepBuilderAPI_MakeFace( + aTranslSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); + myObject3d.Append(anAisTranslShape); +} + +void GeometrySamples::ConjugateObjects3dSample() +{ + gp_Hypr aHypr(gp_Ax2(), 20.0, 10.0); + gp_Ax1 anAsymptote1 = aHypr.Asymptote1(); + gp_Ax1 anAsymptote2 = aHypr.Asymptote2(); + gp_Ax1 aDirectrix1 = aHypr.Directrix1(); + gp_Ax1 aDirectrix2 = aHypr.Directrix2(); + gp_Pnt aFocus1 = aHypr.Focus1(); + gp_Pnt aFocus2 = aHypr.Focus2(); + gp_Pnt aLocation = aHypr.Location(); + + Handle(AdaptorVec_AIS) anAsy1AIS = new AdaptorVec_AIS(anAsymptote1.Location(), gp_Vec(anAsymptote1.Direction())*10.0); + anAsy1AIS->SetText(" Asymptote 1"); + myObject3d.Append(anAsy1AIS); + Handle(AdaptorVec_AIS) anAsy2AIS = new AdaptorVec_AIS(anAsymptote2.Location(), gp_Vec(anAsymptote2.Direction())*10.0); + anAsy2AIS->SetText(" Asymptote 2"); + myObject3d.Append(anAsy2AIS); + Handle(AdaptorVec_AIS) anDir1AIS = new AdaptorVec_AIS(aDirectrix1.Location(), gp_Vec(aDirectrix1.Direction())*10.0); + anDir1AIS->SetText(" Directrix 1"); + myObject3d.Append(anDir1AIS); + Handle(AdaptorVec_AIS) anDir2AIS = new AdaptorVec_AIS(aDirectrix2.Location(), gp_Vec(aDirectrix2.Direction())*10.0); + anDir2AIS->SetText(" Directrix 2"); + myObject3d.Append(anDir2AIS); + + DisplayPnt(aFocus1, "Focus 1", Aspect_TOM_PLUS, 2.0); + DisplayPnt(aFocus2, "Focus 2", Aspect_TOM_PLUS, 2.0); + DisplayPnt(aLocation, "Location", Aspect_TOM_O_STAR, 2.0); + + Handle(Geom_Hyperbola) aGeomHyperbola = new Geom_Hyperbola(aHypr); + Handle(Geom_TrimmedCurve) aTrimmedHyperbola = new Geom_TrimmedCurve(aGeomHyperbola, 2.0, -2.0); + Handle(AdaptorCurve_AIS) anAisHyperbola = new AdaptorCurve_AIS(aTrimmedHyperbola); + myObject3d.Append(anAisHyperbola); +} + +void GeometrySamples::ProjectionOfPoint3dSample() +{ + gp_Sphere aSphere(gp_Ax3(), 10.0); + gp_Pnt aBasePnt(20.0, 20.0, 20.0); + // A projection point in surface coordinate + gp_Pnt2d aPrjPnt2d = ProjLib::Project(aSphere, aBasePnt); + gp_Pnt aPrjPnt = ElSLib::Value(aPrjPnt2d.X(), aPrjPnt2d.Y(), aSphere); + + DisplayPnt(aBasePnt, "Base point", Aspect_TOM_PLUS, 2.0); + DisplayPnt(aPrjPnt, "Projection point", Aspect_TOM_O_STAR, 2.0); + Handle(Geom_SphericalSurface) aSphericalSurface = new Geom_SphericalSurface(aSphere); + Handle(AIS_Shape) anAisSphere = new AIS_Shape(BRepBuilderAPI_MakeFace( + aSphericalSurface, 0.0, 2.0*M_PI, 0.0, 2.0*M_PI, Precision::Confusion()).Shape()); + myObject3d.Append(anAisSphere); +} + +void GeometrySamples::MinimalDistance3dSample() +{ + gp_Cylinder aCylinder(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 10.0); + gp_Lin aLine(gp_Pnt(20.0, 0.0, 5.0), gp_Dir(0.0, 1.0, 0.0)); + Extrema_ExtElCS anExtrema_ExtElCS(aLine, aCylinder); + + if (anExtrema_ExtElCS.IsDone()) + { + NCollection_Array1 aVecArray(1, anExtrema_ExtElCS.NbExt()); + NCollection_Array1 aPntArray(1, anExtrema_ExtElCS.NbExt()); + for (Standard_Integer i = 1; i <= anExtrema_ExtElCS.NbExt(); i++) + { + Extrema_POnCurv aCurvPoint; + Extrema_POnSurf aSurfPoint; + anExtrema_ExtElCS.Points(i, aCurvPoint, aSurfPoint); + gp_Pnt aCurvPnt = aCurvPoint.Value(); + gp_Pnt aSurfPnt = aSurfPoint.Value(); + + DisplayPnt(aCurvPnt, TCollection_AsciiString(i), Aspect_TOM_O_PLUS, 2.0); + DisplayPnt(aSurfPnt, TCollection_AsciiString(i), Aspect_TOM_O_STAR, 2.0); + gp_Vec aVec(aCurvPnt, aSurfPnt); + aVecArray.SetValue(i, aVec); + aPntArray.SetValue(i, aCurvPnt); + } + Standard_Integer aMinDistIndex(0); + Standard_Real aMinDistance = std::numeric_limits::max(); + for (Standard_Integer i = 1; i <= anExtrema_ExtElCS.NbExt(); i++) + { + if (aMinDistance > aVecArray(i).Magnitude()) + { + aMinDistIndex = i; + aMinDistance = aVecArray(i).Magnitude(); + } + } + Handle(AdaptorVec_AIS) anMinDistanceAis = + new AdaptorVec_AIS(aPntArray(aMinDistIndex), aVecArray(aMinDistIndex)); + anMinDistanceAis->SetText(" Min distance"); + myObject3d.Append(anMinDistanceAis); + } + Handle(Geom_CylindricalSurface) aCylindricalSurface = new Geom_CylindricalSurface(aCylinder); + Handle(AIS_Shape) anAisCylinder = new AIS_Shape(BRepBuilderAPI_MakeFace( + aCylindricalSurface, 0.0, 2.0*M_PI, 0.0, 10.0, Precision::Confusion()).Shape()); + myObject3d.Append(anAisCylinder); + Handle(AdaptorVec_AIS) anLineAis = new AdaptorVec_AIS(aLine.Location(), aLine.Direction(), 8.0); + anLineAis->SetText(" gp_Lin"); + myObject3d.Append(anLineAis); +} + +void GeometrySamples::Intersection3dSample() +{ + gp_Lin aLine(gp_Pnt(0.0, 0.0, 10.0), gp_Dir(0.0, 1.0, 0.0)); + gp_Cone aCone(gp_Ax3(gp_Pnt(), gp_Dir(0.0, 0.0, 1.0)), 0.25*M_PI, 0.0); + IntAna_Quadric anIntAna_Quadric(aCone); + IntAna_IntConicQuad anIntAna_IntConicQuad(aLine, anIntAna_Quadric); + if (anIntAna_IntConicQuad.IsDone()) + { + for (int i = 1; i <= anIntAna_IntConicQuad.NbPoints(); i++) + { + const gp_Pnt& aIntersectionPnt = anIntAna_IntConicQuad.Point(i); + DisplayPnt(aIntersectionPnt, TCollection_AsciiString(i)); + } + } + Handle(AdaptorVec_AIS) aLineVecAIS = new AdaptorVec_AIS(aLine.Location(), gp_Vec(aLine.Direction())*5.0); + aLineVecAIS->SetText(" Base vector"); + myObject3d.Append(aLineVecAIS); + Handle(Geom_ConicalSurface) aConicalSurface = new Geom_ConicalSurface(aCone); + Handle(AIS_Shape) anAisCone = new AIS_Shape(BRepBuilderAPI_MakeFace( + aConicalSurface, 0.0, 2.0*M_PI, 0.0, 20.0, Precision::Confusion()).Shape()); + myObject3d.Append(anAisCone); +} + +void GeometrySamples::TranslatedPoint2dSample() +{ + gp_Pnt2d aPnt1; + gp_Pnt2d aPnt2 = aPnt1.Translated(gp_Vec2d(10.0, 10.0)); + DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 1.0); + DisplayPnt(aPnt2, "2", Aspect_TOM_PLUS, 1.0); + gp_Vec2d aTranslationVec(aPnt1, aPnt2); + Handle(AdaptorVec_AIS) aVecAIS = new AdaptorVec_AIS(aPnt1, aTranslationVec); + aVecAIS->SetText(" Translation"); + myObject2d.Append(aVecAIS); +} + +void GeometrySamples::RotatedDirection2dSample() +{ + gp_Dir2d aBaseDir(1.0, 1.0); + gp_Dir2d aRotatedDir = aBaseDir.Rotated(M_PI_4); + + myResult << "An angle between directions: " << aBaseDir.Angle(aRotatedDir)*180.0 / M_PI << " grad"; + Handle(AdaptorVec_AIS) aBaseAIS = new AdaptorVec_AIS(gp_Pnt2d(), aBaseDir, 5.0); + aBaseAIS->SetText(" Base"); + myObject2d.Append(aBaseAIS); + Handle(AdaptorVec_AIS) aRotatedAIS = new AdaptorVec_AIS(gp_Pnt2d(), aRotatedDir, 5.0); + aRotatedAIS->SetText(" Rotated"); + myObject2d.Append(aRotatedAIS); +} + +void GeometrySamples::MirroredAxis2dSample() +{ + gp_Ax22d aBaseAx(gp_Pnt2d(10.0, 0.0), gp_Dir2d(1.0, 0.0), Standard_True); + gp_Ax22d aMirrorAx = aBaseAx.Mirrored(gp_Pnt2d()); + + DisplayPnt(gp_Pnt2d(), "Mirror point", Aspect_TOM_PLUS, 1.0); + Handle(AdaptorVec_AIS) aBaseX_AIS = new AdaptorVec_AIS(aBaseAx.Location(), aBaseAx.XDirection(), 5.0); + aBaseX_AIS->SetText(" X (Base)"); + myObject2d.Append(aBaseX_AIS); + Handle(AdaptorVec_AIS) aBaseY_AIS = new AdaptorVec_AIS(aBaseAx.Location(), aBaseAx.YDirection(), 5.0); + aBaseY_AIS->SetText("Y (Base)"); + myObject2d.Append(aBaseY_AIS); + Handle(AdaptorVec_AIS) aMirrorX_AIS = new AdaptorVec_AIS(aMirrorAx.Location(), aMirrorAx.XDirection(), 5.0); + aMirrorX_AIS->SetText("X (Mirror)"); + myObject2d.Append(aMirrorX_AIS); + Handle(AdaptorVec_AIS) aMirrorY_AIS = new AdaptorVec_AIS(aMirrorAx.Location(), aMirrorAx.YDirection(), 5.0); + aMirrorY_AIS->SetText(" Y (Mirror)"); + myObject2d.Append(aMirrorY_AIS); +} + +void GeometrySamples::TransformedEllipse2dSample() +{ + // Creates an ellipse with the major axis, the major and the minor radius. + // The location of the MajorAxis is the center of the ellipse.The sense of + // parametrization is given by Sense.Warnings : It is possible to create + // an ellipse with MajorRadius = MinorRadius.Raises + // ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0. + gp_Elips2d aBaseEllips(gp_Ax2d(gp_Pnt2d(), gp_Dir2d(1.0, 0.0)), 20.0, 10.0); + gp_Trsf2d aRotTrsf; + aRotTrsf.SetRotation(gp_Pnt2d(), M_PI_4); + gp_Trsf2d aScaleTrsf; + aScaleTrsf.SetScale(gp_Pnt2d(), 1.5); + gp_Trsf2d aTranslTrsf; + aTranslTrsf.SetTranslation(gp_Vec2d(30.0, 0.0)); + gp_Trsf2d aComplexTrsf = aRotTrsf * aScaleTrsf * aTranslTrsf; + gp_Elips2d aTransfEllips = aBaseEllips.Transformed(aComplexTrsf); + + Handle(Geom2d_Ellipse) aBaseEllipse = new Geom2d_Ellipse(aBaseEllips); + Handle(AdaptorCurve2d_AIS) anAisBaseEllipse = new AdaptorCurve2d_AIS(aBaseEllipse, Aspect_TOL_DASH); + myObject2d.Append(anAisBaseEllipse); + Handle(Geom2d_Ellipse) aTransfEllipse = new Geom2d_Ellipse(aTransfEllips); + Handle(AdaptorCurve2d_AIS) anAisTransfEllipse = new AdaptorCurve2d_AIS(aTransfEllipse, Aspect_TOL_DASH); + myObject2d.Append(anAisTransfEllipse); +} + +void GeometrySamples::ConjugateObjects2dSample() +{ + gp_Parab2d aParab(gp_Ax2d(), 20.0); + gp_Ax2d aDirectrix = aParab.Directrix(); + gp_Pnt2d aFocus = aParab.Focus(); + gp_Pnt2d aLocation = aParab.Location(); + gp_Ax2d aMirror = aParab.MirrorAxis(); + + Handle(AdaptorVec_AIS) aDirectAIS = new AdaptorVec_AIS(aDirectrix.Location(), gp_Vec2d(aDirectrix.Direction())*10.0); + aDirectAIS->SetText(" Directrix"); + myObject2d.Append(aDirectAIS); + Handle(AdaptorVec_AIS) aMirrorAIS = new AdaptorVec_AIS(aMirror.Location(), gp_Vec2d(aMirror.Direction())*10.0); + aMirrorAIS->SetText(" Mirror Axis"); + myObject2d.Append(aMirrorAIS); + + DisplayPnt(aFocus, "Focus", Aspect_TOM_PLUS, -3.0); + DisplayPnt(aLocation, " Location", Aspect_TOM_O_STAR, 3.0); + Handle(Geom2d_Parabola) aGeomParabola = new Geom2d_Parabola(aParab); + Handle(Geom2d_TrimmedCurve) aTrimmedParabola = new Geom2d_TrimmedCurve(aGeomParabola, 40.0, -40.0); + Handle(AdaptorCurve2d_AIS) anAisParabola = new AdaptorCurve2d_AIS(aTrimmedParabola, Aspect_TOL_DOT); + myObject2d.Append(anAisParabola); +} + +void GeometrySamples::Tangent2dSample() +{ + gp_Circ2d aCirc1(gp_Ax2d(gp_Pnt2d(0.0, 0.0), gp_Vec2d(1.0, 0.0)), 10.0); + gp_Circ2d aCirc2 = aCirc1.Translated(gp_Vec2d(50.0, 0.0)); + aCirc2.SetRadius(20.0); + + GccEnt_QualifiedCirc aQaCirc1(aCirc1, GccEnt_outside); + GccEnt_QualifiedCirc aQaCirc2(aCirc2, GccEnt_outside); + + GccAna_Lin2d2Tan aLin2d2Tan(aQaCirc1, aQaCirc2, 1E-6); + if (aLin2d2Tan.IsDone()) + { + for (int i = 1; i <= aLin2d2Tan.NbSolutions(); i++) + { + const gp_Lin2d& aTangentLin = aLin2d2Tan.ThisSolution(i); + Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aTangentLin.Location(), aTangentLin.Direction(), 20.0); + myObject2d.Append(anAisLin); + } + } + + Handle(Geom2d_Circle) aCircle1 = new Geom2d_Circle(aCirc1); + Handle(AdaptorCurve2d_AIS) anAisCirc1 = new AdaptorCurve2d_AIS(aCircle1, Aspect_TOL_SOLID); + myObject2d.Append(anAisCirc1); + Handle(Geom2d_Circle) aCircle2 = new Geom2d_Circle(aCirc2); + Handle(AdaptorCurve2d_AIS) anAisCirc2 = new AdaptorCurve2d_AIS(aCircle2, Aspect_TOL_SOLID); + myObject2d.Append(anAisCirc2); +} + +void GeometrySamples::ProjectionOfPoint2dSample() +{ + gp_Pnt2d aPntToProject(40.0, 40.0); + gp_Circ2d aCirc(gp_Ax2d(), 20.0); + Handle(Geom2d_Circle) aGeom_Circle = new Geom2d_Circle(aCirc); + Geom2dAPI_ProjectPointOnCurve aProjector(aPntToProject, aGeom_Circle); + gp_Pnt2d aProjectionPnt = aProjector.NearestPoint(); + + Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeom_Circle, Aspect_TOL_SOLID); + myObject2d.Append(anAisCirc); + DisplayPnt(aPntToProject, "Pnt to project"); + DisplayPnt(aProjectionPnt, "Projection Pnt", Aspect_TOM_O_STAR); +} + +void GeometrySamples::MinimalDistance2dSample() +{ + gp_Lin2d aLin(gp_Pnt2d(-40.0, 0.0), gp_Dir2d(1.0, 1.0)); + Handle(Geom2d_Line) aGeom_Line = new Geom2d_Line(aLin); + gp_Circ2d aCirc(gp_Ax2d(), 20.0); + Handle(Geom2d_Circle) aGeom_Circle = new Geom2d_Circle(aCirc); + + Geom2dAPI_ExtremaCurveCurve anExtremaFinder(aGeom_Line, aGeom_Circle, + std::numeric_limits::min(), + std::numeric_limits::max(), 0.0, M_PI*2.0); + if (anExtremaFinder.NbExtrema()) + { + gp_Pnt2d aPnt1, aPnt2; + anExtremaFinder.NearestPoints(aPnt1, aPnt2); + myResult << "Extrema found: " << anExtremaFinder.NbExtrema() << std::endl; + myResult << "Minimal distance: " << anExtremaFinder.LowerDistance() << std::endl; + DisplayPnt(aPnt1, "1"); + DisplayPnt(aPnt2, "2"); + } + else + { + myResult << "No Extrema found" << std::endl; + } + + Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeom_Circle, Aspect_TOL_SOLID); + myObject2d.Append(anAisCirc); + Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aLin.Location(), aLin.Direction(), 60.0); + anAisLin->SetText(" gp_Lin2d"); + myObject2d.Append(anAisLin); +} + +void GeometrySamples::Intersection2dSample() +{ + gp_Lin2d aLin(gp_Pnt2d(-20.0, 20.0), gp_Dir2d(1.0, -1.5)); + Handle(Geom2d_Line) aGeom_Line = new Geom2d_Line(aLin); + gp_Parab2d aParab(gp_Ax2d(), 20.0); + Handle(Geom2d_Parabola) aGeom_Parabola = new Geom2d_Parabola(aParab); + + Geom2dAPI_InterCurveCurve anIntersectFinder(aGeom_Line, aGeom_Parabola); + for (Standard_Integer i = 1; i <= anIntersectFinder.NbPoints(); i++) + { + gp_Pnt2d aPnt = anIntersectFinder.Point(i); + DisplayPnt(aPnt, i); + } + + myResult << "Number of intersections : " << anIntersectFinder.NbPoints() << std::endl; + + Handle(Geom2d_Parabola) aGeomParabola = new Geom2d_Parabola(aParab); + Handle(Geom2d_TrimmedCurve) aTrimmedParabola = new Geom2d_TrimmedCurve(aGeomParabola, 60.0, -60.0); + Handle(AdaptorCurve2d_AIS) anAisParabola = new AdaptorCurve2d_AIS(aTrimmedParabola, Aspect_TOL_DOT); + myObject2d.Append(anAisParabola); + Handle(AdaptorVec_AIS) anAisLin = new AdaptorVec_AIS(aLin.Location(), aLin.Direction(), 90.0); + anAisLin->SetText(" gp_Lin2d"); + myObject2d.Append(anAisLin); +} + +void GeometrySamples::PointInfo3dSample() +{ + gp_Pnt aPnt1; + gp_Pnt aPnt2(10.0, 10.0, 10.0); + gp_Pnt aPnt3(10.0, -10.0, 0.0); + gp_Pnt aPnt4(10.0, 10.0, 10.0); + Standard_Boolean anIsEqual2_3 = aPnt2.IsEqual(aPnt3, 1E-6); + Standard_Boolean anIsEqual2_4 = aPnt2.IsEqual(aPnt4, 1E-6); + Standard_Real aDistance1_2 = aPnt1.Distance(aPnt2); + Standard_Real aDistance2_4 = aPnt2.Distance(aPnt4); + Standard_Real aSquareDistance1_2 = aPnt1.SquareDistance(aPnt2); + Standard_Real aSquareDistance2_4 = aPnt2.SquareDistance(aPnt4); + + myResult << "A coordinate of a point 1: X: " << aPnt1.X() << " Y: " << aPnt1.Y() << " Z: " << aPnt1.Z() << std::endl; + myResult << "A coordinate of a point 2: X: " << aPnt2.X() << " Y: " << aPnt2.Y() << " Z: " << aPnt2.Z() << std::endl; + myResult << "A coordinate of a point 3: X: " << aPnt3.X() << " Y: " << aPnt3.Y() << " Z: " << aPnt3.Z() << std::endl; + myResult << "A coordinate of a point 4: X: " << aPnt4.X() << " Y: " << aPnt4.Y() << " Z: " << aPnt4.Z() << std::endl; + + if (anIsEqual2_3) + { + myResult << "A point 2 is equal to a point 3" << std::endl; + } + else + { + myResult << "A point 2 is different from a point 3" << std::endl; + } + if (anIsEqual2_4) + { + myResult << "A point 2 is equal to a point 4" << std::endl; + } + else + { + myResult << "A point 2 is different from a point 4" << std::endl; + } + myResult << "A distance from a point 1 to a point 2 is: " << aDistance1_2 << std::endl; + myResult << "A distance from a point 2 to a point 4 is: " << aDistance2_4 << std::endl; + + myResult << "A square distance from a point 1 to a point 2 is: " << aSquareDistance1_2 << std::endl; + myResult << "A square distance from a point 2 to a point 4 is: " << aSquareDistance2_4 << std::endl; + + DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt2, "2 & 4", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt4, "", Aspect_TOM_PLUS, 0.5); +} + +void GeometrySamples::EllipseInfo3dSample() +{ + gp_Elips anElips(gp_Ax2(gp_Pnt(), gp_Dir(1.0, 0.0, 0.0)), 20.0, 10.0); + Standard_Real anArea = anElips.Area(); + // Returns the eccentricity of the ellipse between 0.0 and 1.0 + // If f is the distance between the center of the ellipse and the Focus1 then + // the eccentricity e = f / MajorRadius. Returns 0 if MajorRadius = 0. + Standard_Real anEccentricity = anElips.Eccentricity(); + // Returns the distance between the center of the ellipse and focus1 or focus2. + Standard_Real aFocal = anElips.Focal(); + // Returns p = (1 - e * e) * MajorRadius where e is the eccentricity + // of the ellipse. Returns 0 if MajorRadius = 0. + Standard_Real aParameter = anElips.Parameter(); + + myResult << "Ellipse area = " << anArea << " square units" << std::endl; + myResult << "Eccentricity = " << anEccentricity; + myResult << "Focal distance = " << aFocal; + myResult << "Ellipse parameter = " << aParameter; + + gp_Pnt aCenter = anElips.Location(); + gp_Pnt aFocus1 = anElips.Focus1(); + gp_Pnt aFocus2 = anElips.Focus2(); + DisplayPnt(aCenter, "Center", Aspect_TOM_PLUS, 2.0); + DisplayPnt(aFocus1, "focus 1", Aspect_TOM_PLUS, 2.0); + DisplayPnt(aFocus2, "focus 2", Aspect_TOM_PLUS, 2.0); + + Handle(Geom_Ellipse) aGeomEllipse = new Geom_Ellipse(anElips); + Handle(AdaptorCurve_AIS) anAisEllipce = new AdaptorCurve_AIS(aGeomEllipse); + myObject3d.Append(anAisEllipce); +} + +void GeometrySamples::PointInfo2dSample() +{ + gp_Pnt2d aPnt1; + gp_Pnt2d aPnt2(10.0, 10.0); + gp_Pnt2d aPnt3(10.0, -10.0); + gp_Pnt2d aPnt4(10.0, 10.0); + Standard_Boolean anIsEqual2_3 = aPnt2.IsEqual(aPnt3, 1E-6); + Standard_Boolean anIsEqual2_4 = aPnt2.IsEqual(aPnt4, 1E-6); + Standard_Real aDistance1_2 = aPnt1.Distance(aPnt2); + Standard_Real aDistance2_4 = aPnt2.Distance(aPnt4); + Standard_Real aSquareDistance1_2 = aPnt1.SquareDistance(aPnt2); + Standard_Real aSquareDistance2_4 = aPnt2.SquareDistance(aPnt4); + + myResult << "A coordinate of a point 1: X: " << aPnt1.X() << " Y: " << aPnt1.Y() << std::endl; + myResult << "A coordinate of a point 2: X: " << aPnt2.X() << " Y: " << aPnt2.Y() << std::endl; + myResult << "A coordinate of a point 3: X: " << aPnt3.X() << " Y: " << aPnt3.Y() << std::endl; + myResult << "A coordinate of a point 4: X: " << aPnt4.X() << " Y: " << aPnt4.Y() << std::endl; + if (anIsEqual2_3) + { + myResult << "A point 2 is equal to a point 3" << std::endl; + } + else + { + myResult << "A point 2 is different from a point 3" << std::endl; + } + if (anIsEqual2_4) + { + myResult << "A point 2 is equal to a point 4" << std::endl; + } + else + { + myResult << "A point 2 is different from a point 4" << std::endl; + } + + myResult << "A distance from a point 1 to a point 2 is: " << aDistance1_2 << std::endl; + myResult << "A distance from a point 2 to a point 4 is: " << aDistance2_4 << std::endl; + + myResult << "A square distance from a point 1 to a point 2 is: " << aSquareDistance1_2 << std::endl; + myResult << "A square distance from a point 2 to a point 4 is: " << aSquareDistance2_4 << std::endl; + + DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt2, "2 & 4", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt4, ""); +} + +void GeometrySamples::CircleInfo2dSample() +{ + gp_Circ2d aCirc(gp_Ax22d(gp_Pnt2d(10.0, 10.0), gp_Vec2d(1.0, 0.0)), 10.0); + gp_Pnt2d aPnt1(0.0, 10.0); + gp_Pnt2d aPnt2(10.0, 0.0); + gp_Pnt2d aPnt3(20.0, 20.0); + + if (aCirc.Contains(aPnt1, 1E-6)) + { + DisplayPnt(aPnt1, "1", Aspect_TOM_STAR, 3.0); + myResult << "A circle contains a point 1" << std::endl; + } + else + { + DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 1.0); + myResult << "A circle does contain a point 1" << std::endl; + } + if (aCirc.Contains(aPnt2, 1E-6)) + { + DisplayPnt(aPnt2, "2", Aspect_TOM_STAR, 1.0); + myResult << "A circle contains a point 2" << std::endl; + } + else + { + DisplayPnt(aPnt2, "2", Aspect_TOM_PLUS, 1.0); + myResult << "A circle does contain a point 2" << std::endl; + } + if (aCirc.Contains(aPnt3, 1E-6)) + { + DisplayPnt(aPnt3, "3", Aspect_TOM_STAR, 1.0); + myResult << "A circle contains a point 3" << std::endl; + } + else + { + DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 1.0); + myResult << "A circle does contain a point 3" << std::endl; + } + myResult << "Circle area = " << aCirc.Area() << "square units" << std::endl; + Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(aCirc); + Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle); + myObject2d.Append(anAisCirc); +} + +void GeometrySamples::FreeStyleCurves3dSample() +{ + // Define points. + gp_Pnt aPnt1(0.0, 0.0, 0.0); + gp_Pnt aPnt2(5.0, 5.0, 0.0); + gp_Pnt aPnt3(10.0, 5.0, 0.0); + gp_Pnt aPnt4(15.0, 0.0, 0.0); + + // Add points to the curve poles array. + TColgp_Array1OfPnt aPoles(1, 4); + aPoles.SetValue(1, aPnt1); + aPoles.SetValue(2, aPnt2); + aPoles.SetValue(3, aPnt3); + aPoles.SetValue(4, aPnt4); + + // Define BSpline weights. + TColStd_Array1OfReal aBSplineWeights(1, 4); + aBSplineWeights.SetValue(1, 1.0); + aBSplineWeights.SetValue(2, 0.5); + aBSplineWeights.SetValue(3, 0.5); + aBSplineWeights.SetValue(4, 1.0); + + // Define knots. + TColStd_Array1OfReal aKnots(1, 2); + aKnots.SetValue(1, 0.0); + aKnots.SetValue(2, 1.0); + + // Define multiplicities. + TColStd_Array1OfInteger aMults(1, 2); + aMults.SetValue(1, 4); + aMults.SetValue(2, 4); + + // Define BSpline degree and periodicity. + Standard_Integer aDegree = 3; + Standard_Boolean aPeriodic = Standard_False; + + // Create a BSpline curve. + Handle(Geom_BSplineCurve) aBSplineCurve = new Geom_BSplineCurve( + aPoles, aBSplineWeights, aKnots, aMults, aDegree, aPeriodic); + myResult << "Geom_BSplineCurve was created in red" << std::endl; + + // Define Bezier weights. + TColStd_Array1OfReal aBezierWeights(1, 4); + aBezierWeights.SetValue(1, 0.5); + aBezierWeights.SetValue(2, 1.5); + aBezierWeights.SetValue(3, 1.5); + aBezierWeights.SetValue(4, 0.5); + + // Create Bezier curve. + Handle(Geom_BezierCurve) aBezierCurve = new Geom_BezierCurve(aPoles, aBezierWeights); + myResult << "Geom_BezierCurve was created in green" << std::endl; + + Handle(AIS_ColoredShape) anAisBSplineCurve = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aBSplineCurve).Shape()); + Handle(AIS_ColoredShape) anAisBezierCurve = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aBezierCurve).Shape()); + anAisBSplineCurve->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisBezierCurve->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisBSplineCurve); + myObject3d.Append(anAisBezierCurve); + myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt1))); + myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt2))); + myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt3))); + myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt4))); +} + +void GeometrySamples::AnalyticalSurfaces3dSample() +{ + // Define a XY plane. + gp_Pln aPln(gp::Origin(), gp::DZ()); + // Create plane geometry. + Handle(Geom_Plane) aPlaneSurf = new Geom_Plane(aPln); + myResult << "Geom_Plane was created in red" << std::endl; + + // Define a cylinder. + gp_Cylinder aCyl(gp::XOY(), 2.5); + // Create cylindrical surface. + Handle(Geom_CylindricalSurface) aCylSurf = new Geom_CylindricalSurface(aCyl); + myResult << "Geom_CylindricalSurface was created in green" << std::endl; + + // Define a cone. + gp_Cone aCone(gp::XOY(), M_PI_4, 2.5); + // Create conical surface. + Handle(Geom_ConicalSurface) aConeSurf = new Geom_ConicalSurface(aCone); + myResult << "Geom_ConicalSurface was created in blue" << std::endl; + + // Define a sphere. + gp_Pnt aSphereCenter(15.0, 15.0, 15.0); + gp_Sphere aSphere(gp_Ax3(aSphereCenter, gp::DZ()), 8.0); + // Create conical surface. + Handle(Geom_SphericalSurface) aSphereSurf = new Geom_SphericalSurface(aSphere); + myResult << "Geom_SphericalSurface was created in cyan" << std::endl; + + // Define a sphere. + gp_Pnt aTorusCenter(-15.0, -15.0, 25.0); + gp_Torus aTorus(gp_Ax3(aTorusCenter, gp::DZ()), 15.0, 5.0); + // Create toroidal surface. + Handle(Geom_ToroidalSurface) aTorusSurf = new Geom_ToroidalSurface(aTorus); + myResult << "Geom_ToroidalSurface was created in yellow" << std::endl; + + Handle(AIS_ColoredShape) anAisPlane = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( + aPlaneSurf, 0.0, 20.0, 0.0, 20.0, Precision::Confusion()).Shape()); + Handle(AIS_ColoredShape) anAisCylinder = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( + aCylSurf, 0.0, 2.0 * M_PI, 5.0, 15.0, Precision::Confusion()).Shape()); + Handle(AIS_ColoredShape) anAisCone = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( + aConeSurf, 0.0, 2.0 * M_PI, 0.0, 15.0, Precision::Confusion()).Shape()); + Handle(AIS_ColoredShape) anAisSphere = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( + aSphereSurf, Precision::Confusion()).Shape()); + Handle(AIS_ColoredShape) anAisTorus = new AIS_ColoredShape(BRepBuilderAPI_MakeFace( + aTorusSurf, Precision::Confusion()).Shape()); + anAisPlane->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisCylinder->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + anAisCone->SetColor(Quantity_Color(Quantity_NOC_BLUE1)); + anAisSphere->SetColor(Quantity_Color(Quantity_NOC_CYAN1)); + anAisTorus->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + myObject3d.Append(anAisPlane); + myObject3d.Append(anAisCylinder); + myObject3d.Append(anAisCone); + myObject3d.Append(anAisSphere); + myObject3d.Append(anAisTorus); +} + +void GeometrySamples::FreeStyleSurfaces3dSample() +{ + // Define a 4x4 grid of points for BSpline surface. + TColgp_Array2OfPnt aBSplinePnts(1, 4, 1, 4); + for (Standard_Integer i = 1; i <= 4; ++i) + { + gp_Pnt aPnt; + aPnt.SetX(5.0 * i); + for (Standard_Integer j = 1; j <= 4; ++j) + { + aPnt.SetY(5.0 * j); + if (1 < i && i < 4 && 1 < j && j < 4) + { + aPnt.SetZ(5.0); + } + else + { + aPnt.SetZ(0.0); + } + aBSplinePnts.SetValue(i, j, aPnt); + } + } + + // Define a 4x4 grid of points for Bezier surface. + TColgp_Array2OfPnt aBezierPnts(1, 4, 1, 4); + for (Standard_Integer i = 1; i <= 4; ++i) + { + gp_Pnt aPnt; + aPnt.SetX(20.0 + 5.0 * i); + for (Standard_Integer j = 1; j <= 4; ++j) + { + aPnt.SetY(20.0 + 5.0 * j); + if (1 < i && i < 4 && 1 < j && j < 4) + { + aPnt.SetZ(5.0); + } + else + { + aPnt.SetZ(0.0); + } + aBezierPnts.SetValue(i, j, aPnt); + } + } + + // Define BSpline weights. + TColStd_Array2OfReal aBSplineWeights(1, 4, 1, 4); + for (Standard_Integer i = 1; i <= 4; ++i) + { + for (Standard_Integer j = 1; j <= 4; ++j) + { + if (1 < i && i < 4 && 1 < j && j < 4) + { + aBSplineWeights.SetValue(i, j, 0.5); + } + else + { + aBSplineWeights.SetValue(i, j, 1.0); + } + } + } + + // Define knots. + TColStd_Array1OfReal aUKnots(1, 2), aVKnots(1, 2); + aUKnots.SetValue(1, 0.0); + aUKnots.SetValue(2, 1.0); + aVKnots.SetValue(1, 0.0); + aVKnots.SetValue(2, 1.0); + + // Define multiplicities. + TColStd_Array1OfInteger aUMults(1, 2), aVMults(1, 2); + aUMults.SetValue(1, 4); + aUMults.SetValue(2, 4); + aVMults.SetValue(1, 4); + aVMults.SetValue(2, 4); + + // Define BSpline degree and periodicity. + Standard_Integer aUDegree = 3; + Standard_Integer aVDegree = 3; + Standard_Boolean aUPeriodic = Standard_False; + Standard_Boolean aVPeriodic = Standard_False; + + // Create a BSpline surface. + Handle(Geom_BSplineSurface) aBSplineSurf = new Geom_BSplineSurface( + aBSplinePnts, aBSplineWeights, aUKnots, aVKnots, + aUMults, aVMults, aUDegree, aVDegree, aUPeriodic, aVPeriodic); + myResult << "Geom_BSplineSurface was created in red" << std::endl; + + // Define BSpline weights. + TColStd_Array2OfReal aBezierWeights(1, 4, 1, 4); + for (Standard_Integer i = 1; i <= 4; ++i) + { + for (Standard_Integer j = 1; j <= 4; ++j) + { + if (1 < i && i < 4 && 1 < j && j < 4) + { + aBezierWeights.SetValue(i, j, 1.5); + } + else + { + aBezierWeights.SetValue(i, j, 0.5); + } + } + } + + // Create a Bezier surface. + Handle(Geom_BezierSurface) aBezierSurf = new Geom_BezierSurface(aBezierPnts, aBezierWeights); + myResult << "Geom_BezierSurface was created in green" << std::endl; + + Handle(AIS_ColoredShape) anAisBSplineSurf = new AIS_ColoredShape( + BRepBuilderAPI_MakeFace(aBSplineSurf, Precision::Confusion()).Shape()); + Handle(AIS_ColoredShape) anAisBezierSurf = new AIS_ColoredShape( + BRepBuilderAPI_MakeFace(aBezierSurf, Precision::Confusion()).Shape()); + anAisBSplineSurf->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisBezierSurf->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisBSplineSurf); + myObject3d.Append(anAisBezierSurf); + for (TColgp_Array2OfPnt::Iterator anIt(aBSplinePnts); anIt.More(); anIt.Next()) + { + myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(anIt.Value()))); + } + for (TColgp_Array2OfPnt::Iterator anIt(aBezierPnts); anIt.More(); anIt.Next()) + { + myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(anIt.Value()))); + } +} + +void GeometrySamples::FreeStyleCurves2dSample() +{ + + // Define points. + gp_Pnt2d aPnt1(0.0, 0.0); + gp_Pnt2d aPnt2(5.0, 5.0); + gp_Pnt2d aPnt3(10.0, 5.0); + gp_Pnt2d aPnt4(15.0, 0.0); + + // Add points to the curve poles array. + TColgp_Array1OfPnt2d aBSplinePoles(1, 4); + aBSplinePoles.SetValue(1, aPnt1); + aBSplinePoles.SetValue(2, aPnt2); + aBSplinePoles.SetValue(3, aPnt3); + aBSplinePoles.SetValue(4, aPnt4); + + // Define BSpline weights. + TColStd_Array1OfReal aBSplineWeights(1, 4); + aBSplineWeights.SetValue(1, 1.0); + aBSplineWeights.SetValue(2, 0.5); + aBSplineWeights.SetValue(3, 0.5); + aBSplineWeights.SetValue(4, 1.0); + + // Define knots. + TColStd_Array1OfReal aKnots(1, 2); + aKnots.SetValue(1, 0.0); + aKnots.SetValue(2, 1.0); + + // Define multiplicities. + TColStd_Array1OfInteger aMults(1, 2); + aMults.SetValue(1, 4); + aMults.SetValue(2, 4); + + // Define BSpline degree and periodicity. + Standard_Integer aDegree = 3; + Standard_Boolean aPeriodic = Standard_False; + + // Create a BSpline curve. + Handle(Geom2d_BSplineCurve) aBSplineCurve = + new Geom2d_BSplineCurve(aBSplinePoles, aBSplineWeights, aKnots, aMults, aDegree, aPeriodic); + + + TColgp_Array1OfPnt2d aBezierPoles(1, 4); + gp_Vec2d anUp10Vec(0.0, 10.0); + aBezierPoles.SetValue(1, aPnt1.Translated(anUp10Vec)); + aBezierPoles.SetValue(2, aPnt2.Translated(anUp10Vec)); + aBezierPoles.SetValue(3, aPnt3.Translated(anUp10Vec)); + aBezierPoles.SetValue(4, aPnt4.Translated(anUp10Vec)); + + // Define Bezier weights. + TColStd_Array1OfReal aBezierWeights(1, 4); + aBezierWeights.SetValue(1, 0.5); + aBezierWeights.SetValue(2, 1.5); + aBezierWeights.SetValue(3, 1.5); + aBezierWeights.SetValue(4, 0.5); + + // Create Bezier curve. + Handle(Geom2d_BezierCurve) aBezierCurve = new Geom2d_BezierCurve(aBezierPoles, aBezierWeights); + + Handle(AdaptorCurve2d_AIS) anAisBSpline = new AdaptorCurve2d_AIS(aBSplineCurve); + myObject2d.Append(anAisBSpline); + Handle(AdaptorCurve2d_AIS) anAisBezier = new AdaptorCurve2d_AIS(aBezierCurve); + myObject2d.Append(anAisBezier); + + DisplayPnt(aPnt1, "1", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt2, "2", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt3, "3", Aspect_TOM_PLUS, 0.5); + DisplayPnt(aPnt4, "4", Aspect_TOM_PLUS, 0.5); +} + +void GeometrySamples::TrimmedCurve3dSample() +{ + // Define a circle placed in the origin of XY coordinate + // plane and with the radius equal to 5. + gp_Circ aCirc(gp::XOY(), 5.0); + // Create a closed circular curve. + Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc); + myResult << "Geom_Circle was created in yellow" << std::endl; + + // Cut off a quarter of the circle. + Handle(Geom_TrimmedCurve) aCircQuater = new Geom_TrimmedCurve(aCircCurve, 0.0, M_PI_2); + myResult << "Geom_TrimmedCurve was created in red" << std::endl; + + Handle(AIS_ColoredShape) anAisCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircCurve).Shape()); + Handle(AIS_ColoredShape) anAisCircQuater = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircQuater).Shape()); + anAisCirc->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisCircQuater->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisCircQuater->SetWidth(2.5); + myObject3d.Append(anAisCirc); + myObject3d.Append(anAisCircQuater); +} + +void GeometrySamples::OffsetCurve3dSample() +{ + // Define a circle placed in the origin of XY coordinate + // plane and with the radius equal to 5. + gp_Circ aCirc(gp::XOY(), 5.0); + // Create a closed circular curve. + Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc); + myResult << "Geom_Circle was created in yellow" << std::endl; + + // An offset curve is a curve at constant distance (Offset) from + // a basis curve in a reference direction V. + // The offset curve takes its parametrization from the basis curve. + // The Offset curve is in the direction of the normal N + // defined with the cross product T^V, where the vector T + // is given by the first derivative on the basis curve with non zero length. + // The distance offset may be positive or negative to indicate the + // preferred side of the curve: + // . distance offset >0 => the curve is in the direction of N + // . distance offset <0 => the curve is in the direction of - N + // On the Offset curve: + // Value (U) = BasisCurve.Value(U) + (Offset * (T ^ V)) / ||T ^ V|| + // At any point the Offset direction V must not be parallel to the + // vector T and the vector T must not have null length else the + // offset curve is not defined. + + // Expand the circle by Offset equal to a quarter of the radius + // with direction V equal to Z. + Standard_Real anExpandOffset = +aCirc.Radius() / 4.0; + gp_Dir anExpandDir = gp::DZ(); + Handle(Geom_OffsetCurve) anExpandCircCurve = new Geom_OffsetCurve( + aCircCurve, anExpandOffset, anExpandDir); + myResult << "Geom_OffsetCurve (expanded circle) was created in red" << std::endl; + + // Collapse the circle by Offset equal to a half of the radius with direction V equal to Z. + Standard_Real anCollapseOffset = -aCirc.Radius() / 2.0; + gp_Dir anCollapseDir = gp::DZ(); + Handle(Geom_OffsetCurve) anCollapseCircCurve = new Geom_OffsetCurve (aCircCurve, anCollapseOffset, anCollapseDir); + myResult << "Geom_OffsetCurve (collapsed circle) was created in green" << std::endl; + + Handle(AIS_ColoredShape) anAisCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircCurve).Shape()); + Handle(AIS_ColoredShape) anAisExpandCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(anExpandCircCurve).Shape()); + Handle(AIS_ColoredShape) anAisCpllapsedCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(anCollapseCircCurve).Shape()); + anAisCirc->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisExpandCirc->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisCpllapsedCirc->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisCirc); + myObject3d.Append(anAisExpandCirc); + myObject3d.Append(anAisCpllapsedCirc); +} + +void GeometrySamples::BSplineFromCircle3dSample() +{ + // Define a circle placed in the origin of XY coordinate + // plane and with the radius equal to 5. + gp_Circ aCirc(gp::XOY(), 5.0); + // Create a closed circular curve. + Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc); + myResult << "Geom_Circle was created in yellow" << std::endl; + + // Convert the circle curve to a BSpline one. + Handle(Geom_BSplineCurve) aBSplineFromCirc = GeomConvert::CurveToBSplineCurve(aCircCurve); + myResult << "Geom_BSplineCurve was created in red:" << std::endl; + myResult << "Degree: " << aBSplineFromCirc->Degree() << std::endl; + myResult << "Periodic: " << (aBSplineFromCirc->IsPeriodic() ? "Yes" : "No") << std::endl; + myResult << "Poles: [" << aBSplineFromCirc->Poles().Size() << "]" << std::endl; + for (TColgp_Array1OfPnt::Iterator anIt(aBSplineFromCirc->Poles()); anIt.More(); anIt.Next()) + { + myResult << " (" << anIt.Value().X() << ", " << anIt.Value().Y() << ", " << anIt.Value().Z() << ")" << std::endl; + } + + Handle(AIS_ColoredShape) anAisCirc = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aCircCurve).Shape()); + Handle(AIS_ColoredShape) anAisBSpline = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aBSplineFromCirc).Shape()); + anAisCirc->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisBSpline->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisCirc); + myObject3d.Append(anAisBSpline); +} + +void GeometrySamples::TrimmedSurface3dSample() +{ + // Define a XY plane. + gp_Pln aPln(gp::XOY()); + // Create a plane surface. + Handle(Geom_Plane) aPlaneSurf = new Geom_Plane(aPln); + myResult << "Geom_Plane was created" << std::endl; + + // Trim [0 ... 30 X 0 ... 50] rectangular range. + Standard_Real aUMin = 0.0; + Standard_Real aUMax = 30.0; + Standard_Real aVMin = 0.0; + Standard_Real aVMax = 50.0; + Handle(Geom_RectangularTrimmedSurface) aTrimmedPlaneSurf + = new Geom_RectangularTrimmedSurface(aPlaneSurf, aUMin, aUMax, aVMin, aVMax); + myResult << "Geom_RectangularTrimmedSurface was created in red" << std::endl; + + Handle(AIS_Plane) anAisPlane = new AIS_Plane(aPlaneSurf); + Handle(AIS_ColoredShape) anAisTimmedPlane = new AIS_ColoredShape (BRepBuilderAPI_MakeFace (aTrimmedPlaneSurf, 0.001).Shape()); + anAisTimmedPlane->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisPlane); + myObject3d.Append(anAisTimmedPlane); +} + +void GeometrySamples::OffsetSurface3dSample() +{ + // Define a XY plane. + gp_Pln aPln(gp::XOY()); + // Create a plane surface. + Handle(Geom_Plane) aPlaneSurf = new Geom_Plane(aPln); + myResult << "Geom_Plane was created" << std::endl; + + // An offset surface is defined by: + // - the basis surface to which it is parallel, and + // - the distance between the offset surface and its basis surface. + // A point on the offset surface is built by measuring the + // offset value along the normal vector at a point on the + // basis surface. This normal vector is given by the cross + // product D1u^D1v, where D1u and D1v are the + // vectors tangential to the basis surface in the u and v + // parametric directions at this point. The side of the + // basis surface on which the offset is measured + // depends on the sign of the offset value. + + // Offset the plane in the normal direction. + Standard_Real aPosOffset = 10.0; + Handle(Geom_OffsetSurface) aPosOffsetSurf = new Geom_OffsetSurface(aPlaneSurf, aPosOffset); + myResult << "Geom_OffsetSurface with " << aPosOffset << " was created in red" << std::endl; + + // Offset the plane in direction opposite to the normal one. + Standard_Real aNegOffset = -15.0; + Handle(Geom_OffsetSurface) aNegOffsetSurf = new Geom_OffsetSurface(aPlaneSurf, aNegOffset); + myResult << "Geom_OffsetSurface with " << aNegOffset << " was created in green" << std::endl; + + Handle(AIS_ColoredShape) anAisPlane = new AIS_ColoredShape( + BRepBuilderAPI_MakeFace(aPlaneSurf, 0.0, 10.0, 0.0, 10.0, Precision::Confusion()).Shape()); + Handle(AIS_ColoredShape) anAisPosOffsetPlane = new AIS_ColoredShape( + BRepBuilderAPI_MakeFace(aPosOffsetSurf, 0.0, 10.0, 0.0, 10.0, Precision::Confusion()).Shape()); + Handle(AIS_ColoredShape) anAisNegOffsetPlane = new AIS_ColoredShape( + BRepBuilderAPI_MakeFace(aNegOffsetSurf, 0.0, 10.0, 0.0, 10.0, Precision::Confusion()).Shape()); + anAisPosOffsetPlane->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisNegOffsetPlane->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisPlane); + myObject3d.Append(anAisPosOffsetPlane); + myObject3d.Append(anAisNegOffsetPlane); +} + +void GeometrySamples::ExtrusionSurface3dSample() +{ + // Create an ellipse curve in XY plane. + Standard_Real aMinorRadius = 10.0; + Standard_Real aMajorRadius = 20.0; + Handle(Geom_Ellipse) anEllipseCurve = new Geom_Ellipse(gp::XOY(), aMajorRadius, aMinorRadius); + myResult << "Geom_Ellipse was created in yellow" << std::endl; + + // Make a linear extrusion of the ellipse at 45 degrees to Z axis + gp_Dir aDirOfExtr = gp::DZ(); + Handle(Geom_SurfaceOfLinearExtrusion) aLinExtrSurf + = new Geom_SurfaceOfLinearExtrusion(anEllipseCurve, aDirOfExtr); + myResult << "Geom_SurfaceOfLinearExtrusion was created in red" << std::endl; + + Handle(AIS_ColoredShape) anAisEllipse = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(anEllipseCurve).Shape()); + Handle(AIS_ColoredShape) anAisExtrSurf = new AIS_ColoredShape( + BRepBuilderAPI_MakeFace(aLinExtrSurf, 0.0, 2.0 * M_PI, 0.0, 30.0, + Precision::Confusion()).Shape()); + anAisEllipse->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisEllipse->SetWidth(2.5); + anAisExtrSurf->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisEllipse); + myObject3d.Append(anAisExtrSurf); +} + +void GeometrySamples::RevolutionSurface3dSample() +{ + // Create an ellipse curve in XY plane with + // the center at (-10, 0, 0). + Standard_Real aMinorRadius = 5.0; + Standard_Real aMajorRadius = 10.0; + gp_Pnt aCenter(-30.0, 0.0, 0.0); + Handle(Geom_Ellipse) anEllipseCurve = new Geom_Ellipse(gp_Ax2(aCenter, gp::DZ()), + aMajorRadius, aMinorRadius); + myResult << "Geom_Ellipse was created in yellow" << std::endl; + + // Make a revolution of the ellipse around Y axis + Handle(Geom_SurfaceOfRevolution) aRevolSurf = new Geom_SurfaceOfRevolution(anEllipseCurve, gp::OY()); + myResult << "Geom_SurfaceOfRevolution was created in red" << std::endl; + + Handle(AIS_ColoredShape) anAisEllipse = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(anEllipseCurve).Shape()); + Handle(AIS_ColoredShape) anAisRevolSurf = new AIS_ColoredShape( + BRepBuilderAPI_MakeFace(aRevolSurf, Precision::Confusion()).Shape()); + anAisEllipse->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisEllipse->SetWidth(2.5); + anAisRevolSurf->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisEllipse); + myObject3d.Append(anAisRevolSurf); +} + +void GeometrySamples::TrimmedCurve2dSample() +{ + // Create a closed circular curve. + Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(), gp_Vec2d(1.0, 0.0)), 5.0); + Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle); + myObject2d.Append(anAisCirc); + + // Cut off a quarter of the circle. + Handle(Geom2d_TrimmedCurve) aCircQuater = new Geom2d_TrimmedCurve(aGeomCircle, 0.0, M_PI_2); + aCircQuater->Translate(gp_Vec2d(15.0, 0.0)); + Handle(AdaptorCurve2d_AIS) anAisCircQuater = new AdaptorCurve2d_AIS(aCircQuater); + myObject2d.Append(anAisCircQuater); +} + +void GeometrySamples::OffsetCurve2dSample() +{ + Handle(Geom2d_Circle) aGeomCircle = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(), gp_Vec2d(1.0, 0.0)), 5.0); + + Standard_Real anExpandOffset = aGeomCircle->Radius() / 4.0; + Handle(Geom2d_OffsetCurve) anExpandCircCurve = new Geom2d_OffsetCurve(aGeomCircle, anExpandOffset); + + Standard_Real anCollapseOffset = -aGeomCircle->Radius() / 2.0; + Handle(Geom2d_OffsetCurve) anCollapseCircCurve = new Geom2d_OffsetCurve(aGeomCircle, anCollapseOffset); + + Handle(AdaptorCurve2d_AIS) anAisCirc = new AdaptorCurve2d_AIS(aGeomCircle); + myObject2d.Append(anAisCirc); + Handle(AdaptorCurve2d_AIS) anAisExpand = new AdaptorCurve2d_AIS(anExpandCircCurve); + myObject2d.Append(anAisExpand); + Handle(AdaptorCurve2d_AIS) anAisCollapse = new AdaptorCurve2d_AIS(anCollapseCircCurve); + myObject2d.Append(anAisCollapse); +} + +void GeometrySamples::BoundingBoxOfSurface3dSample() +{ + // Define a 4x4 grid of points for BSpline surface. + TColgp_Array2OfPnt aPoints(1, 4, 1, 4); + for (Standard_Integer i = 1; i <= 4; ++i) + { + gp_Pnt aPnt; + aPnt.SetX(5.0 * i); + for (Standard_Integer j = 1; j <= 4; ++j) + { + aPnt.SetY(5.0 * j); + if (1 < i && i < 4 && 1 < j && j < 4) + { + aPnt.SetZ(5.0); + } + else + { + aPnt.SetZ(0.0); + } + aPoints.SetValue(i, j, aPnt); + } + } + + // Make a BSpline surface from the points array. + Handle(Geom_BSplineSurface) aBSplineSurf = GeomAPI_PointsToBSplineSurface(aPoints).Surface(); + myResult << "Geom_BSplineSurface was created" << std::endl; + + // Compute BSpline surface bounding box. + Bnd_Box aBndBox; + BndLib_AddSurface::AddOptimal(GeomAdaptor_Surface(aBSplineSurf), Precision::Confusion(), aBndBox); + myResult << "Bounding box:" << std::endl; + myResult << " Min corner = [ " + << aBndBox.CornerMin().X() << ", " + << aBndBox.CornerMin().Y() << ", " + << aBndBox.CornerMin().Z() << " ]" << std::endl; + myResult << " Max corner = [ " + << aBndBox.CornerMax().X() << ", " + << aBndBox.CornerMax().Y() << ", " + << aBndBox.CornerMax().Z() << " ]" << std::endl; + + Handle(AIS_ColoredShape) anAisBSplineSurf = new AIS_ColoredShape( + BRepBuilderAPI_MakeFace(aBSplineSurf, Precision::Confusion()).Shape()); + Handle(AIS_ColoredShape) anAisBndBox = new AIS_ColoredShape( + BRepPrimAPI_MakeBox(aBndBox.CornerMin(), aBndBox.CornerMax()).Shell()); + myObject3d.Append(anAisBSplineSurf); + myObject3d.Append(anAisBndBox); + myContext->SetDisplayMode(anAisBndBox, 0, Standard_True); +} + +void GeometrySamples::BoundingBoxOfCurves3dSample() +{ + // Define points. + gp_Pnt aPnt1(0.0, 0.0, 10.0); + gp_Pnt aPnt2(5.0, 5.0, 5.0); + gp_Pnt aPnt3(10.0, 10.0, 15.0); + gp_Pnt aPnt4(15.0, 5.0, 20.0); + + // Add points to the curve poles array. + TColgp_Array1OfPnt aPoles(1, 4); + aPoles.SetValue(1, aPnt1); + aPoles.SetValue(2, aPnt2); + aPoles.SetValue(3, aPnt3); + aPoles.SetValue(4, aPnt4); + + // Make a BSpline curve from the points array. + Handle(Geom_BSplineCurve) aBSplineCurve = GeomAPI_PointsToBSpline(aPoles).Curve(); + myResult << "aBSplineCurve was created" << std::endl; + + // Compute BSpline curve bounding box. + Bnd_Box aBndBox; + BndLib_Add3dCurve::AddOptimal(GeomAdaptor_Curve(aBSplineCurve), Precision::Confusion(), aBndBox); + myResult << "Bounding box:" << std::endl; + myResult << " Min corner = [ " + << aBndBox.CornerMin().X() << ", " + << aBndBox.CornerMin().Y() << ", " + << aBndBox.CornerMin().Z() << " ]" << std::endl; + myResult << " Max corner = [ " + << aBndBox.CornerMax().X() << ", " + << aBndBox.CornerMax().Y() << ", " + << aBndBox.CornerMax().Z() << " ]" << std::endl; + + Handle(AIS_ColoredShape) anAisBSplineCurve = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aBSplineCurve).Shape()); + Handle(AIS_ColoredShape) anAisBndBox = new AIS_ColoredShape (BRepPrimAPI_MakeBox(aBndBox.CornerMin(), aBndBox.CornerMax()).Shell()); + myObject3d.Append(anAisBSplineCurve); + myObject3d.Append(anAisBndBox); + myContext->SetDisplayMode(anAisBndBox, 0, Standard_True); +} + +void GeometrySamples::BoundingBoxOfCurves2dSample() +{ + // Define points. + gp_Pnt2d aPnt1(0.0, 0.0); + gp_Pnt2d aPnt2(5.0, 5.0); + gp_Pnt2d aPnt3(10.0, 10.0); + gp_Pnt2d aPnt4(15.0, 5.0); + + // Add points to the curve poles array. + TColgp_Array1OfPnt2d aPoles(1, 4); + aPoles.SetValue(1, aPnt1); + aPoles.SetValue(2, aPnt2); + aPoles.SetValue(3, aPnt3); + aPoles.SetValue(4, aPnt4); + + // Make a BSpline curve from the points array. + Handle(Geom2d_BSplineCurve) aBSplineCurve = Geom2dAPI_PointsToBSpline(aPoles).Curve(); + + // Compute BSpline curve bounding box. + Bnd_Box2d aBndBox; + BndLib_Add2dCurve::AddOptimal(aBSplineCurve, 0.0, 1.0, Precision::PConfusion(), aBndBox); + Standard_Real aXmin, aYmin, aXmax, aYmax; + aBndBox.Get(aXmin, aYmin, aXmax, aYmax); + + myResult << "Bounding box:" << std::endl; + myResult << " Min corner = [ " << aXmin << ", " << aYmin << " ]" << std::endl; + myResult << " Max corner = [ " << aXmax << ", " << aYmax << " ]" << std::endl; + + Handle(AdaptorCurve2d_AIS) anAisBSpline = new AdaptorCurve2d_AIS(aBSplineCurve); + + Handle(AdaptorVec_AIS) anAisVec1 = new AdaptorVec_AIS(gp_Pnt2d(aXmin, aYmin), gp_Pnt2d(aXmin, aYmax)); + Handle(AdaptorVec_AIS) anAisVec2 = new AdaptorVec_AIS(gp_Pnt2d(aXmin, aYmax), gp_Pnt2d(aXmax, aYmax)); + Handle(AdaptorVec_AIS) anAisVec3 = new AdaptorVec_AIS(gp_Pnt2d(aXmax, aYmax), gp_Pnt2d(aXmax, aYmin)); + Handle(AdaptorVec_AIS) anAisVec4 = new AdaptorVec_AIS(gp_Pnt2d(aXmax, aYmin), gp_Pnt2d(aXmin, aYmin)); + + myObject2d.Append(anAisBSpline); + myObject2d.Append(anAisVec1); + myObject2d.Append(anAisVec2); + myObject2d.Append(anAisVec3); + myObject2d.Append(anAisVec4); +} + +void GeometrySamples::DumpCircleInfoSample() +{ + // Define a circle placed in the origin of XY coordinate + // plane and with the radius equal to 0.5. + gp_Circ aCirc(gp::XOY(), 0.5); + // Create a closed circular curve. + Handle(Geom_Circle) aCircCurve = new Geom_Circle(aCirc); + myResult << "Geom_Circle was created:" << std::endl; + myResult << " Center = [ " + << aCircCurve->Position().Location().X() << ", " + << aCircCurve->Position().Location().Y() << ", " + << aCircCurve->Position().Location().Z() << " ]" + << std::endl; + myResult << " Radius = " << aCircCurve->Radius() << std::endl; + myResult << " Plane normal = [ " + << aCircCurve->Position().Direction().X() << ", " + << aCircCurve->Position().Direction().Y() << ", " + << aCircCurve->Position().Direction().Z() << " ]" + << std::endl; + + Handle(AIS_Circle) anAisCircle = new AIS_Circle(aCircCurve); + Handle(AIS_TextLabel) anAisCenterLabel = new AIS_TextLabel(); + anAisCenterLabel->SetText(" Center"); + anAisCenterLabel->SetPosition(aCircCurve->Position().Location()); + Handle(AIS_Point) anAisCenter = new AIS_Point(new Geom_CartesianPoint(aCirc.Location())); + Handle(AIS_Axis) anAisAxis = new AIS_Axis(new Geom_Axis2Placement(aCircCurve->Position()), AIS_TOAX_ZAxis); + myObject3d.Append(anAisCircle); + myObject3d.Append(anAisCenterLabel); + myObject3d.Append(anAisAxis); +} + +void GeometrySamples::DumpBSplineCurveInfoSample() +{ + // Define points. + gp_Pnt aPnt1(0.0, 0.0, 10.0); + gp_Pnt aPnt2(5.0, 5.0, 5.0); + gp_Pnt aPnt3(10.0, 10.0, 15.0); + gp_Pnt aPnt4(15.0, 5.0, 20.0); + + // Add points to the curve poles array. + TColgp_Array1OfPnt aPoles(1, 4); + aPoles.SetValue(1, aPnt1); + aPoles.SetValue(2, aPnt2); + aPoles.SetValue(3, aPnt3); + aPoles.SetValue(4, aPnt4); + + // Make a BSpline curve from the points array + Handle(Geom_BSplineCurve) aBSplineCurve = GeomAPI_PointsToBSpline(aPoles).Curve(); + myResult << "aBSplineCurve was created:" << std::endl; + myResult << " Degree = " << aBSplineCurve->Degree() << std::endl; + myResult << " Parameter range = [ " + << aBSplineCurve->FirstParameter() << ", " + << aBSplineCurve->LastParameter() << " ]" + << std::endl; + NCollection_List aParams; + aParams.Append(0.75 * aBSplineCurve->FirstParameter() + 0.25 * aBSplineCurve->LastParameter()); + aParams.Append(0.50 * aBSplineCurve->FirstParameter() + 0.50 * aBSplineCurve->LastParameter()); + aParams.Append(0.25 * aBSplineCurve->FirstParameter() + 0.75 * aBSplineCurve->LastParameter()); + myResult << " Curve info:" << std::endl; + for (NCollection_List::Iterator anIt(aParams); anIt.More(); anIt.Next()) + { + Standard_Real aParam = anIt.Value(); + gp_Pnt aPnt; + gp_Vec aVec; + aBSplineCurve->D1(aParam, aPnt, aVec); + myResult << " Param = " << aParam << std::endl; + myResult << " P = [ " << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl; + myResult << " D = [ " << aVec.X() << ", " << aVec.Y() << ", " << aVec.Z() << " ]" << std::endl; + myObject3d.Append(new AIS_Point(new Geom_CartesianPoint(aPnt))); + Handle(AIS_TextLabel) anAisCenterLabel = new AIS_TextLabel(); + Standard_SStream aSS; + aSS << "P [" << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << "]" << std::endl; + aSS << "D [" << aVec.X() << ", " << aVec.Y() << ", " << aVec.Z() << "]" << std::endl; + anAisCenterLabel->SetText(aSS.str().c_str()); + anAisCenterLabel->SetPosition(aPnt); + myObject3d.Append(anAisCenterLabel); + Handle(AIS_Axis) anAisD = new AIS_Axis(new Geom_Axis1Placement(gp_Ax1(aPnt, aVec))); + myObject3d.Append(anAisD); + } + + Handle(AIS_ColoredShape) anAisBSplineCurve = new AIS_ColoredShape (BRepBuilderAPI_MakeEdge(aBSplineCurve).Shape()); + anAisBSplineCurve->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisBSplineCurve); +} diff --git a/samples/qt/OCCTOverview/code/GeometrySamples.h b/samples/qt/OCCTOverview/code/GeometrySamples.h new file mode 100644 index 0000000000..7da4ad7645 --- /dev/null +++ b/samples/qt/OCCTOverview/code/GeometrySamples.h @@ -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 diff --git a/samples/qt/OCCTOverview/code/MakeBottle.cxx b/samples/qt/OCCTOverview/code/MakeBottle.cxx new file mode 100644 index 0000000000..44307e0759 --- /dev/null +++ b/samples/qt/OCCTOverview/code/MakeBottle.cxx @@ -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 + +#include + +#include +#include +#include +#include + +#include + +#include + +#include +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +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 is the top face of the bottleÂ’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; +} diff --git a/samples/qt/OCCTOverview/code/MakeBottle.h b/samples/qt/OCCTOverview/code/MakeBottle.h new file mode 100644 index 0000000000..ad1e783064 --- /dev/null +++ b/samples/qt/OCCTOverview/code/MakeBottle.h @@ -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 +#include + +//! Returns sample bottle TopoDS_Shape +TopoDS_Shape MakeBottle(const Standard_Real theWidth, + const Standard_Real theyHeight, + const Standard_Real theThickness); + +#endif // MAKEBOTTLE_H diff --git a/samples/qt/OCCTOverview/code/Ocaf.xml b/samples/qt/OCCTOverview/code/Ocaf.xml new file mode 100644 index 0000000000..ea269c4b19 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Ocaf.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/qt/OCCTOverview/code/OcafSamples.cxx b/samples/qt/OCCTOverview/code/OcafSamples.cxx new file mode 100644 index 0000000000..0154f48d35 --- /dev/null +++ b/samples/qt/OCCTOverview/code/OcafSamples.cxx @@ -0,0 +1,629 @@ +// 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + + // 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 modified."; + 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(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + // 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 modified."; + 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_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_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_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(); +} diff --git a/samples/qt/OCCTOverview/code/OcafSamples.h b/samples/qt/OCCTOverview/code/OcafSamples.h new file mode 100644 index 0000000000..96116efccf --- /dev/null +++ b/samples/qt/OCCTOverview/code/OcafSamples.h @@ -0,0 +1,81 @@ +// 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 +#include +#include + +//! 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) + { + // + } + + 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: + + TCollection_AsciiString myFileName; + Handle(V3d_Viewer) myViewer; + Handle(TDocStd_Document) myOcafDoc; +}; + +#endif //OCAFSAMPLES_H diff --git a/samples/qt/OCCTOverview/code/Sample2D_Face.cxx b/samples/qt/OCCTOverview/code/Sample2D_Face.cxx new file mode 100644 index 0000000000..462ec01f9a --- /dev/null +++ b/samples/qt/OCCTOverview/code/Sample2D_Face.cxx @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +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_PresentationManager)& , + 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_PresentationManager)& 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_PresentationManager)& 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); +} diff --git a/samples/qt/OCCTOverview/code/Sample2D_Face.h b/samples/qt/OCCTOverview/code/Sample2D_Face.h new file mode 100644 index 0000000000..8222593f9a --- /dev/null +++ b/samples/qt/OCCTOverview/code/Sample2D_Face.h @@ -0,0 +1,108 @@ +// 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 +#include +#include +#include +#include +#include + +//! 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_PresentationManager)& 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_PresentationManager)& thePrsMgr, + const SelectMgr_SequenceOfOwner& theOwners) Standard_OVERRIDE; + + //! Method for advanced customizable highlighting of picked object. + virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager)& 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 diff --git a/samples/qt/OCCTOverview/code/Sample2D_Image.cxx b/samples/qt/OCCTOverview/code/Sample2D_Image.cxx new file mode 100644 index 0000000000..e86f849365 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Sample2D_Image.cxx @@ -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 + +#include "Sample2D_Image.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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_Texture2D) aTexture = new Graphic3d_Texture2D (myFilename); + aTexture->DisableModulate(); + myDrawer->ShadingAspect()->Aspect()->SetTextureMap (aTexture); + myDrawer->ShadingAspect()->Aspect()->SetTextureMapOn(); +} diff --git a/samples/qt/OCCTOverview/code/Sample2D_Image.h b/samples/qt/OCCTOverview/code/Sample2D_Image.h new file mode 100644 index 0000000000..c3b9a886b4 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Sample2D_Image.h @@ -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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//! 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 diff --git a/samples/qt/OCCTOverview/code/Sample2D_Markers.cxx b/samples/qt/OCCTOverview/code/Sample2D_Markers.cxx new file mode 100644 index 0000000000..a564bdcca7 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Sample2D_Markers.cxx @@ -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 + +// 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_PresentationManager)& , + 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); + } +} diff --git a/samples/qt/OCCTOverview/code/Sample2D_Markers.h b/samples/qt/OCCTOverview/code/Sample2D_Markers.h new file mode 100644 index 0000000000..f0252669f4 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Sample2D_Markers.h @@ -0,0 +1,89 @@ +// 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 +#include +#include + +//! 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_PresentationManager)& /*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 diff --git a/samples/qt/OCCTOverview/code/Samples.qrc b/samples/qt/OCCTOverview/code/Samples.qrc new file mode 100644 index 0000000000..5bc1783345 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Samples.qrc @@ -0,0 +1,11 @@ + + + Geometry.xml + Topology.xml + Triangulation.xml + DataExchange.xml + Viewer3d.xml + Viewer2d.xml + Ocaf.xml + + diff --git a/samples/qt/OCCTOverview/code/TOcafFunction_BoxDriver.cxx b/samples/qt/OCCTOverview/code/TOcafFunction_BoxDriver.cxx new file mode 100644 index 0000000000..6589efab1f --- /dev/null +++ b/samples/qt/OCCTOverview/code/TOcafFunction_BoxDriver.cxx @@ -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 +#include +#include +#include + +//======================================================================= +//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; +} diff --git a/samples/qt/OCCTOverview/code/TOcafFunction_BoxDriver.h b/samples/qt/OCCTOverview/code/TOcafFunction_BoxDriver.h new file mode 100644 index 0000000000..bbeed55506 --- /dev/null +++ b/samples/qt/OCCTOverview/code/TOcafFunction_BoxDriver.h @@ -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 +#include + +//! 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 diff --git a/samples/qt/OCCTOverview/code/TOcafFunction_CutDriver.cxx b/samples/qt/OCCTOverview/code/TOcafFunction_CutDriver.cxx new file mode 100644 index 0000000000..cbbaca349b --- /dev/null +++ b/samples/qt/OCCTOverview/code/TOcafFunction_CutDriver.cxx @@ -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 +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +//======================================================================= +//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; +} diff --git a/samples/qt/OCCTOverview/code/TOcafFunction_CutDriver.h b/samples/qt/OCCTOverview/code/TOcafFunction_CutDriver.h new file mode 100644 index 0000000000..9b25cecf95 --- /dev/null +++ b/samples/qt/OCCTOverview/code/TOcafFunction_CutDriver.h @@ -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 +#include + +//! 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 diff --git a/samples/qt/OCCTOverview/code/TOcafFunction_CylDriver.cxx b/samples/qt/OCCTOverview/code/TOcafFunction_CylDriver.cxx new file mode 100644 index 0000000000..3b687e5172 --- /dev/null +++ b/samples/qt/OCCTOverview/code/TOcafFunction_CylDriver.cxx @@ -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 +#include +#include +#include +#include +#include + +//======================================================================= +//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; +} diff --git a/samples/qt/OCCTOverview/code/TOcafFunction_CylDriver.h b/samples/qt/OCCTOverview/code/TOcafFunction_CylDriver.h new file mode 100644 index 0000000000..e6d2534b71 --- /dev/null +++ b/samples/qt/OCCTOverview/code/TOcafFunction_CylDriver.h @@ -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 +#include + +//! 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 diff --git a/samples/qt/OCCTOverview/code/TOcaf_Application.cxx b/samples/qt/OCCTOverview/code/TOcaf_Application.cxx new file mode 100644 index 0000000000..ceea5843f0 --- /dev/null +++ b/samples/qt/OCCTOverview/code/TOcaf_Application.cxx @@ -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 +#include +#include +#include +#include + +#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()); +} diff --git a/samples/qt/OCCTOverview/code/TOcaf_Application.h b/samples/qt/OCCTOverview/code/TOcaf_Application.h new file mode 100644 index 0000000000..bcaaf03a06 --- /dev/null +++ b/samples/qt/OCCTOverview/code/TOcaf_Application.h @@ -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 +#include + +//! Sample OCAF application +class TOcaf_Application : public TDocStd_Application +{ + DEFINE_STANDARD_RTTI_INLINE(TOcaf_Application, TDocStd_Application) +public: + + Standard_EXPORT TOcaf_Application(); +}; + +#endif diff --git a/samples/qt/OCCTOverview/code/Topology.xml b/samples/qt/OCCTOverview/code/Topology.xml new file mode 100644 index 0000000000..a49a69e84a --- /dev/null +++ b/samples/qt/OCCTOverview/code/Topology.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/qt/OCCTOverview/code/TopologySamples.cxx b/samples/qt/OCCTOverview/code/TopologySamples.cxx new file mode 100644 index 0000000000..65f0e38a2d --- /dev/null +++ b/samples/qt/OCCTOverview/code/TopologySamples.cxx @@ -0,0 +1,1884 @@ +// 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 "TopologySamples.h" + +#include "AdaptorVec_AIS.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +void TopologySamples::ExecuteSample (const TCollection_AsciiString& theSampleName) +{ + Standard_Boolean anIsSamplePresent = Standard_True; + FindSourceCode(theSampleName); + if (theSampleName == "Vertex3dSample") + Vertex3dSample(); + else if (theSampleName == "Edge3dSample") + Edge3dSample(); + else if (theSampleName == "Face3dSample") + Face3dSample(); + else if (theSampleName == "Wire3dSample") + Wire3dSample(); + else if (theSampleName == "Shell3dSample") + Shell3dSample(); + else if (theSampleName == "Solid3dSample") + Solid3dSample(); + else if (theSampleName == "Edge2dSample") + Edge2dSample(); + else if (theSampleName == "Box3dSample") + Box3dSample(); + else if (theSampleName == "Cylinder3dSample") + Cylinder3dSample(); + else if (theSampleName == "Revolution3dSample") + Revolution3dSample(); + else if (theSampleName == "TopologyIterator3dSample") + TopologyIterator3dSample(); + else if (theSampleName == "TopologyExplorer3dSample") + TopologyExplorer3dSample(); + else if (theSampleName == "AssessToCurve3dSample") + AssessToCurve3dSample(); + else if (theSampleName == "AssessToCompositeCurve3dSample") + AssessToCompositeCurve3dSample(); + else if (theSampleName == "AssessToSurface3dSample") + AssessToSurface3dSample(); + else if (theSampleName == "Common3dSample") + Common3dSample(); + else if (theSampleName == "Cut3dSample") + Cut3dSample(); + else if (theSampleName == "Cut3dSample") + Cut3dSample(); + else if (theSampleName == "Fuse3dSample") + Fuse3dSample(); + else if (theSampleName == "Section3dSample") + Section3dSample(); + else if (theSampleName == "Splitter3dSample") + Splitter3dSample(); + else if (theSampleName == "Defeaturing3dSample") + Defeaturing3dSample(); + else if (theSampleName == "Fillet3dSample") + Fillet3dSample(); + else if (theSampleName == "Chamfer3dSample") + Chamfer3dSample(); + else if (theSampleName == "Offset3dSample") + Offset3dSample(); + else if (theSampleName == "Evolved3dSample") + Evolved3dSample(); + else if (theSampleName == "Copy3dSample") + Copy3dSample(); + else if (theSampleName == "Transform3dSample") + Transform3dSample(); + else if (theSampleName == "ConvertToNurbs3dSample") + ConvertToNurbs3dSample(); + else if (theSampleName == "SewContiguousFaces3dSample") + SewContiguousFaces3dSample(); + else if (theSampleName == "CheckValidity3dSample") + CheckValidity3dSample(); + else if (theSampleName == "ComputeLinearProperties3dSample") + ComputeLinearProperties3dSample(); + else if (theSampleName == "ComputeSurfaceProperties3dSample") + ComputeSurfaceProperties3dSample(); + else if (theSampleName == "ComputeVolumeProperties3dSample") + ComputeVolumeProperties3dSample(); + else + { + myResult << "No function found: " << theSampleName; + myCode += TCollection_AsciiString("No function found: ") + theSampleName; + anIsSamplePresent = Standard_False; + } + myIsProcessed = anIsSamplePresent; +} + +void TopologySamples::Vertex3dSample() +{ + // Make a vertex from a 3D point. + gp_Pnt aPnt(0.0, 0.0, 10.0); + TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(aPnt); + myResult << "TopoDS_Vertex was created at [ " + << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() + << " ]" << std::endl; + + Handle(AIS_Shape) aAisVertex = new AIS_Shape(aVertex); + Handle(AIS_TextLabel) anAisLabel = new AIS_TextLabel(); + Standard_SStream aSS; + aSS << "TopoDS_Vertex [" << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << "]" << std::endl; + anAisLabel->SetText(aSS.str().c_str()); + anAisLabel->SetPosition(aPnt); + myObject3d.Append(aAisVertex); + myObject3d.Append(anAisLabel); +} + +void TopologySamples::Edge3dSample() +{ + // Make an edge from two 3D points. + gp_Pnt aPnt1(0.0, 10.0, 0.0); + gp_Pnt aPnt2(10.0, 10.0, 0.0); + TopoDS_Edge anEdgeP12 = BRepBuilderAPI_MakeEdge(aPnt1, aPnt2); + myResult << "TopoDS_Edge between [ " + << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() + << " ] and [ " + << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() + << " ] was created in yellow" << std::endl + << std::endl; + + // Make an edge from a circular segment. + // Create a circle in XY plane of the radius 5.0. + gp_Circ aCirc(gp::XOY(), 5.0); + // Make a circular edge from the 1st quoter in the parametric space. + TopoDS_Edge anEdgeCirc = BRepBuilderAPI_MakeEdge(aCirc, 0.0, M_PI_2); + myResult << "TopoDS_Edge on the circle's 1st quoter" << std::endl + << "with the center at [ " + << aCirc.Location().X() << ", " << aCirc.Location().Y() << ", " << aCirc.Location().Z() + << " ] and R = " << aCirc.Radius() << " was created in red" << std::endl + << std::endl; + + // Make an edge from a 3D curve (BSpline). + // Define points. + gp_Pnt aPole1(0.0, 0.0, 10.0); + gp_Pnt aPole2(5.0, 5.0, 5.0); + gp_Pnt aPole3(10.0, 10.0, 15.0); + gp_Pnt aPole4(15.0, 5.0, 20.0); + // Add points to the curve poles array. + TColgp_Array1OfPnt aPoles(1, 4); + aPoles.SetValue(1, aPole1); + aPoles.SetValue(2, aPole2); + aPoles.SetValue(3, aPole3); + aPoles.SetValue(4, aPole4); + // Make a BSpline curve from the points array + Handle(Geom_BSplineCurve) aBSplineCurve = GeomAPI_PointsToBSpline(aPoles).Curve(); + // Make an edge between two point on the BSpline curve. + gp_Pnt aPntOnCurve1, aPntOnCurve2; + aBSplineCurve->D0 (0.75 * aBSplineCurve->FirstParameter() + + 0.25 * aBSplineCurve->LastParameter(), + aPntOnCurve1); + aBSplineCurve->D0 (0.25 * aBSplineCurve->FirstParameter() + + 0.75 * aBSplineCurve->LastParameter(), + aPntOnCurve2); + TopoDS_Edge anEdgeBSpline = BRepBuilderAPI_MakeEdge(aBSplineCurve, aPntOnCurve1, aPntOnCurve2); + myResult << "TopoDS_Edge on the BSpline curve" << std::endl + << "between [ " + << aPntOnCurve1.X() << ", " << aPntOnCurve1.Y() << ", " << aPntOnCurve1.Z() + << " ] and [ " + << aPntOnCurve2.X() << ", " << aPntOnCurve2.Y() << ", " << aPntOnCurve2.Z() + << " ]" << std::endl + << "was created in green" << std::endl; + + Handle(AIS_ColoredShape) anAisEdgeP12 = new AIS_ColoredShape(anEdgeP12); + Handle(AIS_ColoredShape) anAisEdgeCirc = new AIS_ColoredShape(anEdgeCirc); + Handle(AIS_ColoredShape) anAisEdgeBSpline = new AIS_ColoredShape(anEdgeBSpline); + anAisEdgeP12->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisEdgeCirc->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisEdgeBSpline->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisEdgeP12); + myObject3d.Append(anAisEdgeCirc); + myObject3d.Append(anAisEdgeBSpline); + Handle(AIS_TextLabel) anAisEdgeP12Label = new AIS_TextLabel(); + anAisEdgeP12Label->SetText("Edge between two points"); + anAisEdgeP12Label->SetPosition(0.5 * (aPnt1.XYZ() + aPnt2.XYZ())); + anAisEdgeP12Label->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + myObject3d.Append(anAisEdgeP12Label); + Handle(AIS_TextLabel) anAisEdgeCircLabel = new AIS_TextLabel(); + anAisEdgeCircLabel->SetText("Circular edge"); + anAisEdgeCircLabel->SetPosition(aCirc.Location()); + anAisEdgeCircLabel->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisEdgeCircLabel); + Handle(AIS_TextLabel) anAisEdgeBSplineLabel = new AIS_TextLabel(); + anAisEdgeBSplineLabel->SetText("BSpline edge"); + anAisEdgeBSplineLabel->SetPosition(aPole3); + anAisEdgeBSplineLabel->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisEdgeBSplineLabel); + TopoDS_Vertex anEdgeP12_V1, anEdgeP12_V2; + TopExp::Vertices(anEdgeP12, anEdgeP12_V1, anEdgeP12_V2); + myObject3d.Append(new AIS_Shape(anEdgeP12_V1)); + myObject3d.Append(new AIS_Shape(anEdgeP12_V2)); + TopoDS_Vertex anEdgeCirc_V1, anEdgeCirc_V2; + TopExp::Vertices(anEdgeCirc, anEdgeCirc_V1, anEdgeCirc_V2); + myObject3d.Append(new AIS_Shape(anEdgeCirc_V1)); + myObject3d.Append(new AIS_Shape(anEdgeCirc_V2)); + TopoDS_Vertex anEdgeBSpline_V1, anEdgeBSpline_V2; + TopExp::Vertices(anEdgeBSpline, anEdgeBSpline_V1, anEdgeBSpline_V2); + myObject3d.Append(new AIS_Shape(anEdgeBSpline_V1)); + myObject3d.Append(new AIS_Shape(anEdgeBSpline_V2)); +} + +void TopologySamples::Face3dSample() +{ + // Make a face from a sphere with the center + // at [0.0, 0.0, 10.0] and R = 5. + gp_Sphere aSphere(gp_Ax3(gp_Pnt(0.0, 0.0, 10.0), gp::DZ()), 5.0); + TopoDS_Face aFaceSphere = BRepBuilderAPI_MakeFace(aSphere); + myResult << "TopoDS_Face on the sphere with" << std::endl + << "the center at [ " + << aSphere.Location().X() << ", " << aSphere.Location().Y() << ", " << aSphere.Location().Z() + << " ] and R = " << aSphere.Radius() << " was created in yellow" << std::endl + << std::endl; + + // 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); + myResult << "TopoDS_Face on the rectangle was created in red" << std::endl + << std::endl; + + // Make a face from a BSpline surface. + // Define a 4x4 grid of points for BSpline surface. + TColgp_Array2OfPnt aPoints(1, 4, 1, 4); + for (Standard_Integer i = 1; i <= 4; ++i) + { + gp_Pnt aPnt; + aPnt.SetX(5.0 * i); + for (Standard_Integer j = 1; j <= 4; ++j) + { + aPnt.SetY(5.0 * j); + if (1 < i && i < 4 && 1 < j && j < 4) + { + aPnt.SetZ(15.0); + } + else + { + aPnt.SetZ(10.0); + } + aPoints.SetValue(i, j, aPnt); + } + } + // Make a BSpline surface from the points array. + Handle(Geom_BSplineSurface) aBSplineSurf = GeomAPI_PointsToBSplineSurface(aPoints).Surface(); + Standard_Real aU1, aU2, aV1, aV2; + aBSplineSurf->Bounds(aU1, aU2, aV1, aV2); + TopoDS_Face aFaceBSpline = BRepBuilderAPI_MakeFace(aBSplineSurf, aU1, aU2, aV1, aV2, Precision::Confusion()); + myResult << "TopoDS_Face on the BSpline surface was created in green" << std::endl << std::endl; + + Handle(AIS_ColoredShape) anAisFaceSphere = new AIS_ColoredShape(aFaceSphere); + Handle(AIS_ColoredShape) anAisFaceRect = new AIS_ColoredShape(aFaceRect); + Handle(AIS_ColoredShape) anAisFaceBSpline = new AIS_ColoredShape(aFaceBSpline); + anAisFaceSphere->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisFaceRect->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisFaceBSpline->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisFaceSphere); + myObject3d.Append(anAisFaceRect); + myObject3d.Append(anAisFaceBSpline); + Handle(AIS_TextLabel) anAisFaceSphereLabel = new AIS_TextLabel(); + anAisFaceSphereLabel->SetText("Spherical face"); + anAisFaceSphereLabel->SetPosition(aSphere.Location().XYZ() + aSphere.Radius() * gp::DZ().XYZ()); + anAisFaceSphereLabel->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + myObject3d.Append(anAisFaceSphereLabel); + Handle(AIS_TextLabel) anAisFaceRectLabel = new AIS_TextLabel(); + anAisFaceRectLabel->SetText("Flat rectangular face"); + anAisFaceRectLabel->SetPosition(aPln.Location().XYZ() + 2.5 * gp::DZ().XYZ()); + anAisFaceRectLabel->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisFaceRectLabel); + Handle(AIS_TextLabel) anAisFaceBSplineLabel = new AIS_TextLabel(); + anAisFaceBSplineLabel->SetText("BSpline face"); + anAisFaceBSplineLabel->SetPosition(aPoints(4, 4)); + anAisFaceBSplineLabel->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisFaceBSplineLabel); +} + +void TopologySamples::Wire3dSample() +{ + // Make a wire from edges created on a set of points. + // Add points to the curve poles array. + TColgp_Array1OfPnt aPoints(1, 4); + aPoints.SetValue(1, gp_Pnt(0.0, 0.0, 0.0)); + aPoints.SetValue(2, gp_Pnt(20.0, 0.0, 0.0)); + aPoints.SetValue(3, gp_Pnt(20.0, 10.0, 0.0)); + aPoints.SetValue(4, gp_Pnt(0.0, 10.0, 0.0)); + // A wire maker contains an empty wire. + BRepBuilderAPI_MakeWire aMakeWire; + for (Standard_Integer i = 1; i <= 4; ++i) + { + Standard_Integer i1 = i; + Standard_Integer i2 = i1 < 4 ? i1 + 1 : 1; + const gp_Pnt& aPnt1 = aPoints.Value(i1); + const gp_Pnt& aPnt2 = aPoints.Value(i2); + TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aPnt1, aPnt2); + // Add an edge to the wire under construction. + // The edge must be connectible to the wire under construction, and, + // unless it is the first edge of the wire, must satisfy the following + // condition: one of its vertices must be geometrically coincident + // with one of the vertices of the wire (provided that the highest + // tolerance factor is assigned to the two vertices). + // It could also be the same vertex. + // Warning + // If the edge is not connectible to the wire under construction it is not added. + // The function IsDone will return false and the function + // Wire will raise an error, until a new connectible edge is added. + aMakeWire.Add(anEdge); + Standard_ASSERT_VOID(aMakeWire.IsDone(), "Added edge isn't connectible!"); + } + // Retrieve a constructed wire. + TopoDS_Wire aWire = aMakeWire.Wire(); + myResult << "TopoDS_Wire was created. Vertices :" << std::endl; + // Retrieve wire vertices. 4 vertices are expected, because of + // edges connecting during wire constructing. + TopTools_IndexedMapOfShape aVertices; + TopExp::MapShapes(aWire, TopAbs_VERTEX, aVertices); + for (TopTools_IndexedMapOfShape::Iterator anIt(aVertices); anIt.More(); anIt.Next()) + { + TopoDS_Vertex aVertex = TopoDS::Vertex(anIt.Value()); + gp_Pnt aPnt = BRep_Tool::Pnt(aVertex); + myResult << "[ " << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl; + Handle(AIS_Shape) anAisVertex = new AIS_Shape(aVertex); + myObject3d.Append(anAisVertex); + } + + Handle(AIS_Shape) anAisWire = new AIS_Shape(aWire); + myObject3d.Append(anAisWire); +} + +void TopologySamples::Shell3dSample() +{ + // Make a shell from a cylinder with R = 5 and directed along Z axis + gp_Cylinder aCyl(gp::XOY(), 5.0); + Handle(Geom_Surface) aCylSurf = new Geom_CylindricalSurface(aCyl); + TopoDS_Shell aCylShell = BRepBuilderAPI_MakeShell(aCylSurf, 0.0, 2.0 * M_PI, -10.0, +10.0); + myResult << "TopoDS_Shell on the cylinder R = " << aCyl.Radius() << std::endl + << "with axis [ " + << aCyl.Position().Direction().X() << ", " + << aCyl.Position().Direction().Y() << ", " + << aCyl.Position().Direction().Z() << " ]" << std::endl + << "limited in length [-10 ... +10] was created" << std::endl; + + Handle(AIS_Shape) anAisShell = new AIS_Shape(aCylShell); + myObject3d.Append(anAisShell); +} + +void TopologySamples::Solid3dSample() +{ + // Make a torus from a shell. + gp_Torus aTorus(gp::XOY(), 20.0, 7.5); + Handle(Geom_Surface) aTorusSurf = new Geom_ToroidalSurface(aTorus); + TopoDS_Shell aTorusShell = BRepBuilderAPI_MakeShell(aTorusSurf, 0.0, 2.0 * M_PI, 0.0, 2.0 * M_PI); + // Make a solid on the torus shell. + TopoDS_Solid aTorusSolid = BRepBuilderAPI_MakeSolid(aTorusShell); + myResult << "TopoDS_Solid on the torus with" << std::endl + << "R major = " << aTorus.MajorRadius() << std::endl + << "R minor = " << aTorus.MinorRadius() << std::endl + << "was created" << std::endl; + + Handle(AIS_Shape) anAisSolid = new AIS_Shape(aTorusSolid); + myObject3d.Append(anAisSolid); +} + +void TopologySamples::Edge2dSample() +{ + // Make an edge from two 2D points. + gp_Pnt2d aPnt1(0.0, 10.0); + gp_Pnt2d aPnt2(10.0, 10.0); + TopoDS_Edge anEdgeP12 = BRepBuilderAPI_MakeEdge2d(aPnt1, aPnt2); + myResult << "TopoDS_Edge between [ " + << aPnt1.X() << ", " << aPnt1.Y() << " ] and [ " + << aPnt2.X() << ", " << aPnt2.Y() << " ] was created in yellow" << std::endl + << std::endl; + + // Make an edge from a circular segment. + // Create a circle of the radius 5.0. + gp_Circ2d aCirc(gp::OX2d(), 5.0); + // Make a circular edge from the 1st quoter in the parametric space. + TopoDS_Edge anEdgeCirc = BRepBuilderAPI_MakeEdge2d(aCirc, 0.0, M_PI_2); + myResult << "TopoDS_Edge on the 2D circle's 1st quoter" << std::endl + << "with the center at [ " << aCirc.Location().X() << ", " << aCirc.Location().Y() + << " ] and R = " << aCirc.Radius() << " was created in red" << std::endl + << std::endl; + + // Make an edge from a 2D curve (BSpline). + // Define points. + gp_Pnt2d aPole1(0.0, 0.0); + gp_Pnt2d aPole2(5.0, 5.0); + gp_Pnt2d aPole3(10.0, 10.0); + gp_Pnt2d aPole4(15.0, 5.0); + // Add points to the curve poles array. + TColgp_Array1OfPnt2d aPoles(1, 4); + aPoles.SetValue(1, aPole1); + aPoles.SetValue(2, aPole2); + aPoles.SetValue(3, aPole3); + aPoles.SetValue(4, aPole4); + // Make a BSpline curve from the points array + Handle(Geom2d_BSplineCurve) aBSplineCurve = Geom2dAPI_PointsToBSpline(aPoles).Curve(); + // Make an edge between two point on the BSpline curve. + gp_Pnt2d aPntOnCurve1, aPntOnCurve2; + aBSplineCurve->D0 (0.75 * aBSplineCurve->FirstParameter() + + 0.25 * aBSplineCurve->LastParameter(), + aPntOnCurve1); + aBSplineCurve->D0 (0.25 * aBSplineCurve->FirstParameter() + + 0.75 * aBSplineCurve->LastParameter(), + aPntOnCurve2); + TopoDS_Edge anEdgeBSpline = BRepBuilderAPI_MakeEdge2d(aBSplineCurve, aPntOnCurve1, aPntOnCurve2); + myResult << "TopoDS_Edge on the 2D BSpline curve" << std::endl + << "between [ " << aPntOnCurve1.X() << ", " << aPntOnCurve1.Y() + << " ] and [ " << aPntOnCurve2.X() << ", " << aPntOnCurve2.Y() << " ]" << std::endl + << "was created in green" << std::endl; + + Handle(AIS_ColoredShape) anAisEdgeP12 = new AIS_ColoredShape(anEdgeP12); + Handle(AIS_ColoredShape) anAisEdgeCirc = new AIS_ColoredShape(anEdgeCirc); + Handle(AIS_ColoredShape) anAisEdgeBSpline = new AIS_ColoredShape(anEdgeBSpline); + anAisEdgeP12->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisEdgeCirc->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisEdgeBSpline->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject2d.Append(anAisEdgeP12); + myObject2d.Append(anAisEdgeCirc); + myObject2d.Append(anAisEdgeBSpline); + Handle(AIS_TextLabel) anAisEdgeP12Label = new AIS_TextLabel(); + anAisEdgeP12Label->SetText("Edge between two 2d points"); + anAisEdgeP12Label->SetPosition(0.5 * (gp_XYZ(aPnt1.X(), aPnt1.Y() + 0.5, 0.0) + gp_XYZ(aPnt2.X(), aPnt2.Y() + 0.5, 0.0))); + anAisEdgeP12Label->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + myObject2d.Append(anAisEdgeP12Label); + Handle(AIS_TextLabel) anAisEdgeCircLabel = new AIS_TextLabel(); + anAisEdgeCircLabel->SetText("Circular edge"); + anAisEdgeCircLabel->SetPosition(gp_XYZ(aCirc.Location().X(), aCirc.Location().Y() + 0.5, 0.0)); + anAisEdgeCircLabel->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject2d.Append(anAisEdgeCircLabel); + Handle(AIS_TextLabel) anAisEdgeBSplineLabel = new AIS_TextLabel(); + anAisEdgeBSplineLabel->SetText("BSpline edge"); + anAisEdgeBSplineLabel->SetPosition(gp_XYZ(aPole3.X(), aPole3.Y() + 0.5, 0.0)); + anAisEdgeBSplineLabel->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject2d.Append(anAisEdgeBSplineLabel); + TopoDS_Vertex anEdgeP12_V1, anEdgeP12_V2; + TopExp::Vertices(anEdgeP12, anEdgeP12_V1, anEdgeP12_V2); + myObject2d.Append(new AIS_Shape(anEdgeP12_V1)); + myObject2d.Append(new AIS_Shape(anEdgeP12_V2)); + TopoDS_Vertex anEdgeCirc_V1, anEdgeCirc_V2; + TopExp::Vertices(anEdgeCirc, anEdgeCirc_V1, anEdgeCirc_V2); + myObject2d.Append(new AIS_Shape(anEdgeCirc_V1)); + myObject2d.Append(new AIS_Shape(anEdgeCirc_V2)); + TopoDS_Vertex anEdgeBSpline_V1, anEdgeBSpline_V2; + TopExp::Vertices(anEdgeBSpline, anEdgeBSpline_V1, anEdgeBSpline_V2); + myObject2d.Append(new AIS_Shape(anEdgeBSpline_V1)); + myObject2d.Append(new AIS_Shape(anEdgeBSpline_V2)); +} + +void TopologySamples::Box3dSample() +{ + // Make a box with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 5.0; + Standard_Real aSizeY = 10.0; + Standard_Real aSizeZ = 15.0; + TopoDS_Shape aBox1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow" << std::endl; + + // Make a box by two points. + gp_Pnt aPnt1(10.0, 0.0, 0.0); + gp_Pnt aPnt2(20.0, 10.0, 15.0); + TopoDS_Shape aBox2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2); + myResult << "Box with corners [" + << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() + << "] and [" + << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() + << "] was created in red" << std::endl; + + Handle(AIS_ColoredShape) anAisBox1 = new AIS_ColoredShape(aBox1); + Handle(AIS_ColoredShape) anAisBox2 = new AIS_ColoredShape(aBox2); + anAisBox1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisBox2->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisBox1); + myObject3d.Append(anAisBox2); +} + +void TopologySamples::Cylinder3dSample() +{ + // Make a cylinder of the specified radius and length. + Standard_Real aRadius1 = 5.0; + Standard_Real aLength1 = 15.0; + TopoDS_Shape aCyl1 = BRepPrimAPI_MakeCylinder(aRadius1, aLength1); + myResult << "Cylinder with Radius = " << aRadius1 + << " and Length = " << aLength1 + << " was created in yellow" << std::endl; + + // Make a cylinder of the specified radius, length and sector angle. + Standard_Real aRadius2 = 8.0; + Standard_Real aLength2 = 25.0; + Standard_Real anAngle = M_PI_2; + TopoDS_Shape aCyl2 = BRepPrimAPI_MakeCylinder(aRadius2, aLength2, anAngle); + myResult << "Cylinder with Radius = " << aRadius2 + << " , Length = " << aLength2 + << " and Angle = " << anAngle + << " was created in red" << std::endl; + + Handle(AIS_ColoredShape) anAisCyl1 = new AIS_ColoredShape(aCyl1); + Handle(AIS_ColoredShape) anAisCyl2 = new AIS_ColoredShape(aCyl2); + anAisCyl1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisCyl2->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisCyl1); + myObject3d.Append(anAisCyl2); +} + +void TopologySamples::Revolution3dSample() +{ + // Make a toroidal face by a series of shape revolves. + // Make a starting vertex at [-1.0, 0, 0]. + TopoDS_Shape aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(-1.0, 0.0, 0.0)); + + // Make a circular edge by revolting aVertex around + // an axis Y positioned at [-1.5, 0.0, 0.0] on 2*Pi angle + gp_Ax1 anAxis1(gp_Pnt(-1.5, 0.0, 0.0), gp::DY()); + TopoDS_Shape anEdge = BRepPrimAPI_MakeRevol(aVertex, anAxis1); + myResult << "Circular edge was created in yellow" << std::endl; + + // Make a toroidal face by revolting anEdge around + // Z axis on 2*Pi angle. + TopoDS_Shape aFace = BRepPrimAPI_MakeRevol(anEdge, gp::OZ()); + myResult << "Toroidal face was created in red" << std::endl; + + Handle(AIS_Axis) anAisAxis1 = new AIS_Axis(new Geom_Axis1Placement(anAxis1)); + Handle(AIS_Axis) anAisAxis2 = new AIS_Axis(new Geom_Axis1Placement(gp::OZ())); + Handle(AIS_Shape) anAisVertex = new AIS_Shape(aVertex); + Handle(AIS_ColoredShape) anAisEdge = new AIS_ColoredShape(anEdge); + Handle(AIS_ColoredShape) anAisFace = new AIS_ColoredShape(aFace); + anAisEdge->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + anAisEdge->SetWidth(1.5); + anAisAxis1->SetColor(Quantity_NOC_GREEN); + anAisFace->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisAxis2->SetColor(Quantity_NOC_RED); + myObject3d.Append(anAisVertex); + myObject3d.Append(anAisEdge); + myObject3d.Append(anAisFace); +} + +void TopologySamples::TopologyIterator3dSample() +{ + // Make a compound shape. + TopoDS_Compound aComp; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aComp); + // Add shapes to the compound. + aBuilder.Add(aComp, BRepBuilderAPI_MakeVertex(gp::Origin())); + aBuilder.Add(aComp, BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 0.0, 0.0), gp_Pnt(10.0, 0.0, 0.0))); + aBuilder.Add(aComp, BRepBuilderAPI_MakeFace(gp_Sphere(gp::XOY(), 10.0))); + aBuilder.Add(aComp, BRepBuilderAPI_MakeWire( + BRepBuilderAPI_MakeEdge(gp_Pnt(15.0, 0.0, 0.0), gp_Pnt(20.0, 0.0, 0.0)), + BRepBuilderAPI_MakeEdge(gp_Pnt(20.0, 0.0, 0.0), gp_Pnt(25.0, 10.0, 5.0)) + )); + aBuilder.Add(aComp, BRepPrimAPI_MakeBox(5.0, 6.0, 7.0).Shell()); + aBuilder.Add(aComp, BRepPrimAPI_MakeBox(5.0, 6.0, 7.0).Solid()); + TopoDS_Compound aComp1; + aBuilder.MakeCompound(aComp1); + aBuilder.Add(aComp, aComp1); + + // Iterate over compound components. + myResult << "Compound components:" << std::endl; + Standard_Integer anI = 1; + for (TopoDS_Iterator anIt(aComp); anIt.More(); anIt.Next(), ++anI) + { + const TopoDS_Shape& aShape = anIt.Value(); + myResult << "#" << anI << " : "; + Handle(AIS_ColoredShape) anAisShape; + switch (aShape.ShapeType()) + { + case TopAbs_VERTEX: + myResult << "TopAbs_VERTEX"; + anAisShape = new AIS_ColoredShape(aShape); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + break; + case TopAbs_EDGE: + anAisShape = new AIS_ColoredShape(aShape); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myResult << "TopAbs_EDGE"; + break; + case TopAbs_WIRE: + myResult << "TopAbs_WIRE"; + break; + case TopAbs_FACE: + anAisShape = new AIS_ColoredShape(aShape); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); + myResult << "TopAbs_FACE"; + break; + case TopAbs_SHELL: + myResult << "TopAbs_SHELL"; + break; + case TopAbs_SOLID: + myResult << "TopAbs_SOLID"; + break; + case TopAbs_COMPOUND: + myResult << "TopAbs_COMPOUND"; + break; + case TopAbs_COMPSOLID: + myResult << "TopAbs_COMPSOLID"; + break; + case TopAbs_SHAPE: + myResult << "TopAbs_SHAPE"; + break; + } + myResult << std::endl; + if (anAisShape) + { + myObject3d.Append(anAisShape); + } + } +} + +void TopologySamples::TopologyExplorer3dSample() +{ + // Make a box with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 5.0; + Standard_Real aSizeY = 10.0; + Standard_Real aSizeZ = 15.0; + TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); + + // Explore vertex references. + myResult << "Vertex refs. : "; + Standard_Integer nbVertices = 0; + for (TopExp_Explorer anExp(aBox, TopAbs_VERTEX); anExp.More(); anExp.Next(), ++nbVertices) + { + const TopoDS_Shape& aShape = anExp.Current(); + Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + myObject3d.Append(anAisShape); + } + myResult << nbVertices << std::endl; + + // Explore edge references. + myResult << "Edge refs. : "; + Standard_Integer nbEdges = 0; + for (TopExp_Explorer anExp(aBox, TopAbs_EDGE); anExp.More(); anExp.Next(), ++nbEdges) + { + const TopoDS_Shape& aShape = anExp.Current(); + Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + anAisShape->SetWidth(2.5); + myObject3d.Append(anAisShape); + } + myResult << nbEdges << std::endl; + + // Explore face references. + myResult << "Face refs. : "; + Standard_Integer nbFaces = 0; + for (TopExp_Explorer anExp(aBox, TopAbs_FACE); anExp.More(); anExp.Next(), ++nbFaces) + { + const TopoDS_Shape& aShape = anExp.Current(); + Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + anAisShape->SetWidth(2.5); + myObject3d.Append(anAisShape); + } + myResult << nbFaces << std::endl; + + // Explore shell references. + myResult << "Wire refs. : "; + Standard_Integer nbWires = 0; + for (TopExp_Explorer anExp(aBox, TopAbs_WIRE); anExp.More(); anExp.Next(), ++nbWires) + { + } + myResult << nbWires << std::endl; + + // Explore shell references. + myResult << "Shell refs. : "; + Standard_Integer nbShells = 0; + for (TopExp_Explorer anExp(aBox, TopAbs_SHELL); anExp.More(); anExp.Next(), ++nbShells) + { + } + myResult << nbShells << std::endl; + + // Explore solid references. + myResult << "Solid refs. : "; + Standard_Integer nbSolids = 0; + for (TopExp_Explorer anExp(aBox, TopAbs_SOLID); anExp.More(); anExp.Next(), ++nbSolids) + { + } + myResult << nbSolids << std::endl; +} + +void TopologySamples::AssessToCurve3dSample() +{ + // Make a face from a sphere. + gp_Sphere aSphere(gp::XOY(), 1.0); + TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aSphere); + myResult << "TopoDS_Face on the sphere with" << std::endl + << "the center at [ " + << aSphere.Location().X() << ", " << aSphere.Location().Y() << ", " << aSphere.Location().Z() + << " ] and R = " << aSphere.Radius() << " was created in yellow" << std::endl + << std::endl; + + Handle(AIS_ColoredShape) anAisFace = new AIS_ColoredShape(aFace); + anAisFace->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + myObject3d.Append(anAisFace); + + // Retrieve the first not degenerated edge. + TopoDS_Edge aCurveEdge; + for (TopExp_Explorer anExp(aFace, TopAbs_EDGE); anExp.More(); anExp.Next()) + { + TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current()); + if (!BRep_Tool::Degenerated(anEdge)) + { + aCurveEdge = anEdge; + break; + } + } + if (!aCurveEdge.IsNull()) + { + // Make a curve on edge adaptor. + BRepAdaptor_Curve aCurveAdaptor(aCurveEdge); + myResult << "Curve adaptor for edge was built in red" << std::endl; + + Handle(AIS_ColoredShape) anAisCurveEdge = new AIS_ColoredShape(aCurveEdge); + anAisCurveEdge->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisCurveEdge->SetWidth(1.5); + myObject3d.Append(anAisCurveEdge); + + // Use the curve adaptor for some calculations, e.g. compute + // a set of points using GCPnts_QuasiUniformDeflection algo. + Standard_Real aDeflection = 0.1; + GCPnts_QuasiUniformDeflection anAlgo(aCurveAdaptor, aDeflection); + Standard_ASSERT_VOID(anAlgo.IsDone(), "Success is expected!"); + myResult << "Distribution of point on the curve with " << aDeflection + << " deflection was performed:" << std::endl; + for (Standard_Integer i = 1; i <= anAlgo.NbPoints(); ++i) + { + gp_Pnt aPnt = anAlgo.Value(i); + myResult << "Point #" << i << " : [ " + << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl; + Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt)); + myObject3d.Append(anAisPnt); + } + } +} + +void TopologySamples::AssessToCompositeCurve3dSample() +{ + // Make a wire containing two BSpline curves. + // Define points. + gp_Pnt aPole1(0.0, 0.0, 10.0); + gp_Pnt aPole2(5.0, 5.0, 5.0); + gp_Pnt aPole3(10.0, 10.0, 15.0); + gp_Pnt aPole4(15.0, 5.0, 20.0); + gp_Pnt aPole5(25.0, 15.0, 20.0); + gp_Pnt aPole6(35.0, 15.0, 15.0); + gp_Pnt aPole7(45.0, 25.0, 10.0); + // Add points to the curve poles array. + TColgp_Array1OfPnt aPoles1(1, 4), aPoles2(1, 4); + aPoles1.SetValue(1, aPole1); + aPoles1.SetValue(2, aPole2); + aPoles1.SetValue(3, aPole3); + aPoles1.SetValue(4, aPole4); + aPoles2.SetValue(1, aPole4); + aPoles2.SetValue(2, aPole5); + aPoles2.SetValue(3, aPole6); + aPoles2.SetValue(4, aPole7); + // Make a BSpline curves from the point arrays + Handle(Geom_BSplineCurve) aBSplineCurve1 = GeomAPI_PointsToBSpline(aPoles1).Curve(); + Handle(Geom_BSplineCurve) aBSplineCurve2 = GeomAPI_PointsToBSpline(aPoles2).Curve(); + // Make edges + TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aBSplineCurve1); + TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(aBSplineCurve2); + // Make a wire + BRepBuilderAPI_MakeWire aMakeWire; + aMakeWire.Add(anEdge1); + aMakeWire.Add(anEdge2); + Standard_ASSERT_VOID(aMakeWire.IsDone(), "Added edge isn't connectible!"); + TopoDS_Wire aWire = aMakeWire.Wire(); + myResult << "Wire of two BSpline curves was created" << std::endl; + + Handle(AIS_ColoredShape) anAisWire = new AIS_ColoredShape(aWire); + myObject3d.Append(anAisWire); + + // Make an adaptor. + BRepAdaptor_CompCurve aCurveAdaptor(aWire); + + // Use the curve adaptor for some calculations, e.g. compute + // a set of points using GCPnts_QuasiUniformDeflection algo. + Standard_Real aDeflection = 0.5; + GCPnts_QuasiUniformDeflection anAlgo(aCurveAdaptor, aDeflection); + Standard_ASSERT_VOID(anAlgo.IsDone(), "Success is expected!"); + myResult << "Distribution of point on the curve with " << aDeflection + << " deflection was performed:" << std::endl; + for (Standard_Integer i = 1; i <= anAlgo.NbPoints(); ++i) + { + gp_Pnt aPnt = anAlgo.Value(i); + myResult << "Point #" << i << " : [ " + << aPnt.X() << ", " << aPnt.Y() << ", " << aPnt.Z() << " ]" << std::endl; + Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt)); + myObject3d.Append(anAisPnt); + } +} + +void TopologySamples::AssessToSurface3dSample() +{ + // Make a face from a sphere. + gp_Sphere aSphere(gp::XOY(), 4.0); + TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aSphere); + myResult << "TopoDS_Face on the sphere with" << std::endl + << "the center at [ " + << aSphere.Location().X() << ", " << aSphere.Location().Y() << ", " << aSphere.Location().Z() + << " ] and R = " << aSphere.Radius() << " was created in yellow" << std::endl + << std::endl; + + // Make a surface adaptor. + BRepAdaptor_Surface aSurfAdaptor(aFace); + + // Use the surface adaptor for some calculations, e.g. compute + // a normal vector at a surface point. + Standard_Real anU = 0.0, aV = 0.0; + gp_Pnt aPnt; + gp_Vec aDU, aDV; + aSurfAdaptor.D1(anU, aV, aPnt, aDU, aDV); + gp_Vec aNorm = aDU.Crossed(aDV); + Standard_ASSERT_VOID(aNorm.Magnitude() > Precision::Confusion(), "Non zero vector is expected!"); + aNorm.Normalize(); + myResult << "Normal vector at ( " << anU << ", " << aV << " )" << std::endl + << " = " << aNorm.X() << ", " << aNorm.Y() << ", " << aNorm.Z() << " ] is in red" << std::endl; + + Handle(AIS_ColoredShape) anAisFace = new AIS_ColoredShape(aFace); + anAisFace->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + Handle(AIS_Point) anAisPnt = new AIS_Point(new Geom_CartesianPoint(aPnt)); + Handle(AIS_ColoredShape) anAisNorm = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aPnt, aPnt.XYZ() + aNorm.XYZ())); + myObject3d.Append(anAisFace); + myObject3d.Append(anAisNorm); + myObject3d.Append(anAisPnt); +} + +void TopologySamples::Common3dSample() +{ + // Make a box #1 with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 10.0; + Standard_Real aSizeY = 15.0; + Standard_Real aSizeZ = 20.0; + TopoDS_Shape aShape1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow wireframe" << std::endl; + + // Make a box #2 by two points. + gp_Pnt aPnt1(5.0, 7.5, 10.0); + gp_Pnt aPnt2(20.0, 25.0, 30.0); + TopoDS_Shape aShape2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2); + myResult << "Box with corners [" + << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() + << "] and [" + << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() + << "] was created in green wirefreme" << std::endl; + + // Create a boolean algo. + BRepAlgoAPI_Common anAlgo(aShape1, aShape2); + + // Make operation. + anAlgo.Build(); + + if (!anAlgo.IsDone()) // Process errors + { + myResult << "Errors : " << std::endl; + anAlgo.DumpErrors(myResult); + } + if (anAlgo.HasWarnings()) // Process warnings + { + myResult << "Warnings : " << std::endl; + anAlgo.DumpErrors(myResult); + } + + if (anAlgo.IsDone()) + { + // Get result. + TopoDS_Shape aResultShape = anAlgo.Shape(); + myResult << "Result shape was created in red shading" << std::endl; + + Handle(AIS_ColoredShape) anAisShape1 = new AIS_ColoredShape(aShape1); + Handle(AIS_ColoredShape) anAisShape2 = new AIS_ColoredShape(aShape2); + anAisShape1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisShape2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape); + anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisShape1); + myObject3d.Append(anAisShape2); + myObject3d.Append(anAisResult); + myContext->SetDisplayMode(anAisShape1, 0, Standard_True); + myContext->SetDisplayMode(anAisShape2, 0, Standard_True); + myContext->SetDisplayMode(anAisResult, 1, Standard_True); + } +} + +void TopologySamples::Cut3dSample() +{ + // Make a box #1 with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 10.0; + Standard_Real aSizeY = 15.0; + Standard_Real aSizeZ = 20.0; + TopoDS_Shape aShape1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow wireframe" << std::endl; + + // Make a box #2 by two points as a cutting tool. + gp_Pnt aPnt1(5.0, 7.5, 10.0); + gp_Pnt aPnt2(20.0, 25.0, 30.0); + TopoDS_Shape aShape2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2); + myResult << "Box with corners [" + << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() + << "] and [" + << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() + << "] was created in green wireframe" << std::endl; + + // Create a boolean algo. + BRepAlgoAPI_Cut anAlgo(aShape1, aShape2); + + // Make operation. + anAlgo.Build(); + + if (!anAlgo.IsDone()) // Process errors + { + myResult << "Errors : " << std::endl; + anAlgo.DumpErrors(myResult); + } + if (anAlgo.HasWarnings()) // Process warnings + { + myResult << "Warnings : " << std::endl; + anAlgo.DumpErrors(myResult); + } + + if (anAlgo.IsDone()) + { + // Get result. + TopoDS_Shape aResultShape = anAlgo.Shape(); + myResult << "Result shape was created in red shading" << std::endl; + Handle(AIS_ColoredShape) anAisShape1 = new AIS_ColoredShape(aShape1); + Handle(AIS_ColoredShape) anAisShape2 = new AIS_ColoredShape(aShape2); + anAisShape1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisShape2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape); + anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisShape1); + myObject3d.Append(anAisShape2); + myObject3d.Append(anAisResult); + myContext->SetDisplayMode(anAisShape1, 0, Standard_True); + myContext->SetDisplayMode(anAisShape2, 0, Standard_True); + myContext->SetDisplayMode(anAisResult, 1, Standard_True); + } +} + +void TopologySamples::Fuse3dSample() +{ + // Make a box #1 with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 10.0; + Standard_Real aSizeY = 15.0; + Standard_Real aSizeZ = 20.0; + TopoDS_Shape aShape1 = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow wireframe" << std::endl; + + // Make a box #2 by two points. + gp_Pnt aPnt1(5.0, 7.5, 10.0); + gp_Pnt aPnt2(20.0, 25.0, 30.0); + TopoDS_Shape aShape2 = BRepPrimAPI_MakeBox(aPnt1, aPnt2); + myResult << "Box with corners [" + << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() + << "] and [" + << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() + << "] was created in green wireframe" << std::endl; + + // Create a boolean algo. + BRepAlgoAPI_Fuse anAlgo(aShape1, aShape2); + + // Make operation. + anAlgo.Build(); + + if (!anAlgo.IsDone()) // Process errors + { + myResult << "Errors : " << std::endl; + anAlgo.DumpErrors(myResult); + } + if (anAlgo.HasWarnings()) // Process warnings + { + myResult << "Warnings : " << std::endl; + anAlgo.DumpErrors(myResult); + } + + if (anAlgo.IsDone()) + { + // Get result. + TopoDS_Shape aResultShape = anAlgo.Shape(); + myResult << "Result shape was created in red shading" << std::endl; + Handle(AIS_ColoredShape) anAisShape1 = new AIS_ColoredShape(aShape1); + Handle(AIS_ColoredShape) anAisShape2 = new AIS_ColoredShape(aShape2); + anAisShape1->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisShape2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape); + anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisShape1); + myObject3d.Append(anAisShape2); + myObject3d.Append(anAisResult); + myContext->SetDisplayMode(anAisShape1, 0, Standard_True); + myContext->SetDisplayMode(anAisShape2, 0, Standard_True); + myContext->SetDisplayMode(anAisResult, 1, Standard_True); + } +} + +void TopologySamples::Section3dSample() +{ + // Make a box #1 with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 10.0; + Standard_Real aSizeY = 15.0; + Standard_Real aSizeZ = 20.0; + TopoDS_Shape aShape = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow wireframe" << std::endl; + + // Create a boolean algo. + // Make a section by a plane. + gp_Pln aPln(gp_Pnt(aSizeX / 2.0, aSizeY / 2.0, aSizeZ / 2.0), gp::DZ()); + BRepAlgoAPI_Section anAlgo(aShape, aPln, Standard_False); + + // Make operation. + anAlgo.Build(); + + if (!anAlgo.IsDone()) // Process errors + { + myResult << "Errors : " << std::endl; + anAlgo.DumpErrors(myResult); + } + if (anAlgo.HasWarnings()) // Process warnings + { + myResult << "Warnings : " << std::endl; + anAlgo.DumpErrors(myResult); + } + + if (anAlgo.IsDone()) + { + // Get result. + TopoDS_Shape aResultShape = anAlgo.Shape(); + myResult << "Result shape was created in red" << std::endl; + Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); + Handle(AIS_Plane) anAisPlane = new AIS_Plane(new Geom_Plane(aPln)); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResultShape); + anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisShape); + myObject3d.Append(anAisPlane); + myObject3d.Append(anAisResult); + myContext->SetDisplayMode(anAisShape, 0, Standard_True); + } +} + +void TopologySamples::Splitter3dSample() +{ + // Make a box by two points. + gp_Pnt aPnt1(-5.0, -7.5, -10.0); + gp_Pnt aPnt2(10.0, 15.0, 10.0); + TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aPnt1, aPnt2); + myResult << "Box with corners [" + << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() + << "] and [" + << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() + << "] was created in yellow" << std::endl; + + // Make a splitting tool as XY plane. + TopoDS_Shape aTool = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY())); + + // Create a splitter algo. + BRepAlgoAPI_Splitter aSplitter; + + // Add shapes to be split. + TopTools_ListOfShape anArguments; + anArguments.Append(aBox); + aSplitter.SetArguments(anArguments); + + // Add tool shapes. + TopTools_ListOfShape aTools; + aTools.Append(aTool); + aSplitter.SetTools(aTools); + + // Perform splitting. + aSplitter.Build(); + + if (!aSplitter.IsDone()) // Process errors + { + myResult << "Errors : " << std::endl; + aSplitter.DumpErrors(myResult); + } + if (aSplitter.HasWarnings()) // Process warnings + { + myResult << "Warnings : " << std::endl; + aSplitter.DumpErrors(myResult); + } + + Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); + anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + myObject3d.Append(anAisBox); + + if (aSplitter.IsDone()) // Process results + { + // Simplification of the result shape is performed by the means of + // ShapeUpgrade_UnifySameDomain algorithm. The result of the operation will + // be overwritten with the simplified result. + // The simplification is performed without creation of the Internal shapes, + // i.e. shapes connections will never be broken. + // Simplification is performed on the whole result shape. Thus, if the input + // shapes contained connected tangent edges or faces unmodified during the operation + // they will also be unified. + aSplitter.SimplifyResult(); + + // Get result of splitting. + TopoDS_Shape aResult = aSplitter.Shape(); + myResult << "Splitting result (shapes are moved apart for illustativeness) is in red" << std::endl; + + // In this particular sample two shapes in the result are expected. + // Lets move apart them for illustrative purposes. + TopoDS_Iterator anIt(aResult); + Standard_ASSERT_VOID(anIt.More(), "Not empty result is expected!"); + TopoDS_Shape aBox1 = anIt.Value(); anIt.Next(); + Standard_ASSERT_VOID(anIt.More(), "Two shapes in the result are expected!"); + TopoDS_Shape aBox2 = anIt.Value(); + gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(0.0, 0.0, -15.0)); + aBox1.Move(aTrsf1); + gp_Trsf aTrsf2; aTrsf2.SetTranslation(gp_Vec(0.0, 0.0, +15.0)); + aBox2.Move(aTrsf2); + + Handle(AIS_ColoredShape) anAisBox1 = new AIS_ColoredShape(aBox1); + Handle(AIS_ColoredShape) anAisBox2 = new AIS_ColoredShape(aBox2); + anAisBox1->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisBox2->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisBox1); + myObject3d.Append(anAisBox2); + } +} + +void TopologySamples::Defeaturing3dSample() +{ + // Prepare a box with a chamfer. + // Make a box with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 8.0; + Standard_Real aSizeY = 10.0; + Standard_Real aSizeZ = 15.0; + TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); + // Initialize chamfer algo. + BRepFilletAPI_MakeChamfer anAlgo(aBox); + // Set edge to apply a chamfer with specified distance from it. + // Select the 5th edge in the map returned by TopExp::MapShapes method. + TopTools_IndexedMapOfShape anEdges; + TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges); + TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(5)); + Standard_Real aDist = 4.0; + anAlgo.Add(aDist, anEdge); + // Make a chamfer. + anAlgo.Build(); + Standard_ASSERT_VOID(anAlgo.IsDone(), "Couldn't prepare a box with a chamfer!"); + // Get a box with a chamfer. + TopoDS_Shape aBoxWithChamfer = anAlgo.Shape(); + myResult << "Box with a chamfer is in yellow shading" << std::endl; + + Handle(AIS_ColoredShape) anAisBoxWithChamfer = new AIS_ColoredShape(aBoxWithChamfer); + anAisBoxWithChamfer->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + myObject3d.Append(anAisBoxWithChamfer); + myContext->SetDisplayMode(anAisBoxWithChamfer, 1, Standard_True); + + // Retrieve chamfer faces generated from the edge + const TopTools_ListOfShape& aGenShapes = anAlgo.Generated(anEdge); + Standard_ASSERT_VOID(!aGenShapes.IsEmpty(), "Chamfer face is expected!"); + for (TopTools_ListOfShape::Iterator anIt(aGenShapes); anIt.More(); anIt.Next()) + { + Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(anIt.Value()); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + anAisShape->SetWidth(2.5); + myObject3d.Append(anAisShape); + myContext->SetDisplayMode(anAisBoxWithChamfer, 1, Standard_True); + } + myResult << "Chamfer faces : " << aGenShapes.Size() << std::endl; + myResult << "The first one is using to remove" << std::endl; + myResult << "The removed face is in green" << std::endl; + + // Initialize defeaturing algo. + BRepAlgoAPI_Defeaturing aDefeatAlgo; + aDefeatAlgo.SetShape(aBoxWithChamfer); + aDefeatAlgo.AddFaceToRemove(aGenShapes.First()); + + // Remove the chamfer. + aDefeatAlgo.Build(); + + if (aDefeatAlgo.IsDone()) + { + // Get result. + TopoDS_Shape aResult = aDefeatAlgo.Shape(); + myResult << "Defeatured box is in red wireframe" << std::endl; + + Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); + anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisResult); + myContext->SetDisplayMode(anAisResult, 0, Standard_True); + } +} + +void TopologySamples::Fillet3dSample() +{ + // Make a box with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 8.0; + Standard_Real aSizeY = 10.0; + Standard_Real aSizeZ = 15.0; + TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow wireframe" << std::endl; + + // Initialize fillet algo. + BRepFilletAPI_MakeFillet anAlgo(aBox); + + // Set edge to apply a fillet with specified radius. + // Select the first edge in the map returned by TopExp::MapShapes method. + TopTools_IndexedMapOfShape anEdges; + TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges); + TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(1)); + Standard_Real aRadius = 3.0; + anAlgo.Add(aRadius, anEdge); + myResult << "Make a fillet of " << aRadius << " radius on an edge in green" << std::endl; + + Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); + Handle(AIS_ColoredShape) anAisEdge = new AIS_ColoredShape(anEdge); + anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisEdge->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + anAisEdge->SetWidth(2.5); + myObject3d.Append(anAisBox); + myObject3d.Append(anAisEdge); + myContext->SetDisplayMode(anAisBox, 0, Standard_True); + + // Make a fillet. + anAlgo.Build(); + + if (anAlgo.IsDone()) + { + // Get result. + TopoDS_Shape aResult = anAlgo.Shape(); + myResult << "Fillet was built. Result shape is in red shading" << std::endl; + + Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); + anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisResult); + myContext->SetDisplayMode(anAisResult, 1, Standard_True); + } +} + +void TopologySamples::Chamfer3dSample() +{ + // Make a box with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 8.0; + Standard_Real aSizeY = 10.0; + Standard_Real aSizeZ = 15.0; + TopoDS_Shape aBox = BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow wirewrame" << std::endl; + + // Initialize chamfer algo. + BRepFilletAPI_MakeChamfer anAlgo(aBox); + + // Set edge to apply a chamfer with specified distance from it. + // Select the 5th edge in the map returned by TopExp::MapShapes method. + TopTools_IndexedMapOfShape anEdges; + TopExp::MapShapes(aBox, TopAbs_EDGE, anEdges); + TopoDS_Edge anEdge = TopoDS::Edge(anEdges.FindKey(5)); + Standard_Real aDist = 4.0; + anAlgo.Add(aDist, anEdge); + myResult << "Make a chamfer of " << aDist << " size on an edge in green" << std::endl; + + Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); + Handle(AIS_ColoredShape) anAisEdge = new AIS_ColoredShape(anEdge); + anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisEdge->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + anAisEdge->SetWidth(2.5); + myObject3d.Append(anAisBox); + myObject3d.Append(anAisEdge); + myContext->SetDisplayMode(anAisBox, 0, Standard_True); + + // Make a chamfer. + anAlgo.Build(); + if (anAlgo.IsDone()) + { + // Get result. + TopoDS_Shape aResult = anAlgo.Shape(); + myResult << "Fillet was built. Result shape is in red shading" << std::endl; + + Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); + anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisResult); + myContext->SetDisplayMode(anAisResult, 1, Standard_True); + + const TopTools_ListOfShape& aGenShapes = anAlgo.Generated(anEdge); + for (TopTools_ListOfShape::Iterator anIt(aGenShapes); anIt.More(); anIt.Next()) + { + Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(anIt.Value()); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); + anAisShape->SetWidth(2.5); + myObject3d.Append(anAisShape); + } + } +} + +void TopologySamples::Offset3dSample() +{ + // Make a triangle wire. + BRepBuilderAPI_MakePolygon aTria; + TopoDS_Vertex aVertA = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0)); + TopoDS_Vertex aVertB = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 0.0, +1.0)); + TopoDS_Vertex aVertC = BRepBuilderAPI_MakeVertex(gp_Pnt(+0.5, 0.0, 0.0)); + aTria.Add(aVertA); + aTria.Add(aVertB); + aTria.Add(aVertC); + aTria.Close(); + TopoDS_Wire aWire = aTria.Wire(); + myResult << "Triangular wire was created in yellow" << std::endl; + + Handle(AIS_ColoredShape) anAisWire = new AIS_ColoredShape(aWire); + anAisWire->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + myObject3d.Append(anAisWire); + + // Initialize offset algo. + BRepOffsetAPI_MakeOffset anAlgo(aWire); + + // Perform a series of offsets with linearly increasing value and altitude. + Standard_Real anOffsetStep = 0.2; + Standard_Real anAltitudeStep = 0.1; + for (Standard_Integer i = 1; i <= 4; ++i) + { + Standard_Real anOffset = anOffsetStep * i; + Standard_Real anAltitude = anAltitudeStep * i; + anAlgo.Perform(anOffset, anAltitude); + if (anAlgo.IsDone()) + { + // Get result. + TopoDS_Shape aResult = anAlgo.Shape(); + myResult << "#" << i << " : Offset = " << anOffset << " Altitude = " << anAltitude + << ". Result is in red." << std::endl; + + Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); + anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisResult); + } + } +} + +void TopologySamples::Evolved3dSample() +{ + // Make a triangle wire as a spine. + BRepBuilderAPI_MakePolygon aTria; + TopoDS_Vertex aVertA = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0)); + TopoDS_Vertex aVertB = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, +1.0, 0.0)); + TopoDS_Vertex aVertC = BRepBuilderAPI_MakeVertex(gp_Pnt(+0.5, 0.0, 0.0)); + aTria.Add(aVertA); + aTria.Add(aVertB); + aTria.Add(aVertC); + aTria.Close(); + TopoDS_Wire aSpine = aTria.Wire(); + myResult << "Profile wire was created in yellow" << std::endl; + + // Make a wire as a profile. + BRepBuilderAPI_MakePolygon aPoly; + TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, 0.0, 0.0)); + TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, -0.1, 0.5)); + TopoDS_Vertex aVert3 = BRepBuilderAPI_MakeVertex(gp_Pnt(-0.5, -0.2, 1.0)); + aPoly.Add(aVert1); + aPoly.Add(aVert2); + aPoly.Add(aVert3); + TopoDS_Wire aProfile = aPoly.Wire(); + myResult << "Spine wire was created in greed" << std::endl; + + Handle(AIS_ColoredShape) anAisSpine = new AIS_ColoredShape(aSpine); + Handle(AIS_ColoredShape) anAisProfile = new AIS_ColoredShape(aProfile); + anAisSpine->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisSpine->SetWidth(2.5); + anAisProfile->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + anAisProfile->SetWidth(2.5); + myObject3d.Append(anAisSpine); + myObject3d.Append(anAisProfile); + + // Initialize evolving algo. + GeomAbs_JoinType aJoinType = GeomAbs_Arc; + Standard_Boolean aIsGlobalCS = Standard_False; + Standard_Boolean aIsSolid = Standard_True; + BRepOffsetAPI_MakeEvolved anAlgo(aSpine, aProfile, aJoinType, aIsGlobalCS, aIsSolid); + + // Perform evolving. + anAlgo.Build(); + + if (anAlgo.IsDone()) + { + // Get result. + TopoDS_Shape aResult = anAlgo.Shape(); + myResult << "Evolving result is in red" << std::endl; + + Handle(AIS_ColoredShape) anAisResult = new AIS_ColoredShape(aResult); + anAisResult->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisResult); + } +} + +void TopologySamples::Copy3dSample() +{ + // Make a box with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 10.0; + Standard_Real aSizeY = 15.0; + Standard_Real aSizeZ = 20.0; + BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ); + TopoDS_Shape aBox = aBoxMake.Shape(); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow" << std::endl; + + // Make a box copy. + TopoDS_Shape aBoxCopy = BRepBuilderAPI_Copy(aBox); + myResult << "Box copy was created in red" << std::endl; + + gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(15.0, 0.0, 0.0)); + aBoxCopy.Move(aTrsf1); + myResult << "Box copy shape is moved apart for illustativeness" << std::endl; + + Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); + anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisBox->SetWidth(2.5); + Handle(AIS_ColoredShape) anAisBoxCopy = new AIS_ColoredShape(aBoxCopy); + anAisBoxCopy->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisBox); + myObject3d.Append(anAisBoxCopy); +} + +void TopologySamples::Transform3dSample() +{ + // Make a box with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 10.0; + Standard_Real aSizeY = 15.0; + Standard_Real aSizeZ = 20.0; + BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ); + TopoDS_Shape aBox = aBoxMake.Shape(); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow" << std::endl; + + // Move the box. + gp_Trsf aTrMove; aTrMove.SetTranslation(gp_Vec(15.0, 20.0, 25.0)); + TopoDS_Shape aMovedBox = BRepBuilderAPI_Transform(aBox, aTrMove, Standard_True); + myResult << "Moved box in green" << std::endl; + + // Rotate the moved box + gp_Trsf aTrRot; aTrRot.SetRotation(gp_Ax1(gp_Pnt(15.0, 20.0, 25.0), gp::DZ()), 3.0*M_PI_4); + TopoDS_Shape aRotatedBox = BRepBuilderAPI_Transform(aBox, aTrRot, Standard_True); + myResult << "Rotated box in red" << std::endl; + + Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); + Handle(AIS_ColoredShape) anAisMovedBox = new AIS_ColoredShape(aMovedBox); + Handle(AIS_ColoredShape) anAisRotatedBox = new AIS_ColoredShape(aRotatedBox); + anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisMovedBox->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + anAisRotatedBox->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisBox); + myObject3d.Append(anAisMovedBox); + myObject3d.Append(anAisRotatedBox); +} + +void TopologySamples::ConvertToNurbs3dSample() +{ + // Make a torus face. + gp_Torus aTorus(gp::XOY(), 20.0, 7.5); + TopoDS_Shape aTorusFace = BRepBuilderAPI_MakeFace(aTorus); + myResult << "TopoDS_Solid on the torus with" << std::endl + << "R major = " << aTorus.MajorRadius() << std::endl + << "R minor = " << aTorus.MinorRadius() << std::endl + << "was created in yellow" << std::endl; + + // Convert faces/edges from analytic to NURBS geometry. + TopoDS_Shape aNurbsFace = BRepBuilderAPI_NurbsConvert(aTorusFace); + myResult << "Converted torus in red" << std::endl; + gp_Trsf aTrsf1; aTrsf1.SetTranslation(gp_Vec(60.0, 0.0, 0.0)); + aNurbsFace.Move(aTrsf1); + myResult << "Converted torus is moved apart for illustativeness" << std::endl; + + Handle(AIS_ColoredShape) anAisTorus = new AIS_ColoredShape(aTorusFace); + Handle(AIS_ColoredShape) anAisNurbs = new AIS_ColoredShape(aNurbsFace); + anAisTorus->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisTorus->SetWidth(2.5); + anAisNurbs->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisTorus); + myObject3d.Append(anAisNurbs); +} + +void TopologySamples::SewContiguousFaces3dSample() +{ + // Make a sphere. + gp_Sphere aSphere(gp::XOY(), 1.0); + // South hemisphere. + TopoDS_Face aFace1 = BRepBuilderAPI_MakeFace(aSphere, 0.0, 2.0 * M_PI, -M_PI_2, 0.0); + // North hemisphere. + TopoDS_Face aFace2 = BRepBuilderAPI_MakeFace(aSphere, 0.0, 2.0 * M_PI, 0.0, +M_PI_2); + + // Make a default tailor. + BRepBuilderAPI_Sewing aTailor; + + // Add hemisphere faces. + aTailor.Add(aFace1); + aTailor.Add(aFace2); + + // Perform sewing. + aTailor.Perform(); + + // Get result. + const TopoDS_Shape& aSewedSphere = aTailor.SewedShape(); + myResult << "Two hemispheres were sewed : " << aTailor.NbFreeEdges() << " free edges" << std::endl; + + Handle(AIS_ColoredShape) anAisSewedSphere = new AIS_ColoredShape(aSewedSphere); + anAisSewedSphere->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisSewedSphere); +} + +void TopologySamples::CheckValidity3dSample() +{ + // Make a box with a corner at [0, 0, 0] and the specified sizes. + Standard_Real aSizeX = 10.0; + Standard_Real aSizeY = 15.0; + Standard_Real aSizeZ = 20.0; + BRepPrimAPI_MakeBox aBoxMake(aSizeX, aSizeY, aSizeZ); + TopoDS_Shape aBox = aBoxMake.Shape(); + myResult << "Box at corner [0, 0, 0] and sizes [" + << aSizeX << ", " << aSizeY << ", " << aSizeZ + << "] was created in yellow" << std::endl; + + // Analyze the box. + BRepCheck_Analyzer anAnalyzer(aBox); + myResult << "Box is " << (anAnalyzer.IsValid() ? "valid" : "invalid") << std::endl; + + // Make the box invalid manually. + Handle(BRepTools_ReShape) aReShape = new BRepTools_ReShape(); + myResult << "Remove the top face from the box (red)" << std::endl; + aReShape->Remove(aBoxMake.TopFace()); + TopoDS_Shape aBox1 = aReShape->Apply(aBox); + myResult << "The top face was removed" << std::endl; + + // Analyze the modified box. + BRepCheck_Analyzer anAnalyzer1(aBox1); + myResult << "Modified box is " << (anAnalyzer1.IsValid() ? "valid" : "invalid") << std::endl; + + Handle(AIS_ColoredShape) anAisBox = new AIS_ColoredShape(aBox); + Handle(AIS_ColoredShape) anAisTopFace = new AIS_ColoredShape(aBoxMake.TopFace()); + anAisBox->SetColor(Quantity_Color(Quantity_NOC_YELLOW)); + anAisTopFace->SetColor(Quantity_Color(Quantity_NOC_RED)); + myObject3d.Append(anAisBox); + myObject3d.Append(anAisTopFace); +} + +void TopologySamples::ComputeLinearProperties3dSample() +{ + // Make an edge from a circular segment. + // Create a circle in XY plane of the radius 1.0. + gp_Circ aCirc(gp::XOY(), 1.0); + // Make a circular edge from the 1st quoter in the parametric space. + TopoDS_Edge aShape = BRepBuilderAPI_MakeEdge(aCirc, 0.0, M_PI); + myResult << "TopoDS_Edge on the circle's 1st quoter" << std::endl + << "with the center at [ " + << aCirc.Location().X() << ", " << aCirc.Location().Y() << ", " << aCirc.Location().Z() + << " ] and R = " << aCirc.Radius() << " was created in red" << std::endl + << std::endl; + + // Retrieve linear properties from the edge. + GProp_GProps aGProps; + BRepGProp::LinearProperties(aShape, aGProps); + Standard_Real aLength = aGProps.Mass(); + gp_Pnt aCOM = aGProps.CentreOfMass(); + Standard_Real anIx, anIy, anIz; + aGProps.StaticMoments(anIx, anIy, anIz); + gp_Mat aMOI = aGProps.MatrixOfInertia(); + myResult << "Linear properties:" << std::endl + << " Length = " << aLength << std::endl + << " Center of mass = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl + << " Static moments = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl + << " Matrix of inertia = [ " + << aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl + << std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl + << std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl; + GProp_PrincipalProps aPProps = aGProps.PrincipalProperties(); + Standard_Real anIxx, anIyy, anIzz; + aPProps.Moments(anIxx, anIyy, anIzz); + Standard_Real aRxx, aRyy, aRzz; + aPProps.RadiusOfGyration(aRxx, aRyy, aRzz); + myResult << "Principal properties:" << std::endl + << " Has symmetric axis : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl + << " Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl + << " Moments of inertia = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl + << " Radius of gyration = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl; + if (!aPProps.HasSymmetryPoint()) + { + const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia(); + myResult << " 1st axis of inertia = [ " << anAxis1.X() << ", " << anAxis1.Y() << ", " << anAxis1.Z() << " ]" << std::endl; + Handle(AIS_ColoredShape) anAisAxis1 = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis1.XYZ())); + anAisAxis1->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisAxis1); + if (!aPProps.HasSymmetryPoint()) + { + const gp_Vec& anAxis2 = aPProps.SecondAxisOfInertia(); + myResult << " 2nd axis of inertia = [ " << anAxis2.X() << ", " << anAxis2.Y() << ", " << anAxis2.Z() << " ]" << std::endl; + Handle(AIS_ColoredShape) anAisAxis2 = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis2.XYZ())); + anAisAxis2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisAxis2); + const gp_Vec& anAxis3 = aPProps.ThirdAxisOfInertia(); + myResult << " 3rd axis of inertia = [ " << anAxis3.X() << ", " << anAxis3.Y() << ", " << anAxis3.Z() << " ]" << std::endl; + Handle(AIS_ColoredShape) anAisAxis3 = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis3.XYZ())); + anAisAxis3->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisAxis3); + } + } + + Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); + Handle(AIS_Point) anAisCOM = new AIS_Point(new Geom_CartesianPoint(aCOM)); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); + Handle(AIS_TextLabel) aCOMLabel = new AIS_TextLabel(); + aCOMLabel->SetText("Center of mass"); + aCOMLabel->SetPosition(aCOM); + Handle(AIS_Axis) anAisAxisX = new AIS_Axis(new Geom_Axis2Placement(gp::YOZ()), AIS_TOAX_XAxis); + Handle(AIS_Axis) anAisAxisY = new AIS_Axis(new Geom_Axis2Placement(gp::ZOX()), AIS_TOAX_YAxis); + Handle(AIS_Axis) anAisAxisZ = new AIS_Axis(new Geom_Axis2Placement(gp::XOY()), AIS_TOAX_ZAxis); + myObject3d.Append(anAisAxisX); + myObject3d.Append(anAisAxisY); + myObject3d.Append(anAisAxisZ); + myObject3d.Append(anAisShape); + myObject3d.Append(anAisCOM); + myObject3d.Append(aCOMLabel); +} + +void TopologySamples::ComputeSurfaceProperties3dSample() +{ + // Make a face from a cylinder with R = 1 + // and directed along Z axis + gp_Cylinder aCyl(gp::XOY(), 1.0); + TopoDS_Face aShape = BRepBuilderAPI_MakeFace(aCyl, 0.0, M_PI, -1.0, +1.0).Face(); + myResult << "TopoDS_Face on the cylinder R = " << aCyl.Radius() << std::endl + << "with axis [ " << aCyl.Position().Direction().X() << ", " << aCyl.Position().Direction().Y() << ", " << aCyl.Position().Direction().Z() << " ]" << std::endl + << "limited in length [-1 ... +1] was created in red" << std::endl; + + // Retrieve surface properties from the face. + GProp_GProps aGProps; + BRepGProp::SurfaceProperties(aShape, aGProps); + Standard_Real aArea = aGProps.Mass(); + gp_Pnt aCOM = aGProps.CentreOfMass(); + Standard_Real anIx, anIy, anIz; + aGProps.StaticMoments(anIx, anIy, anIz); + gp_Mat aMOI = aGProps.MatrixOfInertia(); + myResult << "Linear properties:" << std::endl + << " Area = " << aArea << std::endl + << " Center of mass = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl + << " Static moments = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl + << " Matrix of inertia = [ " + << aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl + << std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl + << std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl; + GProp_PrincipalProps aPProps = aGProps.PrincipalProperties(); + Standard_Real anIxx, anIyy, anIzz; + aPProps.Moments(anIxx, anIyy, anIzz); + Standard_Real aRxx, aRyy, aRzz; + aPProps.RadiusOfGyration(aRxx, aRyy, aRzz); + myResult << "Principal properties:" << std::endl + << " Has symmetric axis : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl + << " Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl + << " Moments of inertia = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl + << " Radius of gyration = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl; + if (!aPProps.HasSymmetryPoint()) + { + const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia(); + myResult << " 1st axis of inertia = [ " << anAxis1.X() << ", " << anAxis1.Y() << ", " << anAxis1.Z() << " ]" << std::endl; + Handle(AIS_ColoredShape) anAisAxis1 = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis1.XYZ())); + anAisAxis1->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisAxis1); + if (!aPProps.HasSymmetryPoint()) + { + const gp_Vec& anAxis2 = aPProps.SecondAxisOfInertia(); + myResult << " 2nd axis of inertia = [ " << anAxis2.X() << ", " << anAxis2.Y() << ", " << anAxis2.Z() << " ]" << std::endl; + Handle(AIS_ColoredShape) anAisAxis2 = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis2.XYZ())); + anAisAxis2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisAxis2); + const gp_Vec& anAxis3 = aPProps.ThirdAxisOfInertia(); + myResult << " 3rd axis of inertia = [ " << anAxis3.X() << ", " << anAxis3.Y() << ", " << anAxis3.Z() << " ]" << std::endl; + Handle(AIS_ColoredShape) anAisAxis3 = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis3.XYZ())); + anAisAxis3->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisAxis3); + } + } + + Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); + Handle(AIS_Point) anAisCOM = new AIS_Point(new Geom_CartesianPoint(aCOM)); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); + Handle(AIS_TextLabel) aCOMLabel = new AIS_TextLabel(); + aCOMLabel->SetText("Center of mass"); + aCOMLabel->SetPosition(aCOM); + Handle(AIS_Axis) anAisAxisX = new AIS_Axis(new Geom_Axis2Placement(gp::YOZ()), AIS_TOAX_XAxis); + Handle(AIS_Axis) anAisAxisY = new AIS_Axis(new Geom_Axis2Placement(gp::ZOX()), AIS_TOAX_YAxis); + Handle(AIS_Axis) anAisAxisZ = new AIS_Axis(new Geom_Axis2Placement(gp::XOY()), AIS_TOAX_ZAxis); + myObject3d.Append(anAisAxisX); + myObject3d.Append(anAisAxisY); + myObject3d.Append(anAisAxisZ); + myObject3d.Append(anAisShape); + myObject3d.Append(anAisCOM); + myObject3d.Append(aCOMLabel); +} + +void TopologySamples::ComputeVolumeProperties3dSample() +{ + // Make a box by two points. + gp_Pnt aPnt1(-0.5, -0.6, -0.7); + gp_Pnt aPnt2(+0.8, +0.9, +1.0); + TopoDS_Shape aShape = BRepPrimAPI_MakeBox(aPnt1, aPnt2); + myResult << "Box with corners [" << aPnt1.X() << ", " << aPnt1.Y() << ", " << aPnt1.Z() + << "] and [" << aPnt2.X() << ", " << aPnt2.Y() << ", " << aPnt2.Z() + << "] was created in red" << std::endl; + + // Retrieve volume properties from the face. + GProp_GProps aGProps; + BRepGProp::VolumeProperties(aShape, aGProps); + Standard_Real aVolume = aGProps.Mass(); + gp_Pnt aCOM = aGProps.CentreOfMass(); + Standard_Real anIx, anIy, anIz; + aGProps.StaticMoments(anIx, anIy, anIz); + gp_Mat aMOI = aGProps.MatrixOfInertia(); + myResult << "Linear properties:" << std::endl + << " Volume = " << aVolume << std::endl + << " Center of mass = [ " << aCOM.X() << ", " << aCOM.Y() << ", " << aCOM.Z() << " ]" << std::endl + << " Static moments = [ " << anIx << ", " << anIy << ", " << anIz << " ]" << std::endl + << " Matrix of inertia = [ " + << aMOI(1, 1) << ", " << aMOI(1, 2) << ", " << aMOI(1, 3) << std::endl + << std::setw(33) << aMOI(2, 1) << ", " << aMOI(2, 2) << ", " << aMOI(2, 3) << std::endl + << std::setw(33) << aMOI(3, 1) << ", " << aMOI(3, 2) << ", " << aMOI(3, 3) << " ]" << std::endl; + GProp_PrincipalProps aPProps = aGProps.PrincipalProperties(); + Standard_Real anIxx, anIyy, anIzz; + aPProps.Moments(anIxx, anIyy, anIzz); + Standard_Real aRxx, aRyy, aRzz; + aPProps.RadiusOfGyration(aRxx, aRyy, aRzz); + myResult << "Principal properties:" << std::endl + << " Has symmetric axis : " << (aPProps.HasSymmetryAxis() ? "YES" : "NO") << std::endl + << " Has symmetric point : " << (aPProps.HasSymmetryPoint() ? "YES" : "NO") << std::endl + << " Moments of inertia = [ " << anIxx << ", " << anIyy << ", " << anIzz << " ]" << std::endl + << " Radius of gyration = [ " << aRxx << ", " << aRyy << ", " << aRzz << " ]" << std::endl; + if (!aPProps.HasSymmetryPoint()) + { + const gp_Vec& anAxis1 = aPProps.FirstAxisOfInertia(); + myResult << " 1st axis of inertia = [ " << anAxis1.X() << ", " << anAxis1.Y() << ", " << anAxis1.Z() << " ]" << std::endl; + Handle(AIS_ColoredShape) anAisAxis1 = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis1.XYZ())); + anAisAxis1->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisAxis1); + if (!aPProps.HasSymmetryPoint()) + { + const gp_Vec& anAxis2 = aPProps.SecondAxisOfInertia(); + myResult << " 2nd axis of inertia = [ " << anAxis2.X() << ", " << anAxis2.Y() << ", " << anAxis2.Z() << " ]" << std::endl; + Handle(AIS_ColoredShape) anAisAxis2 = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis2.XYZ())); + anAisAxis2->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisAxis2); + const gp_Vec& anAxis3 = aPProps.ThirdAxisOfInertia(); + myResult << " 3rd axis of inertia = [ " << anAxis3.X() << ", " << anAxis3.Y() << ", " << anAxis3.Z() << " ]" << std::endl; + Handle(AIS_ColoredShape) anAisAxis3 = new AIS_ColoredShape( + BRepBuilderAPI_MakeEdge(aCOM, aCOM.XYZ() + anAxis3.XYZ())); + anAisAxis3->SetColor(Quantity_Color(Quantity_NOC_GREEN)); + myObject3d.Append(anAisAxis3); + } + } + + Handle(AIS_ColoredShape) anAisShape = new AIS_ColoredShape(aShape); + Handle(AIS_Point) anAisCOM = new AIS_Point(new Geom_CartesianPoint(aCOM)); + anAisShape->SetColor(Quantity_Color(Quantity_NOC_RED)); + Handle(AIS_TextLabel) aCOMLabel = new AIS_TextLabel(); + aCOMLabel->SetText("Center of mass"); + aCOMLabel->SetPosition(aCOM); + Handle(AIS_Axis) anAisAxisX = new AIS_Axis(new Geom_Axis2Placement(gp::YOZ()), AIS_TOAX_XAxis); + Handle(AIS_Axis) anAisAxisY = new AIS_Axis(new Geom_Axis2Placement(gp::ZOX()), AIS_TOAX_YAxis); + Handle(AIS_Axis) anAisAxisZ = new AIS_Axis(new Geom_Axis2Placement(gp::XOY()), AIS_TOAX_ZAxis); + myObject3d.Append(anAisAxisX); + myObject3d.Append(anAisAxisY); + myObject3d.Append(anAisAxisZ); + myObject3d.Append(anAisShape); + myObject3d.Append(anAisCOM); + myObject3d.Append(aCOMLabel); +} diff --git a/samples/qt/OCCTOverview/code/TopologySamples.h b/samples/qt/OCCTOverview/code/TopologySamples.h new file mode 100644 index 0000000000..ecb6ca51ac --- /dev/null +++ b/samples/qt/OCCTOverview/code/TopologySamples.h @@ -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 + +//! 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 diff --git a/samples/qt/OCCTOverview/code/Triangulation.xml b/samples/qt/OCCTOverview/code/Triangulation.xml new file mode 100644 index 0000000000..04d37b3db0 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Triangulation.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/samples/qt/OCCTOverview/code/TriangulationSamples.cxx b/samples/qt/OCCTOverview/code/TriangulationSamples.cxx new file mode 100644 index 0000000000..1635ef7c7e --- /dev/null +++ b/samples/qt/OCCTOverview/code/TriangulationSamples.cxx @@ -0,0 +1,113 @@ +// 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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); + + for (Standard_Integer i = 1; i <= aTriangulation->NbTriangles(); i++) + { + const Poly_Triangle trian = aTriangulation->Triangle (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(aTriangulation->Node (M), aTriangulation->Node (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; +} diff --git a/samples/qt/OCCTOverview/code/TriangulationSamples.h b/samples/qt/OCCTOverview/code/TriangulationSamples.h new file mode 100644 index 0000000000..aaab1fc070 --- /dev/null +++ b/samples/qt/OCCTOverview/code/TriangulationSamples.h @@ -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 diff --git a/samples/qt/OCCTOverview/code/Viewer2d.xml b/samples/qt/OCCTOverview/code/Viewer2d.xml new file mode 100644 index 0000000000..3b890519ef --- /dev/null +++ b/samples/qt/OCCTOverview/code/Viewer2d.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/qt/OCCTOverview/code/Viewer2dSamples.cxx b/samples/qt/OCCTOverview/code/Viewer2dSamples.cxx new file mode 100644 index 0000000000..624881da34 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Viewer2dSamples.cxx @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +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_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); +} diff --git a/samples/qt/OCCTOverview/code/Viewer2dSamples.h b/samples/qt/OCCTOverview/code/Viewer2dSamples.h new file mode 100644 index 0000000000..66deb43b70 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Viewer2dSamples.h @@ -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 +#include + +//! 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 diff --git a/samples/qt/OCCTOverview/code/Viewer3d.xml b/samples/qt/OCCTOverview/code/Viewer3d.xml new file mode 100644 index 0000000000..2c504e5dc6 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Viewer3d.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/qt/OCCTOverview/code/Viewer3dSamples.cxx b/samples/qt/OCCTOverview/code/Viewer3dSamples.cxx new file mode 100644 index 0000000000..5cb2b76380 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Viewer3dSamples.cxx @@ -0,0 +1,342 @@ +// 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 +#include +#include +#include +#include +#include +#include + +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(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + myContext->SetDisplayMode(anAisObject, 0, false); // set wireframe + } + myContext->UpdateCurrentViewer(); +} + +void Viewer3dSamples::ShadingPresentation3dSample() +{ + AIS_ListOfInteractive anAisObjectsList; + myContext->DisplayedObjects(anAisObjectsList); + for(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + myContext->SetDisplayMode(anAisObject, 1, false); // set shading + } + myContext->UpdateCurrentViewer(); +} + +void Viewer3dSamples::RedColorPresentation3dSample() +{ + AIS_ListOfInteractive anAisObjectsList; + myContext->DisplayedObjects(anAisObjectsList); + for(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + 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(AIS_ListOfInteractive::Iterator anIter(anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + 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(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + myContext->SetMaterial(anAisObject, aMaterial, Standard_False); + } + myContext->UpdateCurrentViewer(); +} + +void Viewer3dSamples::BronzePresentation3dSample() +{ + AIS_ListOfInteractive anAisObjectsList; + myContext->DisplayedObjects(anAisObjectsList); + Graphic3d_NameOfMaterial aMaterial = Graphic3d_NOM_BRONZE; + for(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + myContext->SetMaterial(anAisObject, aMaterial, Standard_False); + } + myContext->UpdateCurrentViewer(); +} + +void Viewer3dSamples::OpaquePresentation3dSample() +{ + AIS_ListOfInteractive anAisObjectsList; + myContext->DisplayedObjects(anAisObjectsList); + for(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + myContext->SetTransparency(anAisObject, 0.0, Standard_False); + } + myContext->UpdateCurrentViewer(); +} + +void Viewer3dSamples::HalfTransparencyPresentation3dSample() +{ + AIS_ListOfInteractive anAisObjectsList; + myContext->DisplayedObjects(anAisObjectsList); + for(AIS_ListOfInteractive::Iterator anIter (anAisObjectsList); + anIter.More(); anIter.Next()) + { + const Handle(AIS_InteractiveObject)& anAisObject = anIter.Value(); + 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; + } +} diff --git a/samples/qt/OCCTOverview/code/Viewer3dSamples.h b/samples/qt/OCCTOverview/code/Viewer3dSamples.h new file mode 100644 index 0000000000..1691736b30 --- /dev/null +++ b/samples/qt/OCCTOverview/code/Viewer3dSamples.h @@ -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 +#include + +//! 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 diff --git a/samples/qt/OCCTOverview/src/ApplicationCommon.cxx b/samples/qt/OCCTOverview/src/ApplicationCommon.cxx index 49d9e894d4..5754c96e96 100644 --- a/samples/qt/OCCTOverview/src/ApplicationCommon.cxx +++ b/samples/qt/OCCTOverview/src/ApplicationCommon.cxx @@ -329,7 +329,7 @@ TCollection_AsciiString ApplicationCommonWindow::getSampleSourceDir() TCollection_AsciiString aCasRoot = OSD_Environment("CASROOT").Value(); if (!aCasRoot.IsEmpty()) { - aSampleSourceDir = aCasRoot + "/samples/OCCTOverview/code"; + aSampleSourceDir = aCasRoot + "/samples/qt/OCCTOverview/code"; } } return aSampleSourceDir; diff --git a/samples/qt/OCCTOverview/src/FILES b/samples/qt/OCCTOverview/src/FILES deleted file mode 100644 index 64a1f81afc..0000000000 --- a/samples/qt/OCCTOverview/src/FILES +++ /dev/null @@ -1,19 +0,0 @@ -ApplicationCommon.cxx -ApplicationCommon.h -CommonSample.h -DocumentCommon.cxx -DocumentCommon.h -GeomWidget.cxx -GeomWidget.h -Main.cxx -OcctHighlighter.cxx -OcctHighlighter.h -OcctWindow.cxx -OcctWindow.h -OCCTOverview.qrc -TranslateDialog.h -TranslateDialog.cxx -Transparency.cxx -Transparency.h -View.cxx -View.h diff --git a/samples/qt/Tutorial/CMakeLists.txt b/samples/qt/Tutorial/CMakeLists.txt index e9f30e2de6..e9f458b364 100644 --- a/samples/qt/Tutorial/CMakeLists.txt +++ b/samples/qt/Tutorial/CMakeLists.txt @@ -1,11 +1,18 @@ project(Tutorial) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) +# Sample configuration +set (EXECUTABLE_PROJECT ON) +set (USE_QT ON) +set (RELATIVE_DIR "samples/qt") +set (TARGET_FOLDER "Samples") + +include_directories("${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE}/${RELATIVE_DIR}") include_directories("${OCCT_ROOT_DIR}/${RELATIVE_DIR}/Interface/src") include_directories("${OCCT_ROOT_DIR}/${RELATIVE_DIR}/Common/src") + OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) -ADD_DEFINITIONS(-DNO_COMMONSAMPLE_EXPORTS -DNO_IESAMPLE_EXPORTS) +# Target-specific definitions +target_compile_definitions(Tutorial PRIVATE -DNO_COMMONSAMPLE_EXPORTS -DNO_IESAMPLE_EXPORTS) diff --git a/samples/qt/Tutorial/EXTERNLIB b/samples/qt/Tutorial/EXTERNLIB deleted file mode 100644 index ec996652e0..0000000000 --- a/samples/qt/Tutorial/EXTERNLIB +++ /dev/null @@ -1,26 +0,0 @@ -TKBRep -TKBool -TKBO -TKCDF -TKFillet -TKG2d -TKG3d -TKGeomAlgo -TKGeomBase -TKernel -TKHLR -TKDEIGES -TKMath -TKMesh -TKOffset -TKOpenGl -TKPrim -TKService -TKShHealing -TKDESTEP -TKDESTL -TKTopAlgo -TKV3d -TKDEVRML -TKXSBase - diff --git a/samples/qt/Tutorial/EXTERNLIB.cmake b/samples/qt/Tutorial/EXTERNLIB.cmake new file mode 100644 index 0000000000..0390483836 --- /dev/null +++ b/samples/qt/Tutorial/EXTERNLIB.cmake @@ -0,0 +1,28 @@ +# External dependencies for Tutorial sample +set(OCCT_Tutorial_EXTERNAL_LIBS + TKBRep + TKBool + TKBO + TKCDF + TKFillet + TKG2d + TKG3d + TKGeomAlgo + TKGeomBase + TKernel + TKHLR + TKDEIGES + TKMath + TKMesh + TKOffset + TKOpenGl + TKPrim + TKService + TKShHealing + TKDESTEP + TKDESTL + TKTopAlgo + TKV3d + TKDEVRML + TKXSBase +) \ No newline at end of file diff --git a/samples/qt/Tutorial/FILES b/samples/qt/Tutorial/FILES deleted file mode 100644 index ca4f0e567b..0000000000 --- a/samples/qt/Tutorial/FILES +++ /dev/null @@ -1,2 +0,0 @@ -EXTERNLIB -PACKAGES diff --git a/samples/qt/Tutorial/FILES.cmake b/samples/qt/Tutorial/FILES.cmake new file mode 100644 index 0000000000..582da6d718 --- /dev/null +++ b/samples/qt/Tutorial/FILES.cmake @@ -0,0 +1,36 @@ +# Source files for Tutorial sample +set(OCCT_Tutorial_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}") + +set(OCCT_Tutorial_FILES + src/ApplicationTut.cxx + src/ApplicationTut.h + src/DocumentTut.cxx + src/DocumentTut.h + src/Main.cxx + src/MakeBottle.cxx + src/Tutorial-icon.ts + src/Tutorial-string.ts + ../Common/src/ApplicationCommon.cxx + ../Common/src/ApplicationCommon.h + ../Common/src/Common-icon.ts + ../Common/src/Common-string.ts + ../Common/src/CommonSample.h + ../Common/src/DocumentCommon.cxx + ../Common/src/DocumentCommon.h + ../Common/src/Material.cxx + ../Common/src/Material.h + ../Common/src/MDIWindow.cxx + ../Common/src/MDIWindow.h + ../Common/src/OcctWindow.cxx + ../Common/src/OcctWindow.h + ../Common/src/Transparency.cxx + ../Common/src/Transparency.h + ../Common/src/View.cxx + ../Common/src/View.h + ../Interface/src/Application.cxx + ../Interface/src/Application.h + ../Interface/src/IESample.h + ../Interface/src/Interface-string.ts + ../Interface/src/Translate.cxx + ../Interface/src/Translate.h +) \ No newline at end of file diff --git a/samples/qt/Tutorial/PACKAGES b/samples/qt/Tutorial/PACKAGES deleted file mode 100644 index bd31a4fb0b..0000000000 --- a/samples/qt/Tutorial/PACKAGES +++ /dev/null @@ -1,2 +0,0 @@ -Tutorial/src -Common/src \ No newline at end of file diff --git a/samples/qt/Tutorial/PACKAGES.cmake b/samples/qt/Tutorial/PACKAGES.cmake new file mode 100644 index 0000000000..7ce8db3957 --- /dev/null +++ b/samples/qt/Tutorial/PACKAGES.cmake @@ -0,0 +1,4 @@ +# Packages for Tutorial sample +set(OCCT_Tutorial_LIST_OF_PACKAGES + Tutorial +) \ No newline at end of file diff --git a/samples/qt/Tutorial/src/FILES b/samples/qt/Tutorial/src/FILES deleted file mode 100644 index 54bd00b648..0000000000 --- a/samples/qt/Tutorial/src/FILES +++ /dev/null @@ -1,8 +0,0 @@ -ApplicationTut.cxx -ApplicationTut.h -DocumentTut.cxx -DocumentTut.h -Main.cxx -MakeBottle.cxx -Tutorial-icon.ts -Tutorial-string.ts