From: vsv Date: Wed, 11 Mar 2015 09:33:38 +0000 (+0300) Subject: Create SketcherPrs package X-Git-Tag: V_1.1.0~143^2~1^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f15802c13f98af8d10e7b81cbd4506d3b486da59;p=modules%2Fshaper.git Create SketcherPrs package --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 895c8e8ed..8406c7645 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ ADD_SUBDIRECTORY (src/GeomDataAPI) ADD_SUBDIRECTORY (src/PartSetPlugin) ADD_SUBDIRECTORY (src/ConstructionPlugin) ADD_SUBDIRECTORY (src/FeaturesPlugin) +ADD_SUBDIRECTORY (src/SketcherPrs) ADD_SUBDIRECTORY (src/SketchPlugin) ADD_SUBDIRECTORY (src/SketchSolver) ADD_SUBDIRECTORY (src/ModuleBase) diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index ef0f5b1a9..e1726ca50 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -29,6 +29,7 @@ SET(PROJECT_HEADERS GeomAPI_DataMapOfShapeShape.h GeomAPI_ICustomPrs.h GeomAPI_Vertex.h + GeomAPI_Ax3.h ) SET(PROJECT_SOURCES @@ -53,6 +54,7 @@ SET(PROJECT_SOURCES GeomAPI_DataMapOfShapeShape.cpp GeomAPI_Vertex.cpp GeomAPI_ICustomPrs.cpp + GeomAPI_Ax3.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 5e0c21b44..021ebfeb2 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -96,9 +96,9 @@ void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoin Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); anAspect->MakeArrows3d(Standard_False); - anAspect->MakeText3d(false); + anAspect->MakeText3d(Standard_False); anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); - anAspect->MakeTextShaded(false); + anAspect->MakeTextShaded(Standard_True); anAspect->ArrowAspect()->SetLength(theDistance / 10.); aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false); aDimAIS->SetDimensionAspect(anAspect); diff --git a/src/GeomAPI/GeomAPI_Ax3.cpp b/src/GeomAPI/GeomAPI_Ax3.cpp new file mode 100644 index 000000000..d7950b585 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Ax3.cpp @@ -0,0 +1,107 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAPI_Ax3.cpp +// Created: 16 February 2015 +// Author: Vitaly SMETANNIKOV + + +#include "GeomAPI_Ax3.h" +#include "GeomAPI_XYZ.h" +#include "GeomAPI_Pnt2d.h" + +#include +#include +#include +#include + + +#define MY_AX3 static_cast(myImpl) + + +GeomAPI_Ax3::GeomAPI_Ax3() +: GeomAPI_Interface(new gp_Ax3()) +{ +} + +GeomAPI_Ax3::GeomAPI_Ax3(std::shared_ptr theOrigin, + std::shared_ptr theDirX, + std::shared_ptr theDirY, + std::shared_ptr theNorm) +: GeomAPI_Interface(new gp_Ax3(theOrigin->impl(), + theNorm->impl(), + theDirX->impl())) + { + MY_AX3->SetYDirection(theDirY->impl()); + } + +void GeomAPI_Ax3::setOrigin(const std::shared_ptr& theOrigin) +{ + gp_Ax1 aAx1 = MY_AX3->Axis(); + aAx1.SetLocation(theOrigin->impl()); + MY_AX3->SetAxis(aAx1); +} + +std::shared_ptr GeomAPI_Ax3::origin() const +{ + gp_Pnt aPnt = MY_AX3->Axis().Location(); + return std::shared_ptr(new GeomAPI_Pnt(aPnt.X(),aPnt.Y(),aPnt.Z())); +} + +void GeomAPI_Ax3::setDirX(const std::shared_ptr& theDirX) +{ + MY_AX3->SetXDirection(theDirX->impl()); +} + +std::shared_ptr GeomAPI_Ax3::dirX() const +{ + gp_Dir aDir = MY_AX3->XDirection(); + return std::shared_ptr(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); +} + +void GeomAPI_Ax3::setDirY(const std::shared_ptr& theDirY) +{ + MY_AX3->SetYDirection(theDirY->impl()); +} + +std::shared_ptr GeomAPI_Ax3::dirY() const +{ + gp_Dir aDir = MY_AX3->YDirection(); + return std::shared_ptr(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); +} + +void GeomAPI_Ax3::setNorm(const std::shared_ptr& theNorm) +{ + gp_Ax1 aAx1 = MY_AX3->Axis(); + aAx1.SetDirection(theNorm->impl()); + MY_AX3->SetAxis(aAx1); +} + +std::shared_ptr GeomAPI_Ax3::norm() const +{ + gp_Dir aDir = MY_AX3->Axis().Direction(); + return std::shared_ptr(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z())); +} + + +std::shared_ptr GeomAPI_Ax3::to3D(double theX, double theY) const +{ + gp_Pnt aPnt = MY_AX3->Axis().Location(); + gp_Dir aXDir = MY_AX3->XDirection(); + gp_Dir aYDir = MY_AX3->YDirection(); + gp_XYZ aSum = aPnt.XYZ().Added(aXDir.XYZ().Multiplied(theX)).Added(aYDir.XYZ().Multiplied(theY)); + + return std::shared_ptr(new GeomAPI_Pnt(aSum.X(), aSum.Y(), aSum.Z())); +} + +std::shared_ptr GeomAPI_Ax3::to2D(double theX, double theY, double theZ) const +{ + gp_Pnt anOriginPnt = MY_AX3->Axis().Location(); + gp_Vec aVec(anOriginPnt, gp_Pnt(0, 0, 0)); + + gp_Dir aXDir = MY_AX3->XDirection(); + gp_Dir aYDir = MY_AX3->YDirection(); + + double aX = aVec.X() * aXDir.X() + aVec.Y() * aXDir.Y() + aVec.Z() * aXDir.Z(); + double aY = aVec.X() * aYDir.X() + aVec.Y() * aYDir.Y() + aVec.Z() * aYDir.Y(); + return std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); +} \ No newline at end of file diff --git a/src/GeomAPI/GeomAPI_Ax3.h b/src/GeomAPI/GeomAPI_Ax3.h new file mode 100644 index 000000000..67bde43ef --- /dev/null +++ b/src/GeomAPI/GeomAPI_Ax3.h @@ -0,0 +1,73 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAPI_Ax3.hxx +// Created: 16 February 2015 +// Author: Vitaly SMETANNIKOV + +#ifndef GEOMAPI_AX3_H_ +#define GEOMAPI_AX3_H_ + +#include "GeomAPI.h" +#include "GeomAPI_Pnt.h" +#include "GeomAPI_Dir.h" + +/** + * \ingroup DataModel + * \brief The class represents a coordinate plane which is 2d plane with X and Y directions + * and origin + */ +class GEOMAPI_EXPORT GeomAPI_Ax3 : public GeomAPI_Interface +{ +public: + /// Default constructor + GeomAPI_Ax3(); + + /// Ñonstructor + /// \param theOrigin point of origin + /// \param theDirX direction of X axis + /// \param theDirY direction of Y axis + /// \param theNorm direction of normal vector + GeomAPI_Ax3(std::shared_ptr theOrigin, + std::shared_ptr theDirX, + std::shared_ptr theDirY, + std::shared_ptr theNorm); + + /// Sets origin point + void setOrigin(const std::shared_ptr& theOrigin); + + /// Returns the plane origin point + std::shared_ptr origin() const; + + /// Sets X direction vector + void setDirX(const std::shared_ptr& theDirX); + + /// Returns X direction vector + std::shared_ptr dirX() const; + + /// Sets Y direction vector + void setDirY(const std::shared_ptr& theDirY); + + /// Returns Y direction vector + std::shared_ptr dirY() const; + + /// Sets Z direction vector + void setNorm(const std::shared_ptr& theNorm); + + /// Returns Z direction vector + std::shared_ptr norm() const; + + /// Converts 2d coordinates from the plane to 3d space point + /// \param theX X coordinate + /// \param theY Y coordinate + std::shared_ptr to3D(double theX, double theY) const; + + /// Converts 3d to 2d coordinates of the plane + /// \param theX X coordinate + /// \param theY Y coordinate + /// \param theZ Z coordinate + std::shared_ptr to2D(double theX, double theY, double theZ) const; + +}; + + +#endif \ No newline at end of file diff --git a/src/GeomAPI/GeomAPI_PlanarEdges.cpp b/src/GeomAPI/GeomAPI_PlanarEdges.cpp index 53470fb5e..f7757cf7e 100644 --- a/src/GeomAPI/GeomAPI_PlanarEdges.cpp +++ b/src/GeomAPI/GeomAPI_PlanarEdges.cpp @@ -52,7 +52,7 @@ std::list > GeomAPI_PlanarEdges::getEdges() } bool GeomAPI_PlanarEdges::hasPlane() const { - return myOrigin && myNorm && myDirX && myDirY; + return myPlane.get() != NULL; } bool GeomAPI_PlanarEdges::isVertex() const { @@ -63,28 +63,38 @@ bool GeomAPI_PlanarEdges::isEdge() const { return false; } -void GeomAPI_PlanarEdges::setOrigin(const std::shared_ptr& theOrigin) +std::shared_ptr GeomAPI_PlanarEdges::origin() const { - myOrigin = theOrigin; + if (hasPlane()) + return myPlane->origin(); + return std::shared_ptr(); } -std::shared_ptr GeomAPI_PlanarEdges::origin() const { - return myOrigin; -} -void GeomAPI_PlanarEdges::setDirX(const std::shared_ptr& theDirX) { - myDirX = theDirX; -} -std::shared_ptr GeomAPI_PlanarEdges::dirX() const { - return myDirX; -} -void GeomAPI_PlanarEdges::setDirY(const std::shared_ptr& theDirY) { - myDirY = theDirY; -} -std::shared_ptr GeomAPI_PlanarEdges::dirY() const { - return myDirY; + +std::shared_ptr GeomAPI_PlanarEdges::dirX() const +{ + if (hasPlane()) + return myPlane->dirX(); + return std::shared_ptr(); } -void GeomAPI_PlanarEdges::setNorm(const std::shared_ptr& theNorm) { - myNorm = theNorm; + +std::shared_ptr GeomAPI_PlanarEdges::dirY() const +{ + if (hasPlane()) + return myPlane->dirY(); + return std::shared_ptr(); } -std::shared_ptr GeomAPI_PlanarEdges::norm() const { - return myNorm; + +std::shared_ptr GeomAPI_PlanarEdges::norm() const +{ + if (hasPlane()) + return myPlane->norm(); + return std::shared_ptr(); } + +void GeomAPI_PlanarEdges::setPlane(const std::shared_ptr& theOrigin, + const std::shared_ptr& theDirX, + const std::shared_ptr& theDirY, + const std::shared_ptr& theNorm) +{ + myPlane = std::shared_ptr(new GeomAPI_Ax3(theOrigin, theDirX, theDirY, theNorm)); +} \ No newline at end of file diff --git a/src/GeomAPI/GeomAPI_PlanarEdges.h b/src/GeomAPI/GeomAPI_PlanarEdges.h index 627bc5d71..1eddd16c8 100644 --- a/src/GeomAPI/GeomAPI_PlanarEdges.h +++ b/src/GeomAPI/GeomAPI_PlanarEdges.h @@ -11,6 +11,7 @@ #include "GeomAPI_Edge.h" #include "GeomAPI_Pnt.h" #include "GeomAPI_Dir.h" +#include "GeomAPI_Ax3.h" #include @@ -41,36 +42,31 @@ class GeomAPI_PlanarEdges : public GeomAPI_Shape /// Returns True if the wire is defined in a plane GEOMAPI_EXPORT bool hasPlane() const; - /// Sets origin point - GEOMAPI_EXPORT void setOrigin(const std::shared_ptr& theOrigin); - /// Returns the plane origin point GEOMAPI_EXPORT std::shared_ptr origin() const; - /// Sets X direction vector - GEOMAPI_EXPORT void setDirX(const std::shared_ptr& theDirX); /// Returns X direction vector GEOMAPI_EXPORT std::shared_ptr dirX() const; - /// Sets Y direction vector - GEOMAPI_EXPORT void setDirY(const std::shared_ptr& theDirY); /// Returns Y direction vector GEOMAPI_EXPORT std::shared_ptr dirY() const; - /// Sets Z direction vector - GEOMAPI_EXPORT void setNorm(const std::shared_ptr& theNorm); /// Returns Z direction vector GEOMAPI_EXPORT std::shared_ptr norm() const; + /// Set working plane + /// \param theOrigin origin of the plane axis + /// \param theDirX X direction of the plane axis + /// \param theDirY Y direction of the plane axis + /// \param theNorm normal direction of the plane axis + GEOMAPI_EXPORT void setPlane(const std::shared_ptr& theOrigin, + const std::shared_ptr& theDirX, + const std::shared_ptr& theDirY, + const std::shared_ptr& theNorm); + private: - /// Origin point of the plane - std::shared_ptr myOrigin; - /// The X direction inside of the plane - std::shared_ptr myDirX; - /// The Y direction inside of the plane - std::shared_ptr myDirY; - /// The normal direction to the plane - std::shared_ptr myNorm; + + std::shared_ptr myPlane; }; #endif diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 3b9c8dc26..15bbb1fb7 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -52,6 +52,7 @@ SET(PROJECT_LIBRARIES GeomAPI GeomAlgoAPI ModelAPI + SketcherPrs ${CAS_KERNEL} ${CAS_SHAPE} ) @@ -71,6 +72,7 @@ INCLUDE_DIRECTORIES( ../GeomAPI ../GeomAlgoAPI ../GeomDataAPI + ../SketcherPrs ) INSTALL(TARGETS SketchPlugin DESTINATION plugins) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp index 15f6d1ccc..358158325 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp @@ -6,9 +6,13 @@ #include "SketchPlugin_ConstraintCoincidence.h" +#include + #include #include #include +#include +#include SketchPlugin_ConstraintCoincidence::SketchPlugin_ConstraintCoincidence() { @@ -24,3 +28,15 @@ void SketchPlugin_ConstraintCoincidence::execute() { } +AISObjectPtr SketchPlugin_ConstraintCoincidence::getAISObject(AISObjectPtr thePrevious) +{ + if (!sketch()) + return thePrevious; + + AISObjectPtr anAIS = thePrevious; + if (!anAIS) { + anAIS = SketcherPrs_Factory::coincidentConstraint(this, sketch()->coordinatePlane()); + anAIS->setColor(0, 0, 255); + } + return anAIS; +} \ No newline at end of file diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h index ce1939f76..c3f359d73 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h @@ -35,6 +35,9 @@ class SketchPlugin_ConstraintCoincidence : public SketchPlugin_ConstraintBase return MY_KIND; } + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp index ae26fc1c2..29a7f0a25 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp @@ -5,7 +5,6 @@ // Author: Artem ZHIDKOV #include "SketchPlugin_ConstraintParallel.h" -#include "SketchPlugin_ConstraintPerpendicular.h" #include #include @@ -14,9 +13,13 @@ #include #include +#include + #include #include #include +#include +#include #include @@ -28,7 +31,7 @@ void SketchPlugin_ConstraintParallel::initAttributes() { data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); - data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); + //data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); } void SketchPlugin_ConstraintParallel::execute() @@ -40,67 +43,11 @@ AISObjectPtr SketchPlugin_ConstraintParallel::getAISObject(AISObjectPtr thePrevi if (!sketch()) return thePrevious; - std::shared_ptr aData = data(); - std::shared_ptr anAttr1 = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - std::shared_ptr anAttr2 = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); - if (!anAttr1 || !anAttr1->isObject() || !anAttr2 || !anAttr2->isObject()) - return thePrevious; - - FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object()); - if (!aFeature) - return thePrevious; - std::shared_ptr aLine1Feature = - std::dynamic_pointer_cast(aFeature); - - aFeature = ModelAPI_Feature::feature(anAttr2->object()); - if (!aFeature) - return thePrevious; - std::shared_ptr aLine2Feature = - std::dynamic_pointer_cast(aFeature); - - if (!aLine1Feature || !aLine2Feature) - return thePrevious; - - std::shared_ptr aPlane = sketch()->plane(); - std::shared_ptr aLine1, aLine2; - std::shared_ptr aConst1 = std::dynamic_pointer_cast< - ModelAPI_ResultConstruction>(anAttr1->object()); - if (aConst1) - aLine1 = aConst1->shape(); - std::shared_ptr aConst2 = std::dynamic_pointer_cast< - ModelAPI_ResultConstruction>(anAttr2->object()); - if (aConst2) - aLine2 = aConst2->shape(); - - std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - std::shared_ptr aFlyoutPnt = std::shared_ptr();; - if(aFlyoutAttr->isInitialized()) { - aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); - } - AISObjectPtr anAIS = thePrevious; - if (!anAIS) - anAIS = AISObjectPtr(new GeomAPI_AISObject); - anAIS->createParallel(aLine1, aLine2, aFlyoutPnt, aPlane); - - // Set color from preferences - std::vector aRGB = Config_PropManager::color("Visualization", "sketch_parallel_color", - SKETCH_CONSTRAINT_COLOR); - anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); + if (!anAIS) { + anAIS = SketcherPrs_Factory::parallelConstraint(this, sketch()->coordinatePlane()); + } return anAIS; } -void SketchPlugin_ConstraintParallel::move(double theDeltaX, double theDeltaY) -{ - std::shared_ptr aData = data(); - if (!aData->isValid()) - return; - - std::shared_ptr aPoint = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - aPoint->move(theDeltaX, theDeltaY); -} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h index 87f69fe70..afaae6c00 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h @@ -46,7 +46,7 @@ class SketchPlugin_ConstraintParallel : public SketchPlugin_ConstraintBase /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved /// \param theDeltaY the delta for Y coordinate is moved - SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); + //SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY); /// \brief Use plugin manager for features creation SketchPlugin_ConstraintParallel(); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index f243c86c7..fdaff1d84 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -116,10 +116,7 @@ void SketchPlugin_Sketch::execute() for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) { aBigWire->addEdge(*aShapeIt); } - aBigWire->setOrigin(anOrigin->pnt()); - aBigWire->setDirX(aDirX->dir()); - aBigWire->setDirY(aDirY->dir()); - aBigWire->setNorm(aNorm->dir()); + aBigWire->setPlane(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir()); // GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(), // aFeaturesPreview, aLoops, aWires); @@ -245,6 +242,21 @@ std::shared_ptr SketchPlugin_Sketch::plane() return std::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir())); } +std::shared_ptr SketchPlugin_Sketch::coordinatePlane() const +{ + DataPtr aData = data(); + std::shared_ptr aC = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + std::shared_ptr aX = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::DIRX_ID())); + std::shared_ptr aY = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::DIRY_ID())); + std::shared_ptr aNorm = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Sketch::NORM_ID())); + + return std::shared_ptr(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aY->dir(), aNorm->dir())); +} + void SketchPlugin_Sketch::erase() { std::shared_ptr aRefList = std::dynamic_pointer_cast< diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index c4721f547..43a6e3707 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #define YZ_PLANE_COLOR "#ff0000" @@ -81,7 +82,6 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) { } - ; /// Return the distance between the feature and the point /// \param thePoint the point @@ -89,7 +89,6 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I { return 0; } - ; /// Converts a 2D sketch space point into point in 3D space SKETCHPLUGIN_EXPORT std::shared_ptr to3D(const double theX, const double theY); @@ -106,6 +105,8 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I /// Returns the basis plane for the sketch std::shared_ptr plane(); + SKETCHPLUGIN_EXPORT std::shared_ptr coordinatePlane() const; + //virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); /// removes also all sub-sketch elements diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 9eb94b38f..3c763c26b 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -116,7 +116,6 @@ - diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt new file mode 100644 index 000000000..fcb8889ad --- /dev/null +++ b/src/SketcherPrs/CMakeLists.txt @@ -0,0 +1,48 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +SET(PROJECT_HEADERS + SketcherPrs.h + SketcherPrs_Coincident.h + SketcherPrs_Factory.h + SketcherPrs_Parallel.h + SketcherPrs_Tools.h +) + +SET(PROJECT_SOURCES + SketcherPrs_Coincident.cpp + SketcherPrs_Factory.cpp + SketcherPrs_Parallel.cpp + SketcherPrs_Tools.cpp +) + +SET(PROJECT_LIBRARIES + Config + ModelAPI + GeomAPI + ${CAS_KERNEL} + ${CAS_MODELER} + ${CAS_VIEWER} + ${CAS_SHAPE} + ${CAS_TKTopAlgo} +) + +SET(PROJECT_PICTURES + icons/parallel.png +) + +ADD_DEFINITIONS(-DCONSTRAINTS_EXPORTS ${CAS_DEFINITIONS}) +ADD_LIBRARY(SketcherPrs SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) + +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/Config + ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/GeomAPI + ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/SketchPlugin + ${CAS_INCLUDE_DIRS} +) + +TARGET_LINK_LIBRARIES(SketcherPrs ${PROJECT_LIBRARIES}) + +INSTALL(TARGETS SketcherPrs DESTINATION bin) +INSTALL(FILES ${PROJECT_PICTURES} DESTINATION resources) diff --git a/src/SketcherPrs/SketcherPrs.h b/src/SketcherPrs/SketcherPrs.h new file mode 100644 index 000000000..978f8c2e6 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs.h @@ -0,0 +1,20 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef SKETCHERPRS_H +#define SKETCHERPRS_H + +#if defined SKETCHERPRS_EXPORTS +#if defined WIN32 +#define SKETCHERPRS_EXPORT __declspec( dllexport ) +#else +#define SKETCHERPRS_EXPORT +#endif +#else +#if defined WIN32 +#define SKETCHERPRS_EXPORT __declspec( dllimport ) +#else +#define SKETCHERPRS_EXPORT +#endif +#endif + +#endif diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp new file mode 100644 index 000000000..60c2e451a --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -0,0 +1,78 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Coincident.cpp +// Created: 12 February 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_Coincident.h" +#include "SketcherPrs_Tools.h" + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject); + +SketcherPrs_Coincident::SketcherPrs_Coincident(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane) + : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane) +{ +} + + + +void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(myConstraint, + SketchPlugin_Constraint::ENTITY_A()); + if (aPnt.get() == NULL) + return; + + std::shared_ptr aPoint = myPlane->to3D(aPnt->x(), aPnt->y()); + + static Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d (); + aPtA->SetType(Aspect_TOM_RING1); + aPtA->SetScale(2.); + aPtA->SetColor(myOwnColor); + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); + aGroup->SetPrimitivesAspect(aPtA); + Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1); + aPntArray->AddVertex (aPoint->x(), aPoint->y(), aPoint->z()); + aGroup->AddPrimitiveArray (aPntArray); +} + + +void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer aMode) +{ +} + +void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol) +{ + SetColor(Quantity_Color(aCol)); +} + +void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol) +{ + hasOwnColor=Standard_True; + myOwnColor=aCol; +} diff --git a/src/SketcherPrs/SketcherPrs_Coincident.h b/src/SketcherPrs/SketcherPrs_Coincident.h new file mode 100644 index 000000000..9b9c4cd8a --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Coincident.h @@ -0,0 +1,53 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Coincident.h +// Created: 12 February 2015 +// Author: Vitaly SMETANNIKOV + +#ifndef SketcherPrs_Coincident_H +#define SketcherPrs_Coincident_H + +#include + +#include +#include + +class SketchPlugin_Constraint; + + +DEFINE_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject) + +/** +* \ingroup GUI +* A redefinition of standard AIS Interactive Object in order to provide +* presentation of coincident constraint +*/ +class SketcherPrs_Coincident: public AIS_InteractiveObject +{ +public: + /// Constructor + /// \param theResult a result object + Standard_EXPORT SketcherPrs_Coincident(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane); + + Standard_EXPORT virtual void SetColor(const Quantity_Color& aColor); + + Standard_EXPORT virtual void SetColor(const Quantity_NameOfColor aColor); + + DEFINE_STANDARD_RTTI(SketcherPrs_Coincident) +protected: + /// Redefinition of virtual function + Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); + + /// Redefinition of virtual function + Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer aMode) ; + +private: + SketchPlugin_Constraint* myConstraint; + std::shared_ptr myPlane; +}; + + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Factory.cpp b/src/SketcherPrs/SketcherPrs_Factory.cpp new file mode 100644 index 000000000..829052fee --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Factory.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Factory.cpp +// Created: 13 February 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_Factory.h" + +#include +#include + + +AISObjectPtr SketcherPrs_Factory::coincidentConstraint(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane) +{ + std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + Handle(SketcherPrs_Coincident) aPrs = new SketcherPrs_Coincident(theConstraint, thePlane); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); + return aAISObj; +} + + +AISObjectPtr SketcherPrs_Factory::parallelConstraint(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane) +{ + std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + Handle(SketcherPrs_Parallel) aPrs = new SketcherPrs_Parallel(theConstraint, thePlane); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); + return aAISObj; +} \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Factory.h b/src/SketcherPrs/SketcherPrs_Factory.h new file mode 100644 index 000000000..75a496f80 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Factory.h @@ -0,0 +1,36 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Factory.h +// Created: 13 February 2015 +// Author: Vitaly SMETANNIKOV + +#ifndef SketcherPrs_Factory_H_ +#define SketcherPrs_Factory_H_ + +#include "SketcherPrs.h" + +#include +#include + +class SketchPlugin_Constraint; + +/** +* Class which creates constraints presentations +*/ +class SKETCHERPRS_EXPORT SketcherPrs_Factory +{ +public: + /// Creates coincedent constraint presentation + /// \param theConstraint the constraint + /// \param thePlane the current sketch plane + static AISObjectPtr coincidentConstraint(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane); + + /// Creates coincedent parallel presentation + /// \param theConstraint the constraint + /// \param thePlane the current sketch plane + static AISObjectPtr parallelConstraint(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane); +}; + +#endif diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp new file mode 100644 index 000000000..74e97723b --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Parallel.cpp @@ -0,0 +1,124 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Parallel.cpp +// Created: 16 February 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_Parallel.h" +#include "SketcherPrs_Tools.h" + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern std::shared_ptr getFeaturePoint(DataPtr theData, + const std::string& theAttribute); + +#ifdef WIN32 +# define FSEP "\\" +#else +# define FSEP "/" +#endif + + +IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject); +IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, AIS_InteractiveObject); + +static Handle(Image_AlienPixMap) MyPixMap; + +SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane) + : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane) +{ + if (MyPixMap.IsNull()) { + TCollection_AsciiString aFile(getenv("NewGeomResources")); + aFile += FSEP; + aFile += "parallel.png"; + MyPixMap = new Image_AlienPixMap(); + if (!MyPixMap->Load(aFile)) + MyPixMap.Nullify(); + } + if (!MyPixMap.IsNull()) { + myAspect = new Graphic3d_AspectMarker3d(MyPixMap); + myPntArray = new Graphic3d_ArrayOfPoints(2); + myPntArray->AddVertex(0., 0., 0.); + myPntArray->AddVertex(0. ,0., 0.); + } +} + +void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + if (myAspect.IsNull()) + return; + + std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + if (aLine1.get() == NULL) + return; + + std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + if (aLine2.get() == NULL) + return; + + std::shared_ptr aPnt1 = aLine1->firstPoint(); + std::shared_ptr aPnt2 = aLine1->lastPoint(); + gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2., + (aPnt1->y() + aPnt2->y())/2., + (aPnt1->z() + aPnt2->z())/2.); + + gp_Vec aVec1(aPnt1->impl(), aPnt2->impl()); + gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl()); + aShift.Normalize(); + aShift.Multiply(20); + aP1.Translate(aShift); + + aPnt1 = aLine2->firstPoint(); + aPnt2 = aLine2->lastPoint(); + gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2., + (aPnt1->y() + aPnt2->y())/2., + (aPnt1->z() + aPnt2->z())/2.); + + gp_Vec aVec2(aPnt1->impl(), aPnt2->impl()); + aShift = aVec1.Crossed(myPlane->norm()->impl()); + aShift.Normalize(); + aShift.Multiply(20); + aP2.Translate(aShift); + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); + aGroup->SetPrimitivesAspect(myAspect); + myPntArray->SetVertice(1, aP1); + myPntArray->SetVertice(2, aP2); + aGroup->AddPrimitiveArray(myPntArray); +} + +void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer aMode) +{ + std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + if (aLine1.get() == NULL) + return; + + std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + if (aLine2.get() == NULL) + return; + + Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this); + Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(1)); + Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(2)); + aSelection->Add(aSP1); + aSelection->Add(aSP2); +} + diff --git a/src/SketcherPrs/SketcherPrs_Parallel.h b/src/SketcherPrs/SketcherPrs_Parallel.h new file mode 100644 index 000000000..5e39abb8f --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Parallel.h @@ -0,0 +1,56 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Parallel.h +// Created: 16 February 2015 +// Author: Vitaly SMETANNIKOV + +#ifndef SketcherPrs_Parallel_H +#define SketcherPrs_Parallel_H + +#include +#include + +#include +#include +#include +#include + +class SketchPlugin_Constraint; +class SketchPlugin_Sketch; + + +DEFINE_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject) + +/** +* \ingroup GUI +* A redefinition of standard AIS Interactive Object in order to provide +* presentation of coincident constraint +*/ +class SketcherPrs_Parallel: public AIS_InteractiveObject +{ +public: + /// Constructor + /// \param theResult a result object + Standard_EXPORT SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, + const std::shared_ptr& thePlane); + + + DEFINE_STANDARD_RTTI(SketcherPrs_Parallel) +protected: + /// Redefinition of virtual function + Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); + + /// Redefinition of virtual function + Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer aMode) ; + +private: + + SketchPlugin_Constraint* myConstraint; + std::shared_ptr myPlane; + Handle(Graphic3d_AspectMarker3d) myAspect; + Handle(Graphic3d_ArrayOfPoints) myPntArray; +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp new file mode 100644 index 000000000..2f356e16b --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -0,0 +1,69 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Tools.cpp +// Created: 10 March 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_Tools.h" + +#include +#include +#include +#include +#include + +#include + + +namespace SketcherPrs_Tools { + + +std::shared_ptr getLine(SketchPlugin_Constraint* theFeature, + const std::string& theAttrName) +{ + std::shared_ptr aData = theFeature->data(); + std::shared_ptr anAttr = + std::dynamic_pointer_cast(aData->attribute(theAttrName)); + + ObjectPtr aObject = anAttr->object(); + ResultConstructionPtr aRes = std::dynamic_pointer_cast(aObject); + if (aRes.get() != NULL) { + std::shared_ptr aShape = aRes->shape(); + if (aShape.get() != NULL) { + return std::shared_ptr(new GeomAPI_Edge(aShape)); + } + } + return std::shared_ptr(); +} + + +std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, + const std::string& theAttribute) +{ + std::shared_ptr aPointAttr; + + if (!theFeature->data()) + return std::shared_ptr(); + + FeaturePtr aFeature; + std::shared_ptr anAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute)); + if (anAttr) + aFeature = ModelAPI_Feature::feature(anAttr->object()); + + if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) + aPointAttr = std::dynamic_pointer_cast( + aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); + + else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID()) + aPointAttr = std::dynamic_pointer_cast( + aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); + + else if (anAttr->attr()) { + aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); + } + return aPointAttr->pnt(); +} + + +}; \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h new file mode 100644 index 000000000..5a9329560 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -0,0 +1,27 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_Tools.h +// Created: 10 March 2015 +// Author: Vitaly SMETANNIKOV + +#ifndef SketcherPrs_Tools_H +#define SketcherPrs_Tools_H + +#include "SketcherPrs.h" +#include +#include +#include + +class SketchPlugin_Constraint; + +namespace SketcherPrs_Tools { + + std::shared_ptr getLine(SketchPlugin_Constraint* theFeature, + const std::string& theAttrName); + + std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, + const std::string& theAttrName); + +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/icons/parallel.png b/src/SketcherPrs/icons/parallel.png new file mode 100644 index 000000000..49186129f Binary files /dev/null and b/src/SketcherPrs/icons/parallel.png differ