//Widgets
const static char* WDG_DOUBLEVALUE = "doublevalue";
//Widget containers
+const static char* WDG_INFO = "label";
const static char* WDG_GROUP = "groupbox";
const static char* WDG_CHECK_GROUP = "check_groupbox";
const static char* WDG_TOOLBOX = "toolbox";
// doublevalue properties:
+const static char* INFO_WDG_TEXT = FEATURE_TEXT;
+const static char* INFO_WDG_TOOLTIP = FEATURE_TOOLTIP;
const static char* DOUBLE_WDG_MIN = "min";
const static char* DOUBLE_WDG_MAX = "max";
const static char* DOUBLE_WDG_STEP = "step";
double y() const;
/// returns Z coordinate
double z() const;
+
};
#endif
GeomAlgoAPI.h
GeomAlgoAPI_CompoundBuilder.h
GeomAlgoAPI_FaceBuilder.h
+ GeomAlgoAPI_EdgeBuilder.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_CompoundBuilder.cpp
GeomAlgoAPI_FaceBuilder.cpp
+ GeomAlgoAPI_EdgeBuilder.cpp
)
ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
--- /dev/null
+// File: GeomAlgoAPI_EdgeBuilder.cpp
+// Created: 23 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <gp_Pln.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+#include <Geom_Plane.hxx>
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::line(
+ boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
+{
+ const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
+ const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
+
+ BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
+ boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+ aRes->setImpl(new TopoDS_Shape(anEdge));
+ return aRes;
+}
--- /dev/null
+// File: GeomAlgoAPI_EdgeBuilder.h
+// Created: 23 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomAlgoAPI_EdgeBuilder_HeaderFile
+#define GeomAlgoAPI_EdgeBuilder_HeaderFile
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_Pnt.h>
+#include <boost/shared_ptr.hpp>
+
+/**\class GeomAlgoAPI_EdgeBuilder
+ * \ingroup DataAlgo
+ * \brief Allows to create face-shapes by different parameters
+ */
+
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder
+{
+public:
+ /// Creates linear edge by two points
+ static boost::shared_ptr<GeomAPI_Shape> line(
+ boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd);
+};
+
+#endif
SET(PROJECT_HEADERS
GeomData.h
GeomData_Point.h
+ GeomData_Dir.h
+ GeomData_Point2D.h
)
SET(PROJECT_SOURCES
GeomData_Point.cpp
+ GeomData_Dir.cpp
+ GeomData_Point2D.cpp
)
ADD_DEFINITIONS(-DGEOMDATA_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
ADD_LIBRARY(GeomData SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config)
+TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI GeomAPI)
INCLUDE_DIRECTORIES(
../ModelAPI
../GeomDataAPI
+ ../GeomAPI
../Events
../Config
${CAS_INCLUDE_DIRS}
--- /dev/null
+// File: GeomData_Dir.cxx
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include "GeomData_Dir.h"
+#include "GeomAPI_Dir.h"
+#include <gp_Dir.hxx>
+
+using namespace std;
+
+void GeomData_Dir::setValue(const double theX, const double theY, const double theZ)
+{
+ myCoords->SetValue(0, theX);
+ myCoords->SetValue(1, theY);
+ myCoords->SetValue(2, theZ);
+}
+
+double GeomData_Dir::x() const
+{
+ return myCoords->Value(0);
+}
+
+double GeomData_Dir::y() const
+{
+ return myCoords->Value(1);
+}
+
+double GeomData_Dir::z() const
+{
+ return myCoords->Value(2);
+}
+
+boost::shared_ptr<GeomAPI_Dir> GeomData_Dir::dir()
+{
+ return boost::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(
+ myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
+}
+
+GeomData_Dir::GeomData_Dir(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ // create attribute: not initialized by value yet, just zero
+ myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
+ }
+}
--- /dev/null
+// File: GeomData_Dir.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomData_Dir_HeaderFile
+#define GeomData_Dir_HeaderFile
+
+#include "GeomData.h"
+#include "GeomDataAPI_Dir.h"
+#include <TDataStd_RealArray.hxx>
+#include <TDF_Label.hxx>
+#include <boost/shared_ptr.hpp>
+
+class GeomAPI_Dir;
+
+/**\class GeomData_Dir
+ * \ingroup DataModel
+ * \brief Attribute that contains direction.
+ */
+class GeomData_Dir : public GeomDataAPI_Dir
+{
+ Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2]
+public:
+ /// Defines the double value
+ GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ);
+
+ /// Returns the X double value
+ GEOMDATA_EXPORT virtual double x() const;
+ /// Returns the Y double value
+ GEOMDATA_EXPORT virtual double y() const;
+ /// Returns the Z double value
+ GEOMDATA_EXPORT virtual double z() const;
+ /// Returns the direction of this attribute
+ GEOMDATA_EXPORT boost::shared_ptr<GeomAPI_Dir> dir();
+
+protected:
+ /// Initializes attributes
+ GEOMDATA_EXPORT GeomData_Dir(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
-// File: ModelAPI_AttributeDouble.cxx
-// Created: 2 Apr 2014
+// File: GeomData_Point.cxx
+// Created: 24 Apr 2014
// Author: Mikhail PONIKAROV
#include "GeomData_Point.h"
/**\class GeomData_Point
* \ingroup DataModel
- * \brief Attribute that contains real value with double precision.
+ * \brief Attribute that contains 3D point.
*/
-class GeomData_Point : public ModelAPI_Attribute
+class GeomData_Point : public GeomDataAPI_Point
{
Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2]
public:
/// Defines the double value
- virtual void setValue(const double theX, const double theY, const double theZ);
+ GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ);
/// Returns the X double value
- virtual double x() const;
+ GEOMDATA_EXPORT virtual double x() const;
/// Returns the Y double value
- virtual double y() const;
+ GEOMDATA_EXPORT virtual double y() const;
/// Returns the Z double value
- virtual double z() const;
+ GEOMDATA_EXPORT virtual double z() const;
protected:
/// Initializes attributes
- GeomData_Point(TDF_Label& theLabel);
+ GEOMDATA_EXPORT GeomData_Point(TDF_Label& theLabel);
+
+ friend class Model_Data;
};
#endif
--- /dev/null
+// File: GeomData_Point2D.cxx
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include "GeomData_Point2D.h"
+
+using namespace std;
+
+void GeomData_Point2D::setValue(const double theX, const double theY)
+{
+ myCoords->SetValue(0, theX);
+ myCoords->SetValue(1, theY);
+}
+
+double GeomData_Point2D::x() const
+{
+ return myCoords->Value(0);
+}
+
+double GeomData_Point2D::y() const
+{
+ return myCoords->Value(1);
+}
+
+GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ // create attribute: not initialized by value yet, just zero
+ myCoords = TDataStd_RealArray::Set(theLabel, 0, 1);
+ }
+}
--- /dev/null
+// File: GeomData_Point2D.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomData_Point2D_HeaderFile
+#define GeomData_Point2D_HeaderFile
+
+#include "GeomData.h"
+#include "GeomDataAPI_Point2D.h"
+#include <TDataStd_RealArray.hxx>
+#include <TDF_Label.hxx>
+
+/**\class GeomData_Point2D
+ * \ingroup DataModel
+ * \brief Attribute that contains 2D point.
+ */
+
+class GeomData_Point2D : public GeomDataAPI_Point2D
+{
+ Handle_TDataStd_RealArray myCoords; ///< X and Y doubles as real array attribute [0; 1]
+public:
+ /// Defines the double value
+ GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY);
+
+ /// Returns the X double value
+ GEOMDATA_EXPORT virtual double x() const;
+ /// Returns the Y double value
+ GEOMDATA_EXPORT virtual double y() const;
+
+protected:
+ /// Initializes attributes
+ GEOMDATA_EXPORT GeomData_Point2D(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
SET(PROJECT_HEADERS
GeomDataAPI.h
GeomDataAPI_Point.h
+ GeomDataAPI_Dir.h
+ GeomDataAPI_Point2D.h
)
SET(CMAKE_SWIG_FLAGS "")
%{
#include "GeomDataAPI.h"
#include "GeomDataAPI_Point.h"
+ #include "GeomDataAPI_Dir.h"
+ #include "GeomDataAPI_Point2D.h"
#include <boost/shared_ptr.hpp>
%}
// boost pointers
%include <boost_shared_ptr.i>
%shared_ptr(GeomDataAPI_Point)
+%shared_ptr(GeomDataAPI_Dir)
+%shared_ptr(GeomDataAPI_Point2D)
// all supported interfaces
%include "GeomDataAPI_Point.h"
+%include "GeomDataAPI_Dir.h"
+%include "GeomDataAPI_Point2D.h"
--- /dev/null
+// File: GeomDataAPI_Dir.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomDataAPI_Dir_HeaderFile
+#define GeomDataAPI_Dir_HeaderFile
+
+#include "GeomDataAPI.h"
+#include <ModelAPI_Attribute.h>
+
+/**\class GeomDataAPI_Dir
+ * \ingroup DataModel
+ * \brief Attribute that contains 3D direction coordinates.
+ */
+
+class GeomDataAPI_Dir : public ModelAPI_Attribute
+{
+public:
+ /// Defines the double value
+ virtual void setValue(const double theX, const double theY, const double theZ) = 0;
+
+ /// Returns the X double value
+ virtual double x() const = 0;
+ /// Returns the Y double value
+ virtual double y() const = 0;
+ /// Returns the Z double value
+ virtual double z() const = 0;
+
+ /// Returns the type of this class of attributes
+ static inline std::string type() {return std::string("Point");}
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType() {return type();}
+
+protected:
+ /// Objects are created for features automatically
+ GeomDataAPI_Dir()
+ {}
+};
+
+#endif
-// File: GeomData_AttributeDouble.h
-// Created: 2 Apr 2014
+// File: GeomDataAPI_Point.h
+// Created: 24 Apr 2014
// Author: Mikhail PONIKAROV
-#ifndef GeomData_AttributeDouble_HeaderFile
-#define GeomData_AttributeDouble_HeaderFile
+#ifndef GeomDataAPI_Point_HeaderFile
+#define GeomDataAPI_Point_HeaderFile
#include "GeomDataAPI.h"
#include <ModelAPI_Attribute.h>
-/**\class GeomData_AttributeDouble
+/**\class GeomDataAPI_Point
* \ingroup DataModel
- * \brief Attribute that contains real value with double precision.
+ * \brief Attribute that contains 3D point coordinates.
*/
class GeomDataAPI_Point : public ModelAPI_Attribute
virtual void setValue(const double theX, const double theY, const double theZ) = 0;
/// Returns the X double value
- virtual double x() = 0;
+ virtual double x() const = 0;
/// Returns the Y double value
- virtual double y() = 0;
+ virtual double y() const = 0;
/// Returns the Z double value
- virtual double z() = 0;
+ virtual double z() const = 0;
/// Returns the type of this class of attributes
static inline std::string type() {return std::string("Point");}
--- /dev/null
+// File: GeomDataAPI_Point2D.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomDataAPI_Point2D_HeaderFile
+#define GeomDataAPI_Point2D_HeaderFile
+
+#include "GeomDataAPI.h"
+#include <ModelAPI_Attribute.h>
+
+/**\class GeomDataAPI_Point2D
+ * \ingroup DataModel
+ * \brief Attribute that contains 2D point coordinates.
+ */
+
+class GeomDataAPI_Point2D : public ModelAPI_Attribute
+{
+public:
+ /// Defines the double value
+ virtual void setValue(const double theX, const double theY) = 0;
+
+ /// Returns the X double value
+ virtual double x() const = 0;
+ /// Returns the Y double value
+ virtual double y() const = 0;
+
+ /// Returns the type of this class of attributes
+ static inline std::string type() {return std::string("Point2D");}
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType() {return type();}
+
+protected:
+ /// Objects are created for features automatically
+ GeomDataAPI_Point2D()
+ {}
+};
+
+#endif
ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config)
+TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config GeomData)
INCLUDE_DIRECTORIES(
../ModelAPI
../Events
../Config
+ ../GeomData
+ ../GeomDataAPI
${CAS_INCLUDE_DIRS}
)
#include <Model_Data.h>
#include <Model_AttributeDocRef.h>
#include <Model_AttributeDouble.h>
+#include <GeomData_Point.h>
+#include <GeomData_Point2D.h>
#include <TDataStd_Name.hxx>
using namespace std;
anAttr = new Model_AttributeDocRef(anAttrLab);
else if (theAttrType == ModelAPI_AttributeDouble::type())
anAttr = new Model_AttributeDouble(anAttrLab);
+ else if (theAttrType == GeomData_Point::type())
+ anAttr = new GeomData_Point(anAttrLab);
+ else if (theAttrType == GeomData_Point2D::type())
+ anAttr = new GeomData_Point2D(anAttrLab);
if (anAttr)
myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
}
return aRes;
}
+
+boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string theID)
+{
+ boost::shared_ptr<ModelAPI_Attribute> aResult;
+ if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
+ return aResult;
+ return myAttrs[theID];
+}
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string theID);
/// Returns the attribute that contains real value with double precision
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string theID);
+ /// Returns the generic attribute by identifier
+ /// \param theID identifier of the attribute
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID);
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
* \ingroup DataModel
* \brief Generic attribute of the Object.
*/
-
class MODELAPI_EXPORT ModelAPI_Attribute
{
public:
class ModelAPI_AttributeDocRef;
class ModelAPI_AttributeDouble;
class ModelAPI_Document;
+class ModelAPI_Attribute;
/**\class ModelAPI_Data
* \ingroup DataModel
/// Returns the attribute that contains real value with double precision
virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string theID) = 0;
+ /// Returns the generic attribute by identifier
+ /// \param theID identifier of the attribute
+ virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID) = 0;
+
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
/// \param theID identifier of the attribute that can be referenced by this ID later
${CMAKE_SOURCE_DIR}/src/Events
${CMAKE_SOURCE_DIR}/src/ModuleBase
${CMAKE_SOURCE_DIR}/src/ModelAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
${CMAKE_SOURCE_DIR}/src/SketchPlugin
${CMAKE_SOURCE_DIR}/src/GeomAPI
${CAS_INCLUDE_DIRS}
)
# The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore
-TARGET_LINK_LIBRARIES(PartSet ${PROJECT_LIBRARIES} XGUI ModelAPI)
+TARGET_LINK_LIBRARIES(PartSet ${PROJECT_LIBRARIES} XGUI ModelAPI GeomAlgoAPI)
ADD_DEPENDENCIES(PartSet ModuleBase)
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
- if (aPreviewOp)
+ if (aPreviewOp) {
visualizePreview(true);
+ connect(aPreviewOp, SIGNAL(viewerProjectionChange(double, double, double)),
+ this, SLOT(onViewerProjectionChange(double, double, double)));
+ }
}
void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
if (aPreviewOp) {
XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
if (aViewer) {
- AIS_ListOfInteractive aList;
- aViewer->getSelectedObjects(aList);
- aPreviewOp->setSelectedObjects(aList);
+ NCollection_List<TopoDS_Shape> aList;
+ aViewer->getSelectedShapes(aList);
+ aPreviewOp->setSelectedShapes(aList);
}
}
}
+void PartSet_Module::onViewerProjectionChange(double theX, double theY, double theZ)
+{
+ XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+ if (aViewer) {
+ aViewer->setViewProjection(theX, theY, theZ);
+ }
+}
+
void PartSet_Module::visualizePreview(bool isDisplay)
{
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
}
else {
myWorkshop->displayer()->GlobalSelection(false);
- myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
+ myWorkshop->displayer()->Erase(anOperation->feature());
}
}
/// SLOT, that is called by the selection in the viewer is changed.
/// The selection is sent to the current operation if it listen the selection.
void onViewSelectionChanged();
+ /// SLOT, to apply to the current viewer the operation
+ /// \param theX the X projection value
+ /// \param theY the Y projection value
+ /// \param theZ the Z projection value
+ void onViewerProjectionChange(double theX, double theY, double theZ);
private:
/// Displays or erase the current operation preview, if it has it.
#include <PartSet_OperationSketch.h>
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <AIS_Shape.hxx>
#include <AIS_ListOfInteractive.hxx>
return TopAbs_FACE;
}
-void PartSet_OperationSketch::setSelectedObjects(const AIS_ListOfInteractive& theList)
+void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
{
if (theList.IsEmpty())
return;
- // 1. get selected fase
- Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(theList.First());
- if (anAISShape.IsNull())
- return;
-
- const TopoDS_Shape& aShape = anAISShape->Shape();
- boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
- aRes->setImpl(new TopoDS_Shape(aShape));
+ // get selected shape
+ const TopoDS_Shape& aShape = theList.First();
+ boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
+ aGShape->setImpl(new TopoDS_Shape(aShape));
// get plane parameters
- double anX = 1, anY = 0, aZ = 0, anOrigin = 0;
+ boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
// set plane parameters to feature
- //boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- //boost::shared_ptr<ModelAPI_AttributeDocRef> anAttr = aData->docRef(SKETCH_ATTR_X);
- //anAttr->setValue(anX);
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ double anA, aB, aC, aD;
+ aPlane->coefficients(anA, aB, aC, aD);
+
+ boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+ /*
+ aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
+ aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
+ aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
+ aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
+ */
+ // temporary solution for main planes only
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ anOrigin->setValue(0, 0, 0);
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ aNormal->setValue(anA, aB, aC);
+ boost::shared_ptr<GeomDataAPI_Dir> aDirX =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ aDirX->setValue(aB, aC, anA);
+ boost::shared_ptr<GeomDataAPI_Dir> aDirY =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+ aDirY->setValue(aC, anA, aB);
+
+ boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+ emit viewerProjectionChange(aDir->x(), aDir->y(), aDir->z());
commit();
}
virtual int getSelectionMode() const;
/// Gives the current selected objects to be processed by the operation
- /// \param theList a list of interactive selected objects
- virtual void setSelectedObjects(const AIS_ListOfInteractive& theList);
+ /// \param theList a list of interactive selected shapes
+ virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList);
};
#endif
#include "PartSet.h"
#include <TopoDS_Shape.hxx>
+#include <NCollection_List.hxx>
#include <ModuleBase_PropPanelOperation.h>
#include <QObject>
-class AIS_ListOfInteractive;
-
/*!
\class PartSet_OperationSketchBase
* \brief The base operation for the sketch features.
/// Gives the current selected objects to be processed by the operation
/// \param a list of interactive selected objects
- virtual void setSelectedObjects(const AIS_ListOfInteractive& aList) = 0;
+ virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList) = 0;
+
+signals:
+ void viewerProjectionChange(double theX, double theY, double theZ);
};
#endif
SketchPlugin_Feature.h
SketchPlugin_Plugin.h
SketchPlugin_Sketch.h
+ SketchPlugin_Line.h
)
SET(PROJECT_SOURCES
SketchPlugin_Feature.cpp
SketchPlugin_Plugin.cpp
SketchPlugin_Sketch.cpp
+ SketchPlugin_Line.cpp
)
SET(PROJECT_LIBRARIES
../ModelAPI
../GeomAPI
../GeomAlgoAPI
+ ../GeomDataAPI
)
SET(XML_RESOURCES
#include "SketchPlugin.h"
#include <ModelAPI_Feature.h>
-
#include <GeomAPI_Shape.h>
+class SketchPlugin_Sketch;
+
/**\class SketchPlugin_Feature
* \ingroup DataModel
* \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
{
public:
/// Returns the sketch preview
+ /// \param theSketch the owner of this feature
/// \return the built preview
SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview() = 0;
+ /// Adds sub-feature of the higher level feature (sub-element of the sketch)
+ /// \param theFeature sub-feature
+ SKETCHPLUGIN_EXPORT virtual const void addSub(
+ const boost::shared_ptr<ModelAPI_Feature>& theFeature) = 0;
+
protected:
/// Set the shape to the internal preview field
/// \param theShape a preview shape
/// Return the shape from the internal preview field
/// \return theShape a preview shape
const boost::shared_ptr<GeomAPI_Shape>& getPreview() const;
+ /// Sets the higher-level feature for the sub-feature (sketch for line)
+ void setSketch(SketchPlugin_Sketch* theSketch) {mySketch = theSketch;}
+ /// Returns the sketch of this feature
+ SketchPlugin_Sketch* sketch() {return mySketch;}
+
+ friend class SketchPlugin_Sketch;
private:
boost::shared_ptr<GeomAPI_Shape> myPreview; ///< the preview shape
+ SketchPlugin_Sketch* mySketch; /// sketch that contains this feature
};
#endif
--- /dev/null
+// File: SketchPlugin_Line.cxx
+// Created: 27 Mar 2014
+// Author: Mikhail PONIKAROV
+
+#include "SketchPlugin_Line.h"
+#include "SketchPlugin_Sketch.h"
+#include <ModelAPI_Data.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomDataAPI_Point2D.h>
+
+using namespace std;
+
+// face of the square-face displayed for selection of general plane
+const double PLANE_SIZE = 200;
+
+SketchPlugin_Line::SketchPlugin_Line()
+{
+}
+
+void SketchPlugin_Line::initAttributes()
+{
+ data()->addAttribute(LINE_ATTR_START, GeomDataAPI_Point2D::type());
+ data()->addAttribute(LINE_ATTR_END, GeomDataAPI_Point2D::type());
+}
+
+void SketchPlugin_Line::execute()
+{
+}
+
+const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Line::preview()
+{
+ SketchPlugin_Sketch* aSketch = sketch();
+ // compute a start point in 3D view
+ boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_START));
+ boost::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+ // compute an end point in 3D view
+ boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_END));
+ boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+ // make linear edge
+ boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+ setPreview(anEdge);
+
+ return getPreview();
+}
--- /dev/null
+// File: SketchPlugin_Line.h
+// Created: 24 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef SketchPlugin_Line_HeaderFile
+#define SketchPlugin_Line_HeaderFile
+
+#include "SketchPlugin.h"
+#include <SketchPlugin_Feature.h>
+#include <list>
+
+/// Start 2D point of the line
+const std::string LINE_ATTR_START("StartPoint");
+/// End 2D point of the line
+const std::string LINE_ATTR_END("EndPoint");
+
+/**\class SketchPlugin_Line
+ * \ingroup DataModel
+ * \brief Feature for creation of the new part in PartSet.
+ */
+class SketchPlugin_Line: public SketchPlugin_Feature
+{
+public:
+ /// Returns the kind of a feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+ {static std::string MY_KIND = "SketchLine"; return MY_KIND;}
+
+ /// Returns to which group in the document must be added feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
+ {static std::string MY_GROUP = "Sketch"; return MY_GROUP;}
+
+ /// Creates a new part document if needed
+ SKETCHPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Returns the sketch preview
+ SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+
+ /// Use plugin manager for features creation
+ SketchPlugin_Line();
+};
+
+#endif
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeDouble.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
using namespace std;
+/// the active sketch
+boost::shared_ptr<SketchPlugin_Sketch> MY_ACITVE_SKETCH;
+
// face of the square-face displayed for selection of general plane
const double PLANE_SIZE = 200;
void SketchPlugin_Sketch::initAttributes()
{
- data()->addAttribute(SKETCH_ATTR_PLANE_A, ModelAPI_AttributeDouble::type());
- data()->addAttribute(SKETCH_ATTR_PLANE_B, ModelAPI_AttributeDouble::type());
- data()->addAttribute(SKETCH_ATTR_PLANE_C, ModelAPI_AttributeDouble::type());
- data()->addAttribute(SKETCH_ATTR_PLANE_D, ModelAPI_AttributeDouble::type());
+ data()->addAttribute(SKETCH_ATTR_ORIGIN, GeomDataAPI_Point::type());
+ data()->addAttribute(SKETCH_ATTR_DIRX, GeomDataAPI_Dir::type());
+ data()->addAttribute(SKETCH_ATTR_DIRY, GeomDataAPI_Dir::type());
+ data()->addAttribute(SKETCH_ATTR_NORM, GeomDataAPI_Dir::type());
}
void SketchPlugin_Sketch::execute()
return getPreview();
}
+const void SketchPlugin_Sketch::addSub(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+{
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature)->setSketch(this);
+}
+
void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ,
std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const
{
GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
theShapes.push_back(aFace);
}
+
+boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
+{
+ boost::shared_ptr<GeomDataAPI_Point> aC =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SKETCH_ATTR_ORIGIN));
+ boost::shared_ptr<GeomDataAPI_Dir> aX =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRX));
+ boost::shared_ptr<GeomDataAPI_Dir> aY =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRY));
+
+ return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(
+ aC->x() + aX->x() * theX + aY->x() * theY,
+ aC->y() + aX->y() * theX + aY->y() * theY,
+ aC->z() + aX->z() * theX + aY->z() * theY));
+}
#include "SketchPlugin.h"
#include <SketchPlugin_Feature.h>
+#include <GeomAPI_Pnt.h>
#include <list>
-/// Coefficient A of the sketch plane (Ax+By+Cz+D=0)
-const std::string SKETCH_ATTR_PLANE_A("PlaneA");
-/// Coefficient B of the sketch plane
-const std::string SKETCH_ATTR_PLANE_B("PlaneB");
-/// Coefficient C of the sketch plane
-const std::string SKETCH_ATTR_PLANE_C("PlaneC");
-/// Coefficient D of the sketch plane
-const std::string SKETCH_ATTR_PLANE_D("PlaneD");
+/// Origin point of the sketcher in 3D space
+const std::string SKETCH_ATTR_ORIGIN("Origin");
+/// Vector X inside of the sketch plane
+const std::string SKETCH_ATTR_DIRX("DirX");
+/// Vector Y inside of the sketch plane
+const std::string SKETCH_ATTR_DIRY("DirY");
+/// Vector Z, normal to the sketch plane
+const std::string SKETCH_ATTR_NORM("Norm");
/**\class SketchPlugin_Sketch
* \ingroup DataModel
/// Returns the sketch preview
SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+ /// Adds sub-feature of the higher level feature (sub-element of the sketch)
+ /// \param theFeature sub-feature
+ SKETCHPLUGIN_EXPORT virtual const void addSub(
+ const boost::shared_ptr<ModelAPI_Feature>& theFeature);
+
+ /// Converts a 2D sketch space point into point in 3D space
+ SKETCHPLUGIN_EXPORT boost::shared_ptr<GeomAPI_Pnt> to3D(
+ const double theX, const double theY);
+
/// Use plugin manager for features creation
SketchPlugin_Sketch();
protected:
<plugin>
<workbench id="Sketch">
<group id="Basic">
- <feature id="Sketch" text="New sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png"/>
+ <feature id="Sketch" text="New sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+ <label text="Natasha, please provide a text for the label" tooltip="Natasha, please provide a text for the tooltip"/>
+ <!--icon=":pictures/x_point.png"-->
+ </feature>
</group>
</workbench>
</plugin>
#include <AIS_InteractiveContext.hxx>
#include <AIS_ListOfInteractive.hxx>
+#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <AIS_Shape.hxx>
Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
+ std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
+ if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
+ aDispAIS = myFeature2AISObjectMap[theFeature];
+ }
+ aDispAIS.push_back(anAIS);
+ myFeature2AISObjectMap[theFeature] = aDispAIS;
+
aContext->Display(anAIS, Standard_False);
if (isUpdateViewer)
}
void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape, const bool isUpdateViewer)
+ const bool isUpdateViewer)
{
+ if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
+ return;
+
+ std::vector<Handle(AIS_InteractiveObject)> aDispAIS = myFeature2AISObjectMap[theFeature];
+ std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIt = aDispAIS.begin(),
+ aLast = aDispAIS.end();
Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
- aContext->EraseAll();
+ for (; anIt != aLast; anIt++) {
+ Handle(AIS_InteractiveObject) anAIS = *anIt;
+ Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+ if (anAISShape.IsNull())
+ continue;
+ aContext->Erase(anAISShape);
+ }
+
if (isUpdateViewer)
aContext->UpdateCurrentViewer();
}
Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
+ std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
+ if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
+ aDispAIS = myFeature2AISObjectMap[theFeature];
+ }
+ aDispAIS.push_back(anAIS);
+ myFeature2AISObjectMap[theFeature] = aDispAIS;
aContext->Display(anAIS, Standard_False);
+
AIS_ListOfInteractive anAISList;
anAISList.Append(anAIS);
myViewer->setLocalSelection(anAISList, theMode, true);
#include <boost/shared_ptr.hpp>
#include <TopoDS_Shape.hxx>
+#include <AIS_InteractiveObject.hxx>
+
+#include <map>
+#include <vector>
class XGUI_Viewer;
class ModelAPI_Feature;
+
/**\class XGUI_Displayer
* \ingroup GUI
* \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
/// Erase the feature and a shape.
/// \param theFeature a feature instance
- /// \param theFeature a shape
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void Erase(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
- const bool isUpdateViewer = true);
+ void Erase(boost::shared_ptr<ModelAPI_Feature> theFeature, const bool isUpdateViewer = true);
/// Deactivates selection of sub-shapes
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
protected:
XGUI_Viewer* myViewer; ///< the viewer where the objects should be visualized
+ std::map<boost::shared_ptr<ModelAPI_Feature>, std::vector<Handle(AIS_InteractiveObject)> > myFeature2AISObjectMap;
};
#endif
theList.Append(myAISContext->SelectedInteractive());
}
+void XGUI_Viewer::getSelectedShapes(NCollection_List<TopoDS_Shape>& theList)
+{
+ Handle(AIS_InteractiveContext) ic = AISContext();
+
+ for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
+ TopoDS_Shape aShape = ic->SelectedShape();
+ if (!aShape.IsNull())
+ theList.Append(aShape);
+ }
+}
+
void XGUI_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
{
AIS_ListIteratorOfListOfInteractive aIt;
theButton = myButtonMap[theInteractionStyle][theOper];
}
+void XGUI_Viewer::setViewProjection(double theX, double theY, double theZ)
+{
+ XGUI_ViewWindow* aWindow = dynamic_cast<XGUI_ViewWindow*>(myActiveView->widget());
+ if (aWindow) {
+ Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
+ if ( !aView3d.IsNull() )
+ aView3d->SetProj(theX, theY, theZ);
+ aWindow->viewPort()->fitAll();
+ }
+}
+
/*!
Changes visibility of trihedron to opposite
*/
#include <V3d_Viewer.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Trihedron.hxx>
+#include <NCollection_List.hxx>
+#include <TopoDS_Shape.hxx>
class XGUI_MainWindow;
class QMdiSubWindow;
/// \param theList - list to be filled with selected objects
void getSelectedObjects(AIS_ListOfInteractive& theList);
+ /// Return shapes selected in 3D viewer
+ /// \param theList - list to be filled with selected shapes
+ void getSelectedShapes(NCollection_List<TopoDS_Shape>& theList);
+
/// Selects objects in 3D viewer. Other selected objects are left as selected
/// \param theList - list objects to be selected
void setObjectsSelected(const AIS_ListOfInteractive& theList);
static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
+ //! Sets the view projection
+ /// \param theX the X projection value
+ /// \param theY the Y projection value
+ /// \param theZ the Z projection value
+ void setViewProjection(double theX, double theY, double theZ);
+
typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
theParent->setLayout(aWidgetLay);
}
+QWidget* XGUI_WidgetFactory::labelControl(QWidget* theParent)
+{
+ QWidget* result = new QWidget(theParent);
+ QVBoxLayout* aLabelLay = new QVBoxLayout(result);
+ QLabel* aLabel = new QLabel(result);
+ aLabel->setText(qs(myWidgetApi->getProperty(INFO_WDG_TEXT)));
+ aLabel->setToolTip(qs(myWidgetApi->getProperty(INFO_WDG_TOOLTIP)));
+ aLabelLay->addWidget(aLabel);
+ aLabelLay->addStretch(1);
+ result->setLayout(aLabelLay);
+ return result;
+}
+
QWidget* XGUI_WidgetFactory::createWidgetByType(const std::string& theType, QWidget* theParent)
{
QWidget* result = NULL;
if (theType == WDG_DOUBLEVALUE) {
result = doubleSpinBoxControl();
+ } else if (theType == WDG_INFO) {
+ result = labelControl(theParent);
} else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
result = createContainer(theType, theParent);
}
protected:
//Widgets
- QWidget* doubleSpinBoxControl();
QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL);
+ QWidget* labelControl(QWidget* theParent);
+ QWidget* doubleSpinBoxControl();
QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
- bool connectWidget(QWidget*, const QString&);
+ bool connectWidget(QWidget*, const QString&);
QString qs(const std::string& theStdString) const;
private:
//******************************************************
void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
{
- hidePropertyPanel();
- updateCommandStatus();
+ ModuleBase_PropPanelOperation* aOperation =
+ (ModuleBase_PropPanelOperation*)(myOperationMgr->currentOperation());
+
+ if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
+ updateCommandStatus();
+ } else {
+ hidePropertyPanel();
+ updateCommandStatus();
if (myMainWindow) {
XGUI_MainMenu* aMenu = myMainWindow->menuObject();
aMenu->restoreCommandState();
}
+ }
}
/*