INCLUDE(FindPython)
INCLUDE(FindSalome)
INCLUDE(FindSolveSpace)
+INCLUDE(FindCAS)
IF(UNIX)
IF(CMAKE_COMPILER_IS_GNUCC)
INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Events)
SET(PROJECT_HEADERS
- Config.h
+ Config_def.h
Config_FeatureMessage.h
Config_XMLReader.h
Config_ModuleReader.h
+++ /dev/null
-#ifndef CONFIG_H
-#define CONFIG_H
-
-#if defined CONFIG_EXPORTS
-#if defined WIN32
-#define CONFIG_EXPORT __declspec( dllexport )
-#else
-#define CONFIG_EXPORT
-#endif
-#else
-#if defined WIN32
-#define CONFIG_EXPORT __declspec( dllimport )
-#else
-#define CONFIG_EXPORT
-#endif
-#endif
-
-#endif //CONFIG_H
#ifndef Config_Common_H_
#define Config_Common_H_
-#include "Config.h"
+#include "Config_def.h"
#include <string>
#include <stdarg.h>
#ifndef CONFIG_MESSAGE_H\r
#define CONFIG_MESSAGE_H\r
\r
-#include <Config.h>\r
+#include <Config_def.h>\r
#include <Events_Message.h>\r
\r
#include <string>\r
#ifndef CONFIG_FEATUREREADER_H_
#define CONFIG_FEATUREREADER_H_
-#include <Config.h>
+#include <Config_def.h>
#include <Config_XMLReader.h>
#include <string>
#ifndef CONFIG_MODULEREADER_H_
#define CONFIG_MODULEREADER_H_
-#include <Config.h>
+#include <Config_def.h>
#include <Config_XMLReader.h>
#include <map>
#ifndef PARTSET_MESSAGE_H_
#define PARTSET_MESSAGE_H_
-#include <Config.h>
+#include <Config_def.h>
#include <Events_Message.h>
/*
return myCurrentNode != NULL;
}
-std::string Config_WidgetAPI::widgetType()
+std::string Config_WidgetAPI::widgetType() const
{
std::string result = "";
if(myCurrentNode) {
return result;
}
-bool Config_WidgetAPI::isContainerWidget()
+bool Config_WidgetAPI::isContainerWidget() const
{
return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
NULL);
}
-bool Config_WidgetAPI::isPagedWidget()
+bool Config_WidgetAPI::isPagedWidget() const
{
return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
NULL);
}
-std::string Config_WidgetAPI::getProperty(const char* thePropName)
+std::string Config_WidgetAPI::getProperty(const char* thePropName) const
{
std::string result = "";
char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName);
return result;
}
-std::string Config_WidgetAPI::widgetId()
+std::string Config_WidgetAPI::widgetId() const
{
return getProperty("id");
}
-std::string Config_WidgetAPI::widgetTooltip()
+std::string Config_WidgetAPI::widgetTooltip() const
{
return getProperty("tooltip");
}
-std::string Config_WidgetAPI::widgetIcon()
+std::string Config_WidgetAPI::widgetIcon() const
{
return getProperty("icon");
}
-std::string Config_WidgetAPI::widgetLabel()
+std::string Config_WidgetAPI::widgetLabel() const
{
return getProperty("label");
}
#ifndef CONFIG_WIDGETAPI_H_
#define CONFIG_WIDGETAPI_H_
-#include <Config.h>
+#include <Config_def.h>
#include <cstdarg>
#include <string>
bool toChildWidget();
bool toParentWidget();
- std::string widgetType();
- bool isContainerWidget();
- bool isPagedWidget();
+ std::string widgetType() const;
+ bool isContainerWidget() const;
+ bool isPagedWidget() const;
- std::string widgetId();
- std::string widgetIcon();
- std::string widgetLabel();
- std::string widgetTooltip();
+ std::string widgetId() const;
+ std::string widgetIcon() const;
+ std::string widgetLabel() const;
+ std::string widgetTooltip() const;
- std::string getProperty(const char* thePropName);
+ std::string getProperty(const char* thePropName) const;
private:
xmlDocPtr myDoc;
#ifndef CONFIG_WIDGETREADER_H_
#define CONFIG_WIDGETREADER_H_
-#include <Config.h>
+#include <Config_def.h>
#include <Config_XMLReader.h>
#include <map>
#ifndef CONFIG_XMLREADER_H_
#define CONFIG_XMLREADER_H_
-#include <Config.h>
+#include <Config_def.h>
#include <cstdarg>
#include <string>
--- /dev/null
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#if defined CONFIG_EXPORTS
+#if defined WIN32
+#define CONFIG_EXPORT __declspec( dllexport )
+#else
+#define CONFIG_EXPORT
+#endif
+#else
+#if defined WIN32
+#define CONFIG_EXPORT __declspec( dllimport )
+#else
+#define CONFIG_EXPORT
+#endif
+#endif
+
+#endif //CONFIG_H
ADD_DEFINITIONS(-DCONSTRUCTIONPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
ADD_LIBRARY(ConstructionPlugin SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(ConstructionPlugin ${PROJECT_LIBRARIES} ModelAPI)
+TARGET_LINK_LIBRARIES(ConstructionPlugin ${PROJECT_LIBRARIES} ModelAPI GeomAPI GeomAlgoAPI)
INCLUDE_DIRECTORIES(
../ModelAPI
+ ../GeomAPI
+ ../GeomAlgoAPI
)
SET(XML_RESOURCES
#include "ConstructionPlugin.h"
#include <ModelAPI_Feature.h>
+/// Extrusion kind
+const std::string CONSTRUCTION_EXTRUSION_KIND("Extrusion");
+
/// attribute name of referenced face
-const std::string EXTRUSION_FACE = "extrusion_select_face";
+const std::string EXTRUSION_FACE = "extrusion_face";
/// attribute name of extrusion size
const std::string EXTRUSION_SIZE = "extrusion_size";
public:
/// Returns the kind of a feature
CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind()
- { static std::string MY_KIND = "Extrusion"; return MY_KIND; }
+ { static std::string MY_KIND = CONSTRUCTION_EXTRUSION_KIND; return MY_KIND; }
/// Returns to which group in the document must be added feature
CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getGroup()
ModelAPI_PluginManager::get()->registerPlugin(this);
}
-boost::shared_ptr<ModelAPI_Feature> ConstructionPlugin_Plugin::createFeature(string theFeatureID)
+FeaturePtr ConstructionPlugin_Plugin::createFeature(string theFeatureID)
{
- if (theFeatureID == "Point") {
- return boost::shared_ptr<ModelAPI_Feature>(new ConstructionPlugin_Point);
- } else if (theFeatureID == "Extrusion") {
- return boost::shared_ptr<ModelAPI_Feature>(new ConstructionPlugin_Extrusion);
+ if (theFeatureID == CONSTRUCTION_POINT_KIND) {
+ return FeaturePtr(new ConstructionPlugin_Point);
+ } else if (theFeatureID == CONSTRUCTION_EXTRUSION_KIND) {
+ return FeaturePtr(new ConstructionPlugin_Extrusion);
}
// feature of such kind is not found
- return boost::shared_ptr<ModelAPI_Feature>();
+ return FeaturePtr();
}
#include "ConstructionPlugin.h"
#include "ModelAPI_Plugin.h"
+#include "ModelAPI_Feature.h"
class CONSTRUCTIONPLUGIN_EXPORT ConstructionPlugin_Plugin: public ModelAPI_Plugin
{
public:
/// Creates the feature object of this plugin by the feature string ID
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+ virtual FeaturePtr createFeature(std::string theFeatureID);
public:
/// Is needed for python wrapping by swig
#include "ModelAPI_Document.h"
#include "ModelAPI_Data.h"
#include "ModelAPI_AttributeDouble.h"
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAPI_Pnt.h>
using namespace std;
data()->addAttribute(POINT_ATTR_Z, ModelAPI_AttributeDouble::type());
}
-// this is for debug only
-#include <iostream>
void ConstructionPlugin_Point::execute()
{
- // TODO: create a real shape for the point using OCC layer
- cout<<"X="<<data()->real(POINT_ATTR_X)->value()<<" Y="<<data()->real(POINT_ATTR_Y)->value()
- <<" Z="<<data()->real(POINT_ATTR_Z)->value()<<endl;
+ boost::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(
+ data()->real(POINT_ATTR_X)->value(), data()->real(POINT_ATTR_Y)->value(), data()->real(POINT_ATTR_Z)->value()));
+
+ data()->store(GeomAlgoAPI_PointBuilder::point(aPnt));
}
#include "ConstructionPlugin.h"
#include <ModelAPI_Feature.h>
+/// Point kind
+const std::string CONSTRUCTION_POINT_KIND("Point");
+
/// attribute name for X coordinate
const std::string POINT_ATTR_X = "x";
/// attribute name for Y coordinate
public:
/// Returns the kind of a feature
CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "Point"; return MY_KIND;}
+ {static std::string MY_KIND = CONSTRUCTION_POINT_KIND; return MY_KIND;}
/// Returns to which group in the document must be added feature
CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getGroup()
<source>
- <selector id="extrusion_select_face"
+ <selector id="extrusion_face"
label="Select a face"
icon=":icons/sketch.png"
tooltip="Select a face for extrusion"
+ activate="true"
/>
<doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set size of extrusion"/>
<boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
FIND_PACKAGE(SWIG REQUIRED)
-INCLUDE(FindCAS)
INCLUDE(${SWIG_USE_FILE})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
FIND_PACKAGE(SWIG REQUIRED)
-INCLUDE(FindCAS)
INCLUDE(${SWIG_USE_FILE})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
GeomAlgoAPI_CompoundBuilder.h
GeomAlgoAPI_FaceBuilder.h
GeomAlgoAPI_EdgeBuilder.h
+ GeomAlgoAPI_PointBuilder.h
GeomAlgoAPI_SketchBuilder.h
)
GeomAlgoAPI_CompoundBuilder.cpp
GeomAlgoAPI_FaceBuilder.cpp
GeomAlgoAPI_EdgeBuilder.cpp
+ GeomAlgoAPI_PointBuilder.cpp
GeomAlgoAPI_SketchBuilder.cpp
)
#include "memory"
#include "GeomAlgoAPI.h"
#include "GeomAlgoAPI_FaceBuilder.h"
+ #include "GeomAlgoAPI_EdgeBuilder.h"
+ #include "GeomAlgoAPI_PointBuilder.h"
%}
// to avoid error on this
// all supported interfaces
%include "GeomAlgoAPI_FaceBuilder.h"
+%include "GeomAlgoAPI_EdgeBuilder.h"
+%include "GeomAlgoAPI_PointBuilder.h"
--- /dev/null
+// File: GeomAlgoAPI_PointBuilder.cpp
+// Created: 02 Jun 2014
+// Author: Mikhail PONIKAROV
+
+
+
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Shape.h>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <TopoDS_Vertex.hxx>
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
+ boost::shared_ptr<GeomAPI_Pnt> thePoint)
+{
+ const gp_Pnt& aPnt = thePoint->impl<gp_Pnt>();
+ BRepBuilderAPI_MakeVertex aMaker(aPnt);
+ TopoDS_Vertex aVertex = aMaker.Vertex();
+ boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ aRes->setImpl(new TopoDS_Shape(aVertex));
+ return aRes;
+}
--- /dev/null
+// File: GeomAlgoAPI_PointBuilder.h
+// Created: 02 Jun 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomAlgoAPI_PointBuilder_HeaderFile
+#define GeomAlgoAPI_PointBuilder_HeaderFile
+
+#include <GeomAlgoAPI.h>
+#include <boost/shared_ptr.hpp>
+
+class GeomAPI_Shape;
+class GeomAPI_Pnt;
+
+/**\class GeomAlgoAPI_PointBuilder
+ * \ingroup DataAlgo
+ * \brief Allows to create face-shapes by different parameters
+ */
+
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_PointBuilder
+{
+public:
+ /// Creates linear edge by two points
+ static boost::shared_ptr<GeomAPI_Shape> point(
+ boost::shared_ptr<GeomAPI_Pnt> thePoint);
+};
+
+#endif
INCLUDE(Common)
-INCLUDE(FindCAS)
SET(PROJECT_HEADERS
GeomData.h
INCLUDE(Common)
-INCLUDE(FindCAS)
SET(PROJECT_HEADERS
Model.h
Events
Config
GeomData
+ GeomAPI
${CAS_OCAF}
+ ${CAS_TKCAF}
)
../Config
../GeomData
../GeomDataAPI
+ ../GeomAPI
${CAS_INCLUDE_DIRS}
)
void Model_AttributeBoolean::setValue(bool theValue)
{
- if (myBool->Get() != theValue) {
- myBool->Set(theValue? 1 : 0);
+ Standard_Boolean aValue = theValue ? Standard_True : Standard_False;
+ if (myBool->Get() != aValue) {
+ myBool->Set(aValue);
static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
Events_Loop::loop()->send(aMsg);
bool Model_AttributeBoolean::value()
{
- return (myBool->Get() == 1)? true : false;
+ return myBool->Get() == Standard_True;
}
Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel)
boost::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::attr()
{
- boost::shared_ptr<ModelAPI_Feature> aFeature = feature();
+ FeaturePtr aFeature = feature();
if (aFeature) {
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
return boost::shared_ptr<ModelAPI_Attribute>();
}
-void Model_AttributeRefAttr::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void Model_AttributeRefAttr::setFeature(FeaturePtr theFeature)
{
if (myID->Get().Length() != 0 || feature() != theFeature) {
boost::shared_ptr<Model_Data> aData =
}
}
-boost::shared_ptr<ModelAPI_Feature> Model_AttributeRefAttr::feature()
+FeaturePtr Model_AttributeRefAttr::feature()
{
if (myRef->Get() != myRef->Label()) { // initialized
boost::shared_ptr<Model_Document> aDoc =
}
}
// not initialized
- return boost::shared_ptr<ModelAPI_Feature>();
+ return FeaturePtr();
}
Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel)
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attr();
/// Defines the reference to the feature
- MODEL_EXPORT virtual void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ MODEL_EXPORT virtual void setFeature(FeaturePtr theFeature);
/// Returns feature referenced from this attribute
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> feature();
+ MODEL_EXPORT virtual FeaturePtr feature();
protected:
/// Objects are created for features automatically
using namespace std;
-void Model_AttributeRefList::append(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void Model_AttributeRefList::append(FeaturePtr theFeature)
{
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
Events_Loop::loop()->send(aMsg);
}
-void Model_AttributeRefList::remove(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void Model_AttributeRefList::remove(FeaturePtr theFeature)
{
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
return myRef->Extent();
}
-list<boost::shared_ptr<ModelAPI_Feature> > Model_AttributeRefList::list()
+list<FeaturePtr > Model_AttributeRefList::list()
{
- std::list< boost::shared_ptr<ModelAPI_Feature> > aResult;
+ std::list< FeaturePtr > aResult;
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
if (aDoc) {
#include "Model.h"
#include "ModelAPI_AttributeRefList.h"
+#include "ModelAPI_Feature.h"
+
#include <TDataStd_ReferenceList.hxx>
/**\class Model_AttributeRefList
Handle_TDataStd_ReferenceList myRef; ///< references to the features labels
public:
/// Appends the feature to the end of a list
- MODEL_EXPORT virtual void append(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ MODEL_EXPORT virtual void append(FeaturePtr theFeature);
/// Erases the first meet of the feature in the list
- MODEL_EXPORT virtual void remove(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ MODEL_EXPORT virtual void remove(FeaturePtr theFeature);
/// Returns number of features in the list
MODEL_EXPORT virtual int size();
/// Returns the list of features
- MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Feature> > list();
+ MODEL_EXPORT virtual std::list<FeaturePtr > list();
protected:
/// Objects are created for features automatically
using namespace std;
-void Model_AttributeReference::setValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void Model_AttributeReference::setValue(FeaturePtr theFeature)
{
if (value() != theFeature) {
boost::shared_ptr<Model_Data> aData =
if (myRef.IsNull()) {
boost::shared_ptr<Model_Data> aMyData =
boost::dynamic_pointer_cast<Model_Data>(owner()->data());
- TDF_Reference::Set(aMyData->label(), aData->label());
+ myRef = TDF_Reference::Set(aMyData->label(), aData->label());
} else {
myRef->Set(aData->label());
}
}
}
-boost::shared_ptr<ModelAPI_Feature> Model_AttributeReference::value()
+FeaturePtr Model_AttributeReference::value()
{
if (!myRef.IsNull()) {
boost::shared_ptr<Model_Document> aDoc =
}
}
// not initialized
- return boost::shared_ptr<ModelAPI_Feature>();
+ return FeaturePtr();
}
Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
#include "Model.h"
#include "ModelAPI_AttributeReference.h"
+#include <ModelAPI_Feature.h>
#include <TDF_Label.hxx>
#include <TDF_Reference.hxx>
Handle_TDF_Reference myRef; ///< references to the feature label
public:
/// Defines the feature referenced from this attribute
- MODEL_EXPORT virtual void setValue(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ MODEL_EXPORT virtual void setValue(FeaturePtr theFeature);
/// Returns feature referenced from this attribute
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> value();
+ MODEL_EXPORT virtual FeaturePtr value();
protected:
/// Objects are created for features automatically
#include <Model_AttributeReference.h>
#include <Model_AttributeRefAttr.h>
#include <Model_AttributeRefList.h>
+#include <Model_AttributeBoolean.h>
#include <GeomData_Point.h>
#include <GeomData_Point2D.h>
#include <GeomData_Dir.h>
anAttr = new GeomData_Dir(anAttrLab);
else if (theAttrType == GeomData_Point2D::type())
anAttr = new GeomData_Point2D(anAttrLab);
+ else if (theAttrType == Model_AttributeBoolean::type())
+ anAttr = new Model_AttributeBoolean(anAttrLab);
if (anAttr) {
myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
return aRes;
}
+boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string theID)
+{
+ map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ if (aFound == myAttrs.end()) {
+ // TODO: generate error on unknown attribute request and/or add mechanism for customization
+ return boost::shared_ptr<ModelAPI_AttributeBoolean>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeBoolean> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
+
boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const string theID)
{
map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
{
return !myLab.IsNull() && myLab.HasAttribute();
}
+
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
+
+void Model_Data::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
+{
+ // the simplest way is to keep this attribute here, on Data
+ // TODO: add naming structure in separated document for shape storage
+ TNaming_Builder aBuilder(myLab);
+ if (!theShape) return; // bad shape
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ if (aShape.IsNull()) return; // null shape inside
+
+ aBuilder.Generated(aShape);
+}
+
+boost::shared_ptr<GeomAPI_Shape> Model_Data::shape()
+{
+ Handle(TNaming_NamedShape) aName;
+ if (myLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
+ TopoDS_Shape aShape = aName->Get();
+ if (!aShape.IsNull()) {
+ boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ aRes->setImpl(new TopoDS_Shape(aShape));
+ return aRes;
+ }
+ }
+ return boost::shared_ptr<GeomAPI_Shape>();
+}
#include "Model.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_Feature.h>
#include <TDF_Label.hxx>
#include <map>
class ModelAPI_Attribute;
-class ModelAPI_Feature;
/**\class Model_Data
* \ingroup DataModel
std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> > myAttrs;
/// needed here to emit signal that feature changed on change of the attribute
- boost::shared_ptr<ModelAPI_Feature> myFeature;
+ FeaturePtr myFeature;
Model_Data();
/// Returns the attribute that contains list of references to features
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefList>
reflist(const std::string theID);
+ /// Returns the attribute that contains boolean value
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeBoolean>
+ boolean(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);
/// Returns true if it is correctly connected t othe data model
MODEL_EXPORT virtual bool isValid();
+ /// Stores the shape (called by the execution method).
+ MODEL_EXPORT virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape);
+ /// Returns the shape-result produced by this feature
+ MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
+
/// 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
MODEL_EXPORT void setLabel(TDF_Label& theLab);
/// Sets the feature of this data
- MODEL_EXPORT virtual void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+ MODEL_EXPORT virtual void setFeature(FeaturePtr theFeature)
{myFeature = theFeature;}
};
subDocument(*aSubIter)->redo();
}
-boost::shared_ptr<ModelAPI_Feature> Model_Document::addFeature(string theID)
+FeaturePtr Model_Document::addFeature(string theID)
{
- boost::shared_ptr<ModelAPI_Feature> aFeature =
+ FeaturePtr aFeature =
ModelAPI_PluginManager::get()->createFeature(theID);
if (aFeature) {
boost::dynamic_pointer_cast<Model_Document>(aFeature->documentToAdd())->addFeature(aFeature);
}
}
-void Model_Document::addFeature(const boost::shared_ptr<ModelAPI_Feature> theFeature)
+void Model_Document::addFeature(const FeaturePtr theFeature)
{
if (theFeature->isAction()) return; // do not add action to the data model
return aResult;
}
-void Model_Document::removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void Model_Document::removeFeature(FeaturePtr theFeature)
{
boost::shared_ptr<Model_Data> aData = boost::static_pointer_cast<Model_Data>(theFeature->data());
TDF_Label aFeatureLabel = aData->label();
int aRemovedIndex = RemoveFromRefArray(aGroupLabel, aFeatureLabel);
RemoveFromRefArray(aGroupLabel.FindChild(1), TDF_Label(), aRemovedIndex);
// remove feature from the myFeatures list
- std::vector<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = myFeatures.begin();
+ std::vector<FeaturePtr >::iterator aFIter = myFeatures.begin();
while(aFIter != myFeatures.end()) {
if (*aFIter == theFeature) {
aFIter = myFeatures.erase(aFIter);
Events_Loop::loop()->send(aMsg);
}
-boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(TDF_Label& theLabel)
+FeaturePtr Model_Document::feature(TDF_Label& theLabel)
{
// iterate all features, may be optimized later by keeping labels-map
- vector<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = myFeatures.begin();
+ vector<FeaturePtr >::iterator aFIter = myFeatures.begin();
for(; aFIter != myFeatures.end(); aFIter++) {
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>((*aFIter)->data());
if (aData->label().IsEqual(theLabel))
return *aFIter;
}
- return boost::shared_ptr<ModelAPI_Feature>(); // not found
+ return FeaturePtr(); // not found
}
boost::shared_ptr<ModelAPI_Document> Model_Document::subDocument(string theDocID)
return Model_Application::getApplication()->getDocument(theDocID);
}
-boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(
+FeaturePtr Model_Document::feature(
const string& theGroupID, const int theIndex, const bool isOperation)
{
TDF_Label aGroupLab = groupLabel(theGroupID);
if (aGroupLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
if (aRefs->Lower() <= theIndex && aRefs->Upper() >= theIndex) {
TDF_Label aFeatureLab = aRefs->Value(theIndex);
- boost::shared_ptr<ModelAPI_Feature> aFeature = feature(aFeatureLab);
+ FeaturePtr aFeature = feature(aFeatureLab);
if (theGroupID == FEATURES_GROUP || isOperation) { // just returns the feature from the history
return aFeature;
}
// not found
- return boost::shared_ptr<ModelAPI_Feature>();
+ return FeaturePtr();
}
int Model_Document::size(const string& theGroupID)
return aNew;
}
-void Model_Document::setUniqueName(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void Model_Document::setUniqueName(FeaturePtr theFeature)
{
string aName; // result
// iterate all features but also iterate group of this feature if object is not in history
}
//! Returns the object by the feature
-boost::shared_ptr<ModelAPI_Feature> Model_Document::objectByFeature(
- const boost::shared_ptr<ModelAPI_Feature> theFeature)
+FeaturePtr Model_Document::objectByFeature(
+ const FeaturePtr theFeature)
{
for(int a = 0; a < size(theFeature->getGroup()); a++) {
boost::shared_ptr<Model_Object> anObj =
return anObj;
}
}
- return boost::shared_ptr<ModelAPI_Feature>(); // not found
+ return FeaturePtr(); // not found
}
void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
{
boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
// update features
- vector<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = myFeatures.begin();
+ vector<FeaturePtr >::iterator aFIter = myFeatures.begin();
// and in parallel iterate labels of features
TDF_ChildIDIterator aFLabIter(groupLabel(FEATURES_GROUP), TDataStd_Comment::GetID());
while(aFIter != myFeatures.end() || aFLabIter.More()) {
Events_Loop::loop()->send(aMsg2);
} else if (aDSTag < aFeatureTag) { // a new feature is inserted
// create a feature
- boost::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_PluginManager::get()->createFeature(
+ FeaturePtr aFeature = ModelAPI_PluginManager::get()->createFeature(
TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
aFLabIter.Value())->Get()).ToCString());
static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
Model_FeatureUpdatedMessage aMsg1(aFeature, anEvent);
Events_Loop::loop()->send(aMsg1);
- boost::shared_ptr<ModelAPI_Feature> anObj = objectByFeature(aFeature);
+ FeaturePtr anObj = objectByFeature(aFeature);
if (anObj) {
Model_FeatureUpdatedMessage aMsg2(anObj, anEvent);
Events_Loop::loop()->send(aMsg2);
#include <Model.h>
#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
#include <TDocStd_Document.hxx>
#include <map>
//! Adds to the document the new feature of the given feature id
//! \param creates feature and puts it in the document
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
+ MODEL_EXPORT virtual FeaturePtr addFeature(std::string theID);
//! Removes the feature from the document
- MODEL_EXPORT virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature);
//! Returns the existing feature by the label
//! \param theLabel base label of the feature
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> feature(TDF_Label& theLabel);
+ MODEL_EXPORT virtual FeaturePtr feature(TDF_Label& theLabel);
//! Adds a new sub-document by the identifier, or returns existing one if it is already exist
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID);
//! \param theGroupID group that contains a feature
//! \param theIndex zero-based index of feature in the group
//! \param isOperation if it is true, returns feature (not Object)
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
+ MODEL_EXPORT virtual FeaturePtr
feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false);
//! Returns the number of features in the group
//! Initializes feature with a unique name in this group (unique name is generated as
//! feature type + "_" + index
- void setUniqueName(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ void setUniqueName(FeaturePtr theFeature);
//! Adds to the document the new feature
- void addFeature(const boost::shared_ptr<ModelAPI_Feature> theFeature);
+ void addFeature(const FeaturePtr theFeature);
//! Returns the object by the feature
- boost::shared_ptr<ModelAPI_Feature> objectByFeature(
- const boost::shared_ptr<ModelAPI_Feature> theFeature);
+ FeaturePtr objectByFeature(
+ const FeaturePtr theFeature);
//! Synchronizes myFeatures list with the updated document
void synchronizeFeatures(const bool theMarkUpdated = false);
/// number of nested transactions performed (or -1 if not nested)
int myNestedNum;
/// All features managed by this document (not only in history of OB)
- std::vector<boost::shared_ptr<ModelAPI_Feature> > myFeatures;
+ std::vector<FeaturePtr > myFeatures;
///< set of identifiers of sub-documents of this document
std::set<std::string> mySubs;
#include <string>
#include <set>
-class ModelAPI_Feature;
+#include "ModelAPI_Feature.h"
+
class ModelAPI_Document;
/// Event ID that feature is created (comes with Model_FeatureUpdatedMessage)
/// Message that feature was changed (used for Object Browser update): moved, updated and deleted
class Model_FeatureUpdatedMessage : public Events_MessageGroup {
- std::set<boost::shared_ptr<ModelAPI_Feature> > myFeatures; ///< which feature is changed
+ std::set<FeaturePtr > myFeatures; ///< which feature is changed
public:
/// sender is not important, all information is located in the feature
Model_FeatureUpdatedMessage(
- const boost::shared_ptr<ModelAPI_Feature>& theFeature,
+ const FeaturePtr& theFeature,
const Events_ID& theEvent) : Events_MessageGroup(theEvent, 0)
{if (theFeature) myFeatures.insert(theFeature);}
/// Returns the feature that has been updated
- std::set<boost::shared_ptr<ModelAPI_Feature> > features() const {return myFeatures;}
+ std::set<FeaturePtr > features() const {return myFeatures;}
//! Creates a new empty group (to store it in the loop before flush)
virtual Events_MessageGroup* newEmpty() {
- boost::shared_ptr<ModelAPI_Feature> anEmptyFeature;
+ FeaturePtr anEmptyFeature;
return new Model_FeatureUpdatedMessage(anEmptyFeature, eventID());
}
//! Allows to join the given message with the current one
virtual void Join(Events_MessageGroup& theJoined) {
Model_FeatureUpdatedMessage* aJoined = dynamic_cast<Model_FeatureUpdatedMessage*>(&theJoined);
- std::set<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = aJoined->myFeatures.begin();
+ std::set<FeaturePtr >::iterator aFIter = aJoined->myFeatures.begin();
for(; aFIter != aJoined->myFeatures.end(); aFIter++) {
myFeatures.insert(*aFIter);
}
#include "Model_Events.h"
#include <Events_Loop.h>
-boost::shared_ptr<ModelAPI_Feature> Model_Object::featureRef()
+FeaturePtr Model_Object::featureRef()
{
return myRef;
}
}
}
-Model_Object::Model_Object(boost::shared_ptr<ModelAPI_Feature> theRef,
+Model_Object::Model_Object(FeaturePtr theRef,
Handle_TDataStd_Name theName)
: myRef(theRef), myName(theName)
{
*/
class Model_Object : public ModelAPI_Object
{
- boost::shared_ptr<ModelAPI_Feature> myRef; ///< the referenced feature
+ FeaturePtr myRef; ///< the referenced feature
Handle_TDataStd_Name myName; ///< the name of this object that may be changed
public:
/// Reference to the feature-operation that produces this object
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> featureRef();
+ MODEL_EXPORT virtual FeaturePtr featureRef();
/// Returns the name of this object (by default equal to the name of feature)
MODEL_EXPORT virtual std::string getName();
{return myRef->document();}
/// Returns true if feature refers to the same model data instance
- MODEL_EXPORT virtual bool isSame(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+ MODEL_EXPORT virtual bool isSame(const FeaturePtr& theFeature)
{
boost::shared_ptr<Model_Object> anObj = boost::dynamic_pointer_cast<Model_Object>(theFeature);
return anObj && myRef == anObj->myRef;
private:
/// Constructor fully defines this object
- Model_Object(boost::shared_ptr<ModelAPI_Feature> theRef, Handle_TDataStd_Name theName);
+ Model_Object(FeaturePtr theRef, Handle_TDataStd_Name theName);
friend class Model_Document;
};
static Model_PluginManager* myImpl = new Model_PluginManager();
-boost::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
+FeaturePtr Model_PluginManager::createFeature(string theFeatureID)
{
if (this != myImpl) return myImpl->createFeature(theFeatureID);
Config_ModuleReader::loadLibrary(myCurrentPluginName);
}
if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
- boost::shared_ptr<ModelAPI_Feature> aCreated =
+ FeaturePtr aCreated =
myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
if (!aCreated) {
Events_Error::send(string("Can not initialize feature '") + theFeatureID +
}
}
- return boost::shared_ptr<ModelAPI_Feature>(); // return nothing
+ return FeaturePtr(); // return nothing
}
boost::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
#include "Model.h"
#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Feature.h>
+
#include <Events_Listener.h>
#include <map>
void LoadPluginsInfo();
/// Creates the feature object using plugins functionality
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+ virtual FeaturePtr createFeature(std::string theFeatureID);
};
#endif
#define ModelAPI_AttributeRefAttr_HeaderFile
#include "ModelAPI_Attribute.h"
+#include "ModelAPI_Feature.h"
/**\class ModelAPI_AttributeRefAttr
* \ingroup DataModel
MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attr() = 0;
/// Defines the reference to the feature
- MODELAPI_EXPORT virtual void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+ MODELAPI_EXPORT virtual void setFeature(FeaturePtr theFeature) = 0;
/// Returns feature referenced from this attribute
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> feature() = 0;
+ MODELAPI_EXPORT virtual FeaturePtr feature() = 0;
/// Returns the type of this class of attributes
MODELAPI_EXPORT static std::string type() {return "RefAttr";}
#define ModelAPI_AttributeRefList_HeaderFile
#include "ModelAPI_Attribute.h"
+#include "ModelAPI_Feature.h"
#include <list>
/**\class ModelAPI_AttributeRefList
MODELAPI_EXPORT virtual std::string attributeType() {return type();}
/// Appends the feature to the end of a list
- MODELAPI_EXPORT virtual void append(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+ MODELAPI_EXPORT virtual void append(FeaturePtr theFeature) = 0;
/// Erases the first meet of the feature in the list
- MODELAPI_EXPORT virtual void remove(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+ MODELAPI_EXPORT virtual void remove(FeaturePtr theFeature) = 0;
/// Returns number of features in the list
MODELAPI_EXPORT virtual int size() = 0;
/// Returns the list of features
- MODELAPI_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Feature> > list() = 0;
+ MODELAPI_EXPORT virtual std::list<FeaturePtr > list() = 0;
protected:
/// Objects are created for features automatically
#define ModelAPI_AttributeReference_HeaderFile
#include "ModelAPI_Attribute.h"
+#include <ModelAPI_Feature.h>
/**\class ModelAPI_AttributeReference
* \ingroup DataModel
{
public:
/// Defines the feature referenced from this attribute
- MODELAPI_EXPORT virtual void setValue(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+ MODELAPI_EXPORT virtual void setValue(FeaturePtr theFeature) = 0;
/// Returns feature referenced from this attribute
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> value() = 0;
+ MODELAPI_EXPORT virtual FeaturePtr value() = 0;
/// Returns the type of this class of attributes
MODELAPI_EXPORT static std::string type() {return "Reference";}
class ModelAPI_AttributeReference;
class ModelAPI_AttributeRefAttr;
class ModelAPI_AttributeRefList;
+class ModelAPI_AttributeBoolean;
class ModelAPI_Document;
class ModelAPI_Attribute;
+class GeomAPI_Shape;
/**\class ModelAPI_Data
* \ingroup DataModel
virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string theID) = 0;
/// Returns the attribute that contains list of references to features
virtual boost::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string theID) = 0;
+ /// Returns the attribute that contains boolean value
+ virtual boost::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string theID) = 0;
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
/// Returns true if it is correctly connected t othe data model
virtual bool isValid() = 0;
+ /// Stores the shape (called by the execution method).
+ virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+ /// Returns the shape-result produced by this feature
+ virtual boost::shared_ptr<GeomAPI_Shape> shape() = 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
/// Returns true if feature refers to the same model data instance
MODELAPI_EXPORT virtual bool isSame(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
- {return true;}
+ {return theFeature.get() == this;}
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Feature() {}
MODELAPI_EXPORT virtual bool isInHistory() {return false;}
/// Reference to the feature-operation that produces this object
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> featureRef() = 0;
+ MODELAPI_EXPORT virtual FeaturePtr featureRef() = 0;
/// Returns the name of this object (by default equal to the name of feature)
MODELAPI_EXPORT virtual std::string getName() = 0;
ModuleBase_WidgetPoint2D.h
ModuleBase_WidgetSwitch.h
ModuleBase_MetaWidget.h
+ ModuleBase_SelectorWidget.h
+ ModuleBase_IWorkshop.h
+ ModuleBase_Widgets.h
)
SET(PROJECT_SOURCES
ModuleBase_WidgetPoint2D.cpp
ModuleBase_WidgetSwitch.cpp
ModuleBase_MetaWidget.cpp
+ ModuleBase_SelectorWidget.cpp
+ ModuleBase_Widgets.cpp
)
SET(PROJECT_LIBRARIES
Config
ModelAPI
${QT_LIBRARIES}
+ ${CAS_VIEWER}
+ ${CAS_KERNEL}
)
SET(PROJECT_AUTOMOC
#SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES})
INCLUDE_DIRECTORIES(
- ${PROJECT_SOURCE_DIR}/src/Config
+ ${CAS_INCLUDE_DIRS}
+ ${CMAKE_SOURCE_DIR}/src/Config
${CMAKE_SOURCE_DIR}/src/Events
${CMAKE_SOURCE_DIR}/src/Model
${CMAKE_SOURCE_DIR}/src/ModelAPI
${CMAKE_SOURCE_DIR}/src/GeomDataAPI
)
-ADD_DEFINITIONS(-DMODULEBASE_EXPORTS)
+ADD_DEFINITIONS(-DMODULEBASE_EXPORTS ${CAS_DEFINITIONS})
ADD_LIBRARY(ModuleBase SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
TARGET_LINK_LIBRARIES(ModuleBase ${PROJECT_LIBRARIES})
--- /dev/null
+// File: ModuleBase_IWorkshop.h
+// Created: 2 June 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ModuleBase_IWorkshop_H
+#define ModuleBase_IWorkshop_H
+
+#include "ModuleBase.h"
+
+#include <ModelAPI_Feature.h>
+
+#include <AIS_InteractiveContext.hxx>
+
+#include <QObject>
+
+/**
+* Class which provides access to Workshop object serveces
+*/
+class MODULEBASE_EXPORT ModuleBase_IWorkshop: public QObject
+{
+Q_OBJECT
+public:
+ ModuleBase_IWorkshop(QObject* theParent):QObject(theParent) {}
+
+ virtual ~ModuleBase_IWorkshop() {};
+
+ //! Returns AIS_InteractiveContext from current OCCViewer
+ virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
+
+ //! Returns list of currently selected data objects
+ virtual QList<FeaturePtr> selectedFeatures() const = 0;
+
+signals:
+ void selectionChanged();
+};
+
+#endif
\ No newline at end of file
}
-bool ModuleBase_MetaWidget::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
+bool ModuleBase_MetaWidget::storeValue(FeaturePtr theFeature)
{
#ifdef _DEBUG
std::cout << "ModuleBase_MetaWidget::storeValue"
return true;
}
-bool ModuleBase_MetaWidget::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
+bool ModuleBase_MetaWidget::restoreValue(FeaturePtr theFeature)
{
#ifdef _DEBUG
std::cout << "ModuleBase_MetaWidget::restoreValue"
MODULEBASE_EXPORT ModuleBase_MetaWidget(QWidget* theWrapped);
virtual ~ModuleBase_MetaWidget();
//! Interface for saving widget's data into the data model
- MODULEBASE_EXPORT virtual bool storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ MODULEBASE_EXPORT virtual bool storeValue(FeaturePtr theFeature);
//! Interface for loading widget's data from the data model
- MODULEBASE_EXPORT virtual bool restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ MODULEBASE_EXPORT virtual bool restoreValue(FeaturePtr theFeature);
/// Set focus to the current widget if it corresponds to the given attribute
/// \param theAttribute name
#include <ModuleBase.h>
+#include <ModelAPI_Feature.h>
+
#include <QObject>
#include <boost/shared_ptr.hpp>
/// Saves the internal parameters to the given feature
/// \param theFeature a model feature to be changed
- virtual bool storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+ virtual bool storeValue(FeaturePtr theFeature) const = 0;
- virtual bool restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+ virtual bool restoreValue(FeaturePtr theFeature) = 0;
/// Returns whether the widget can accept focus, or if it corresponds to the given attribute
/// \param theAttribute name
- virtual bool canFocusTo(const std::string& theAttributeName) = 0;
+ virtual bool canFocusTo(const std::string& theAttributeName) const { return false; }
/// Set focus to the current widget if it corresponds to the given attribute
- virtual void focusTo() = 0;
+ virtual void focusTo() {}
/// Returns list of widget controls
/// \return a control list
#endif
ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
-: ModuleBase_IOperation(theId, theParent)
+: ModuleBase_IOperation(theId, theParent), myIsEditing(false)
{
}
return getDescription()->operationId();
}
-boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
+FeaturePtr ModuleBase_Operation::feature() const
{
return myFeature;
}
void ModuleBase_Operation::startOperation()
{
- setFeature(createFeature());
+ if (!myIsEditing)
+ setFeature(createFeature());
//emit callSlot();
//commit();
}
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
}
-boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::createFeature(const bool theFlushMessage)
+FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
{
boost::shared_ptr<ModelAPI_Document> aDoc = document();
- boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature(
+ FeaturePtr aFeature = aDoc->addFeature(
getDescription()->operationId().toStdString());
if (aFeature) // TODO: generate an error if feature was not created
aFeature->execute();
return aFeature;
}
-void ModuleBase_Operation::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
{
myFeature = theFeature;
}
+
+void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature)
+{
+ myFeature = theFeature;
+ myIsEditing = true;
+}
#include <ModuleBase.h>
#include <ModuleBase_IOperation.h>
+#include "ModelAPI_Feature.h"
+
#include <QObject>
#include <QString>
#include <boost/shared_ptr.hpp>
-class ModelAPI_Feature;
class ModelAPI_Document;
class QKeyEvent;
QString id() const;
/// Returns the operation feature
/// \return the feature
- boost::shared_ptr<ModelAPI_Feature> feature() const;
+ FeaturePtr feature() const;
/// Returns whether the nested operations are enabled.
/// The state can depend on the operation current state.
virtual void keyReleased(std::string theName, QKeyEvent* theEvent) {};
+ /// Sets the operation feature
+ void setEditingFeature(FeaturePtr theFeature);
+
+ bool isEditOperation() const { return myIsEditing; }
+
protected:
/// Virtual method called when operation started (see start() method for more description)
/// Default impl calls corresponding slot and commits immediately.
/// Creates an operation new feature
/// \param theFlushMessage the flag whether the create message should be flushed
/// \returns the created feature
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true);
- /// Returns the operation feature
- /// \return the feature
- void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ /// Sets the operation feature
+ void setFeature(FeaturePtr theFeature);
private:
- boost::shared_ptr<ModelAPI_Feature> myFeature; /// the operation feature to be handled
+ FeaturePtr myFeature; /// the operation feature to be handled
+
+ bool myIsEditing;
};
#endif
--- /dev/null
+// File: ModuleBase_SelectorWidget.h
+// Created: 2 June 2014
+// Author: Vitaly Smetannikov
+
+
+#include "ModuleBase_SelectorWidget.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeReference.h>
+#include <Config_WidgetAPI.h>
+
+#include <QWidget>
+#include <QLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QToolButton>
+#include <QString>
+#include <QEvent>
+#include <QDockWidget>
+
+
+ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop), myActivateOnStart(false)
+{
+ myFeatureAttributeID = theData->widgetId();
+
+ myContainer = new QWidget(theParent);
+ QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
+
+ aLayout->setContentsMargins(0, 0, 0, 0);
+ QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+ myLabel = new QLabel(aLabelText, myContainer);
+ myLabel->setPixmap(QPixmap(aLabelIcon));
+
+ aLayout->addWidget(myLabel);
+
+ QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+ myTextLine = new QLineEdit(myContainer);
+ myTextLine->setReadOnly(true);
+ myTextLine->setToolTip(aToolTip);
+ myTextLine->installEventFilter(this);
+
+ aLayout->addWidget(myTextLine);
+
+ myActivateBtn = new QToolButton(myContainer);
+ myActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
+ myActivateBtn->setCheckable(true);
+ myActivateBtn->setToolTip(tr("Activate/Deactivate selection"));
+ connect(myActivateBtn, SIGNAL(toggled(bool)), this, SLOT(activateSelection(bool)));
+
+ aLayout->addWidget(myActivateBtn);
+
+ QString aActivateTxt = QString::fromStdString(theData->getProperty("activate"));
+ if (!aActivateTxt.isNull()) {
+ myActivateOnStart = (aActivateTxt == "true");
+ }
+}
+
+//********************************************************************
+ModuleBase_SelectorWidget::~ModuleBase_SelectorWidget()
+{
+}
+
+//********************************************************************
+bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature) const
+{
+ DataPtr aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
+
+ FeaturePtr aFeature = aRef->value();
+ if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
+ aRef->setValue(mySelectedFeature);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ }
+ return true;
+}
+
+//********************************************************************
+bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
+{
+ DataPtr aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(myFeatureAttributeID);
+
+ bool isBlocked = this->blockSignals(true);
+ mySelectedFeature = aRef->value();
+ updateSelectionName();
+
+ this->blockSignals(isBlocked);
+ return true;
+}
+
+//********************************************************************
+QList<QWidget*> ModuleBase_SelectorWidget::getControls() const
+{
+ QList<QWidget*> aControls;
+ aControls.append(myLabel);
+ aControls.append(myTextLine);
+ aControls.append(myActivateBtn);
+ return aControls;
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::onSelectionChanged()
+{
+ QList<FeaturePtr> aFeatures = myWorkshop->selectedFeatures();
+ if (aFeatures.size() > 0) {
+ FeaturePtr aFeature = aFeatures.first();
+ if ((!mySelectedFeature) && (!aFeature))
+ return;
+ if (mySelectedFeature && aFeature && mySelectedFeature->isSame(aFeature))
+ return;
+
+ // TODO: Check that the selection corresponds to selection type
+ // TODO: Use the feature kind definition like SKETCH_KIND instead of the direct text
+ if (aFeature->getKind().compare("Sketch") != 0)
+ return;
+
+ mySelectedFeature = aFeature;
+ if (mySelectedFeature) {
+ updateSelectionName();
+ activateSelection(false);
+ raisePanel();
+ } else {
+ myTextLine->setText("");
+ }
+ emit valuesChanged();
+ }
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::updateSelectionName()
+{
+ if (mySelectedFeature) {
+ std::string aName;
+ if (mySelectedFeature->data())
+ aName = mySelectedFeature->data()->getName();
+ else
+ aName = boost::dynamic_pointer_cast<ModelAPI_Object>(mySelectedFeature)->getName();
+
+ myTextLine->setText(QString::fromStdString(aName));
+ } else
+ myTextLine->setText("");
+}
+
+//********************************************************************
+bool ModuleBase_SelectorWidget::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+ if (theObj == myTextLine) {
+ if (theEvent->type() == QEvent::Polish) {
+ activateSelection(myActivateOnStart);
+ onSelectionChanged();
+ }
+ }
+ return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::enableOthersControls(bool toEnable) const
+{
+ QWidget* aParent = myContainer->parentWidget();
+ QList<QWidget*> aChldList = aParent->findChildren<QWidget*>();
+ foreach(QWidget* aWgt, aChldList) {
+ if ((aWgt != myLabel) && (aWgt != myActivateBtn) && (aWgt != myTextLine) && (aWgt != myContainer))
+ aWgt->setEnabled(toEnable);
+ }
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::activateSelection(bool toActivate)
+{
+ enableOthersControls(!toActivate);
+ myTextLine->setEnabled(toActivate);
+
+ if (toActivate)
+ connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ else
+ disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+
+ myActivateBtn->setDown(toActivate);
+}
+
+//********************************************************************
+void ModuleBase_SelectorWidget::raisePanel() const
+{
+ QWidget* aParent = myContainer->parentWidget();
+ QWidget* aLastPanel = 0;
+ while (!aParent->inherits("QDockWidget")) {
+ aLastPanel = aParent;
+ aParent = aParent->parentWidget();
+ if (!aParent) return;
+ }
+ if (aParent->inherits("QDockWidget")) {
+ QDockWidget* aTabWgt = (QDockWidget*) aParent;
+ aTabWgt->raise();
+ }
+}
\ No newline at end of file
--- /dev/null
+// File: ModuleBase_SelectorWidget.h
+// Created: 2 June 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ModuleBase_SelectorWidget_H
+#define ModuleBase_SelectorWidget_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+#include <ModelAPI_Feature.h>
+
+
+class Config_WidgetAPI;
+class QWidget;
+class QLabel;
+class QLineEdit;
+class QToolButton;
+class ModuleBase_IWorkshop;
+
+class MODULEBASE_EXPORT ModuleBase_SelectorWidget: public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+public:
+ ModuleBase_SelectorWidget(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData);
+
+ virtual ~ModuleBase_SelectorWidget();
+
+ /// Saves the internal parameters to the given feature
+ /// \param theFeature a model feature to be changed
+ virtual bool storeValue(FeaturePtr theFeature) const;
+
+ virtual bool restoreValue(FeaturePtr theFeature);
+
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ QWidget* getControl() const { return myContainer; }
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+ void setActivationOnStart(bool toActivate) { myActivateOnStart = toActivate; }
+ bool activateOnStart() const { return myActivateOnStart; }
+
+ FeaturePtr selectedFeature() const { return mySelectedFeature; }
+
+public slots:
+
+ /// Activate or deactivate selection
+ void activateSelection(bool toActivate);
+
+protected:
+ bool eventFilter(QObject* theObj, QEvent* theEvent);
+
+private slots:
+ void onSelectionChanged();
+
+private:
+ void enableOthersControls(bool toEnable) const;
+ void updateSelectionName();
+ void raisePanel() const;
+
+ std::string myFeatureAttributeID;
+
+ QWidget* myContainer;
+ QLabel* myLabel;
+ QLineEdit* myTextLine;
+ QToolButton* myActivateBtn;
+
+ ModuleBase_IWorkshop* myWorkshop;
+
+ bool myActivateOnStart;
+
+ FeaturePtr mySelectedFeature;
+};
+
+#endif
\ No newline at end of file
#include <ModuleBase_WidgetFactory.h>
-#include <ModuleBase_MetaWidget.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
#include <ModuleBase_WidgetSwitch.h>
+#include <ModuleBase_SelectorWidget.h>
+#include <ModuleBase_Widgets.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
#include <QPixmap>
#include <QGroupBox>
#include <QToolBox>
-#include <QLineEdit>
-#include <QToolButton>
-#include <QCheckBox>
#ifdef _DEBUG
#include <QDebug>
#include <cfloat>
#include <climits>
-ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(ModuleBase_Operation* theOperation)
- : myOperation(theOperation)
+ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(ModuleBase_Operation* theOperation, ModuleBase_IWorkshop* theWorkshop)
+ : myOperation(theOperation), myWorkshop(theWorkshop)
{
QString aXml = myOperation->getDescription()->xmlRepresentation();
myWidgetApi = new Config_WidgetAPI(aXml.toStdString());
{
QWidget* result = NULL;
if (theType == WDG_DOUBLEVALUE) {
- result = doubleSpinBoxControl();
+ result = doubleSpinBoxControl(theParent);
} else if (theType == WDG_INFO) {
result = labelControl(theParent);
return result;
}
-QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl()
+QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent)
{
- QWidget* result = new QWidget();
- QHBoxLayout* aControlLay = new QHBoxLayout(result);
- aControlLay->setContentsMargins(0, 0, 0, 0);
- QString aLabelText = qs(myWidgetApi->widgetLabel());
- QString aLabelIcon = qs(myWidgetApi->widgetIcon());
- QLabel* aLabel = new QLabel(aLabelText);
- aLabel->setPixmap(QPixmap(aLabelIcon));
+ ModuleBase_DoubleValueWidget* aDblWgt = new ModuleBase_DoubleValueWidget(theParent, myWidgetApi);
+ QObject::connect(aDblWgt, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue()));
- aControlLay->addWidget(aLabel);
- QDoubleSpinBox* aBox = new QDoubleSpinBox(result);
- QString anObjName = QString::fromStdString(myWidgetApi->widgetId());
- aBox->setObjectName(anObjName);
- bool isOk = false;
- std::string aProp = myWidgetApi->getProperty(DOUBLE_WDG_MIN);
- double aMinVal = qs(aProp).toDouble(&isOk);
- if (isOk) {
- aBox->setMinimum(aMinVal);
- } else {
- aBox->setMinimum(-DBL_MAX);
- }
- aProp = myWidgetApi->getProperty(DOUBLE_WDG_MAX);
- double aMaxVal = qs(aProp).toDouble(&isOk);
- if (isOk) {
- aBox->setMaximum(aMaxVal);
- } else {
- aBox->setMaximum(DBL_MAX);
- }
- aProp = myWidgetApi->getProperty(DOUBLE_WDG_STEP);
- double aStepVal = qs(aProp).toDouble(&isOk);
- if (isOk) {
- aBox->setSingleStep(aStepVal);
- }
- aProp = myWidgetApi->getProperty(DOUBLE_WDG_DFLT);
- double aDefVal = qs(aProp).toDouble(&isOk);
- if (isOk) {
- aBox->setValue(aDefVal);
- }
- QString aTTip = qs(myWidgetApi->widgetTooltip());
- aBox->setToolTip(aTTip);
- aControlLay->addWidget(aBox);
- aControlLay->setStretch(1, 1);
- result->setLayout(aControlLay);
- connectWidget(aBox, WDG_DOUBLEVALUE);
- return result;
+ myModelWidgets.append(aDblWgt);
+
+ // Init default values
+ if (!myOperation->isEditOperation())
+ aDblWgt->storeValue(myOperation->feature());
+ return aDblWgt->getControl();
}
QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent)
QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent)
{
- QWidget* aRes = new QWidget();
- QHBoxLayout* aLayout = new QHBoxLayout(aRes);
-
- aLayout->setContentsMargins(0, 0, 0, 0);
- QString aLabelText = qs(myWidgetApi->widgetLabel());
- QString aLabelIcon = qs(myWidgetApi->widgetIcon());
- QLabel* aLabel = new QLabel(aLabelText, aRes);
- aLabel->setPixmap(QPixmap(aLabelIcon));
+ ModuleBase_SelectorWidget* aSelector = new ModuleBase_SelectorWidget(theParent, myWorkshop, myWidgetApi);
+
+ QObject::connect(aSelector, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue()));
- aLayout->addWidget(aLabel);
-
- QLineEdit* aTextLine = new QLineEdit(aRes);
- aTextLine->setReadOnly(true);
-
- aLayout->addWidget(aTextLine);
-
- QToolButton* aActivateBtn = new QToolButton(aRes);
- aActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
- aActivateBtn->setCheckable(true);
-
- aLayout->addWidget(aActivateBtn);
-
- return aRes;
+ myModelWidgets.append(aSelector);
+ return aSelector->getControl();
}
QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent)
{
- QString aText = qs(myWidgetApi->widgetLabel());
- QString aToolTip = qs(myWidgetApi->widgetTooltip());
- QString aDefault = qs(myWidgetApi->getProperty("default"));
+ ModuleBase_BoolValueWidget* aBoolWgt = new ModuleBase_BoolValueWidget(theParent, myWidgetApi);
+ QObject::connect(aBoolWgt, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue()));
+
+ myModelWidgets.append(aBoolWgt);
- QCheckBox* aRes = new QCheckBox(aText, theParent);
- aRes->setToolTip(aToolTip);
- aRes->setChecked(aDefault == "true");
- return aRes;
+ // Init default values
+ if (!myOperation->isEditOperation())
+ aBoolWgt->storeValue(myOperation->feature());
+ return aBoolWgt->getControl();
}
\ No newline at end of file
#ifndef ModuleBase_WidgetFactory_H_
#define ModuleBase_WidgetFactory_H_
-#include <ModuleBase.h>
-#include <ModuleBase_ModelWidget.h>
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
#include <QString>
#include <QList>
class QWidget;
class Config_WidgetAPI;
class ModuleBase_Operation;
+class ModuleBase_IWorkshop;
class MODULEBASE_EXPORT ModuleBase_WidgetFactory
{
public:
- ModuleBase_WidgetFactory(ModuleBase_Operation*);
+ ModuleBase_WidgetFactory(ModuleBase_Operation* theOperation, ModuleBase_IWorkshop* theWorkshop);
virtual ~ModuleBase_WidgetFactory();
void createWidget(QWidget* theParent);
//Widgets
QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL);
QWidget* labelControl(QWidget* theParent);
- QWidget* doubleSpinBoxControl();
+ QWidget* doubleSpinBoxControl(QWidget* theParent);
QWidget* pointSelectorControl(QWidget* theParent);
QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
QWidget* selectorControl(QWidget* theParent);
private:
Config_WidgetAPI* myWidgetApi;
ModuleBase_Operation* myOperation;
+ ModuleBase_IWorkshop* myWorkshop;
QList<ModuleBase_ModelWidget*> myModelWidgets;
};
{
}
-bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
+bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const
{
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
- bool isBlocked = this->blockSignals(true);
+ ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
+ bool isBlocked = that->blockSignals(true);
aPoint->setValue(myXSpin->value(), myYSpin->value());
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ that->blockSignals(isBlocked);
- this->blockSignals(isBlocked);
return true;
}
-bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
+bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature)
{
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
/// Saves the internal parameters to the given feature
/// \param theFeature a model feature to be changed
- virtual bool storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ virtual bool storeValue(FeaturePtr theFeature) const;
- virtual bool restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ virtual bool restoreValue(FeaturePtr theFeature);
/// Returns whether the widget can accept focus, or if it corresponds to the given attribute
/// \param theAttribute name
--- /dev/null
+// File: ModuleBase_Widgets.h
+// Created: 04 June 2014
+// Author: Vitaly Smetannikov
+
+#include "ModuleBase_Widgets.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_Data.h>
+
+#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#include <QWidget>
+#include <QLayout>
+#include <QLabel>
+#include <QDoubleSpinBox>
+#include <QCheckBox>
+
+
+ModuleBase_DoubleValueWidget::ModuleBase_DoubleValueWidget(QWidget* theParent, const Config_WidgetAPI* theData)
+ : ModuleBase_ModelWidget(theParent)
+{
+ myContainer = new QWidget(theParent);
+ QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
+ aControlLay->setContentsMargins(0, 0, 0, 0);
+
+ QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+ myLabel = new QLabel(aLabelText, myContainer);
+ myLabel->setPixmap(QPixmap(aLabelIcon));
+ aControlLay->addWidget(myLabel);
+
+ myAttributeID = theData->widgetId();
+ mySpinBox = new QDoubleSpinBox(myContainer);
+ QString anObjName = QString::fromStdString(myAttributeID);
+ mySpinBox->setObjectName(anObjName);
+
+ bool isOk = false;
+ std::string aProp = theData->getProperty(DOUBLE_WDG_MIN);
+ double aMinVal = QString::fromStdString(aProp).toDouble(&isOk);
+ if (isOk) {
+ mySpinBox->setMinimum(aMinVal);
+ } else {
+ mySpinBox->setMinimum(-DBL_MAX);
+ }
+
+ aProp = theData->getProperty(DOUBLE_WDG_MAX);
+ double aMaxVal = QString::fromStdString(aProp).toDouble(&isOk);
+ if (isOk) {
+ mySpinBox->setMaximum(aMaxVal);
+ } else {
+ mySpinBox->setMaximum(DBL_MAX);
+ }
+
+ aProp = theData->getProperty(DOUBLE_WDG_STEP);
+ double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
+ if (isOk) {
+ mySpinBox->setSingleStep(aStepVal);
+ }
+
+ aProp = theData->getProperty(DOUBLE_WDG_DFLT);
+ double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
+ if (isOk) {
+ mySpinBox->setValue(aDefVal);
+ }
+
+ QString aTTip = QString::fromStdString(theData->widgetTooltip());
+ mySpinBox->setToolTip(aTTip);
+
+ aControlLay->addWidget(mySpinBox);
+ aControlLay->setStretch(1, 1);
+
+ connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
+}
+
+ModuleBase_DoubleValueWidget::~ModuleBase_DoubleValueWidget()
+{
+}
+
+bool ModuleBase_DoubleValueWidget::storeValue(FeaturePtr theFeature) const
+{
+ DataPtr aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(myAttributeID);
+ if (aReal->value() != mySpinBox->value()) {
+ aReal->setValue(mySpinBox->value());
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ }
+ return true;
+}
+
+bool ModuleBase_DoubleValueWidget::restoreValue(FeaturePtr theFeature)
+{
+ DataPtr aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeDouble> aRef = aData->real(myAttributeID);
+
+ bool isBlocked = mySpinBox->blockSignals(true);
+ mySpinBox->setValue(aRef->value());
+ mySpinBox->blockSignals(isBlocked);
+
+ return true;
+}
+
+QList<QWidget*> ModuleBase_DoubleValueWidget::getControls() const
+{
+ QList<QWidget*> aList;
+ aList.append(myLabel);
+ aList.append(mySpinBox);
+ return aList;
+}
+
+
+//////////////////////////////////////////////////////////////////////////////////
+ModuleBase_BoolValueWidget::ModuleBase_BoolValueWidget(QWidget* theParent, const Config_WidgetAPI* theData)
+ : ModuleBase_ModelWidget(theParent)
+{
+ myAttributeID = theData->widgetId();
+ QString aText = QString::fromStdString(theData->widgetLabel());
+ QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+ QString aDefault = QString::fromStdString(theData->getProperty("default"));
+
+ myCheckBox = new QCheckBox(aText, theParent);
+ myCheckBox->setToolTip(aToolTip);
+ myCheckBox->setChecked(aDefault == "true");
+
+ connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
+}
+
+ModuleBase_BoolValueWidget::~ModuleBase_BoolValueWidget()
+{
+}
+
+QWidget* ModuleBase_BoolValueWidget::getControl() const
+{
+ return myCheckBox;
+}
+
+bool ModuleBase_BoolValueWidget::storeValue(FeaturePtr theFeature) const
+{
+ DataPtr aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(myAttributeID);
+
+ if (aBool->value() != myCheckBox->isChecked()) {
+ aBool->setValue(myCheckBox->isChecked());
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ }
+ return true;
+}
+
+bool ModuleBase_BoolValueWidget::restoreValue(FeaturePtr theFeature)
+{
+ DataPtr aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(myAttributeID);
+
+ bool isBlocked = myCheckBox->blockSignals(true);
+ myCheckBox->setChecked(aRef->value());
+ myCheckBox->blockSignals(isBlocked);
+
+ return true;
+}
+
+QList<QWidget*> ModuleBase_BoolValueWidget::getControls() const
+{
+ QList<QWidget*> aList;
+ aList.append(myCheckBox);
+ return aList;
+}
--- /dev/null
+// File: ModuleBase_Widgets.h
+// Created: 04 June 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ModuleBase_Widgets_H
+#define ModuleBase_Widgets_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+class Config_WidgetAPI;
+class QWidget;
+class QLabel;
+class QDoubleSpinBox;
+class QCheckBox;
+
+class MODULEBASE_EXPORT ModuleBase_DoubleValueWidget: public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+public:
+ ModuleBase_DoubleValueWidget(QWidget* theParent, const Config_WidgetAPI* theData);
+
+ virtual ~ModuleBase_DoubleValueWidget();
+
+ /// Saves the internal parameters to the given feature
+ /// \param theFeature a model feature to be changed
+ virtual bool storeValue(FeaturePtr theFeature) const;
+
+ virtual bool restoreValue(FeaturePtr theFeature);
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ QWidget* getControl() const { return myContainer; }
+
+private:
+ std::string myAttributeID;
+
+ QWidget* myContainer;
+ QLabel* myLabel;
+ QDoubleSpinBox* mySpinBox;
+};
+
+
+//////////////////////////////////////////////////////////////////////////////////
+
+class MODULEBASE_EXPORT ModuleBase_BoolValueWidget: public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+public:
+ ModuleBase_BoolValueWidget(QWidget* theParent, const Config_WidgetAPI* theData);
+
+ virtual ~ModuleBase_BoolValueWidget();
+
+ /// Saves the internal parameters to the given feature
+ /// \param theFeature a model feature to be changed
+ virtual bool storeValue(FeaturePtr theFeature) const;
+
+ virtual bool restoreValue(FeaturePtr theFeature);
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ QWidget* getControl() const;
+
+private:
+ std::string myAttributeID;
+
+ QCheckBox* myCheckBox;
+};
+
+#endif
\ No newline at end of file
-INCLUDE(FindCAS)
-
SET(CMAKE_AUTOMOC ON)
SET(PROJECT_HEADERS
INCLUDE(Common)
-INCLUDE(FindCAS)
SET(CMAKE_AUTOMOC ON)
SET(PROJECT_HEADERS
PartSet.h
+ PartSet_Constants.h
+ PartSet_FeaturePrs.h
PartSet_Listener.h
PartSet_Module.h
+ PartSet_OperationConstraint.h
+ PartSet_OperationCreateFeature.h
PartSet_OperationEditLine.h
PartSet_OperationSketchBase.h
PartSet_OperationSketch.h
- PartSet_OperationSketchLine.h
+ PartSet_Presentation.h
PartSet_TestOCC.h
PartSet_Tools.h
)
SET(PROJECT_SOURCES
+ PartSet_FeaturePrs.cpp
PartSet_Listener.cpp
PartSet_Module.cpp
+ PartSet_OperationConstraint.cpp
+ PartSet_OperationCreateFeature.cpp
PartSet_OperationEditLine.cpp
PartSet_OperationSketchBase.cpp
PartSet_OperationSketch.cpp
- PartSet_OperationSketchLine.cpp
+ PartSet_Presentation.cpp
PartSet_TestOCC.cpp
PartSet_Tools.cpp
)
--- /dev/null
+// File: PartSet_Tools.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_Constants_H
+#define PartSet_Constants_H
+
+#include <ModelAPI_Feature.h>
+
+/// This file contains various constants used in the PartSet module
+
+/// Types of viewer selection in an operation
+enum PartSet_SelectionMode
+{
+ SM_FirstPoint,
+ SM_SecondPoint,
+ SM_DonePoint
+};
+
+
+#endif
--- /dev/null
+// File: PartSet_FeaturePrs.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_FeaturePrs.h>
+
+#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+
+#include <Precision.hxx>
+
+using namespace std;
+
+PartSet_FeaturePrs::PartSet_FeaturePrs(FeaturePtr theFeature)
+: mySketch(theFeature)
+{
+}
+
+PartSet_FeaturePrs::~PartSet_FeaturePrs()
+{
+}
+
+void PartSet_FeaturePrs::init(FeaturePtr theFeature, FeaturePtr theSourceFeature)
+{
+ myFeature = theFeature;
+ if (theSourceFeature)
+ {
+ // use the last point of the previous feature as the first of the new one
+ boost::shared_ptr<ModelAPI_Data> aData = theSourceFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> anInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(LINE_ATTR_END));
+ setLinePoint(theFeature, anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START);
+ setLinePoint(theFeature, anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END);
+
+ aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(LINE_ATTR_START));
+ createConstraint(anInitPoint, aPoint);
+ }
+}
+
+boost::shared_ptr<ModelAPI_Document> PartSet_FeaturePrs::document() const
+{
+ return ModelAPI_PluginManager::get()->rootDocument();
+}
+
+FeaturePtr PartSet_FeaturePrs::sketch() const
+{
+ return mySketch;
+}
+
+PartSet_SelectionMode PartSet_FeaturePrs::setPoint(double theX, double theY,
+ const PartSet_SelectionMode& theMode)
+{
+ PartSet_SelectionMode aMode = theMode;
+ switch (theMode)
+ {
+ case SM_FirstPoint: {
+ setLinePoint(feature(), theX, theY, LINE_ATTR_START);
+ setLinePoint(feature(), theX, theY, LINE_ATTR_END);
+ aMode = SM_SecondPoint;
+ }
+ break;
+ case SM_SecondPoint: {
+ setLinePoint(feature(), theX, theY, LINE_ATTR_END);
+ aMode = SM_DonePoint;
+ }
+ break;
+ default:
+ break;
+ }
+ return aMode;
+}
+
+FeaturePtr PartSet_FeaturePrs::feature() const
+{
+ return myFeature;
+}
+
+void PartSet_FeaturePrs::createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
+ boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
+{
+ boost::shared_ptr<ModelAPI_Document> aDoc = document();
+ FeaturePtr aFeature = aDoc->addFeature(SKETCH_CONSTRAINT_COINCIDENCE_KIND);
+
+ if (sketch()) {
+ boost::shared_ptr<SketchPlugin_Feature> aSketch =
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
+ aSketch->addSub(aFeature);
+ }
+
+ boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ aRef1->setAttr(thePoint1);
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+ aRef2->setAttr(thePoint2);
+
+ if (aFeature) // TODO: generate an error if feature was not created
+ aFeature->execute();
+}
+
+void PartSet_FeaturePrs::setConstraints(double theX, double theY,
+ const PartSet_SelectionMode& theMode)
+{
+ std::string aPointArg;
+ switch (theMode)
+ {
+ case SM_FirstPoint:
+ aPointArg = LINE_ATTR_START;
+ break;
+ case SM_SecondPoint:
+ aPointArg = LINE_ATTR_END;
+ break;
+ default:
+ break;
+ }
+
+ FeaturePtr aSkFeature = feature();
+
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(aPointArg));
+ aData = sketch()->data();
+ boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
+
+ std::list<FeaturePtr > aFeatures = aRefList->list();
+ std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(),
+ aLast = aFeatures.end();
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aFeature = *anIt;
+ boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = findLinePoint(aFeature, theX, theY);
+ if (aFPoint)
+ createConstraint(aFPoint, aPoint);
+ }
+}
+
+std::string PartSet_FeaturePrs::getAttribute(const PartSet_SelectionMode& theMode) const
+{
+ std::string aAttribute;
+ switch (theMode)
+ {
+ case SM_FirstPoint:
+ aAttribute = LINE_ATTR_START;
+ break;
+ case SM_SecondPoint:
+ aAttribute = LINE_ATTR_END;
+ break;
+ default:
+ break;
+ }
+ return aAttribute;
+}
+
+PartSet_SelectionMode PartSet_FeaturePrs::getNextMode(const std::string& theAttribute) const
+{
+ PartSet_SelectionMode aMode;
+
+ if (theAttribute == LINE_ATTR_START)
+ aMode = SM_SecondPoint;
+ else if (theAttribute == LINE_ATTR_END)
+ aMode = SM_DonePoint;
+ return aMode;
+}
+
+void PartSet_FeaturePrs::getLinePoint(FeaturePtr theFeature,
+ const std::string& theAttribute,
+ double& theX, double& theY)
+{
+ if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ return;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+ theX = aPoint->x();
+ theY = aPoint->y();
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePrs::findLinePoint(
+ FeaturePtr theFeature,
+ double theX, double theY)
+{
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
+ if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ return aPoint2D;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+ aPoint2D = aPoint;
+ else {
+ aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+ aPoint2D = aPoint;
+ }
+ return aPoint2D;
+}
+
+void PartSet_FeaturePrs::setLinePoint(FeaturePtr theFeature,
+ double theX, double theY,
+ const std::string& theAttribute)
+{
+ if (!theFeature)
+ return;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+ aPoint->setValue(theX, theY);
+}
--- /dev/null
+// File: PartSet_FeaturePrs.h
+// Created: 04 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_FeaturePrs_H
+#define PartSet_FeaturePrs_H
+
+#include "PartSet.h"
+
+#include "PartSet_Constants.h"
+
+class GeomDataAPI_Point2D;
+
+/*!
+ \class PartSet_FeaturePrs
+ * \brief The abstract class to define the specific feature manipulation. It is created for
+ * the feature create operation to move out the feature properties set and use one operation
+ * for any type of features.
+*/
+class PARTSET_EXPORT PartSet_FeaturePrs
+{
+public:
+ /// Constructor
+ /// \param theSketch the sketch feature
+ PartSet_FeaturePrs(FeaturePtr theSketch);
+ /// Destructor
+ virtual ~PartSet_FeaturePrs();
+
+ /// Initializes some fields of feature accorging to the source feature
+ /// Saves the fiature as the presentation internal feature
+ /// \param theFeature the presentation feature
+ /// \param theSourceFeature the feature, which attributes are used to initialize the feature
+ virtual void init(FeaturePtr theFeature, FeaturePtr theSourceFeature);
+
+ /// Returns the operation sketch feature
+ /// \returns the sketch instance
+ FeaturePtr sketch() const;
+
+ /// Sets the point to the feature in an attribute depending on the selection mode
+ /// \param theX the 2D point horizontal coordinate
+ /// \param theY the 2D point vertical coordinate
+ /// \param theMode the selection mode
+ /// \return the new selection mode
+ PartSet_SelectionMode setPoint(double theX, double theY, const PartSet_SelectionMode& theMode);
+
+ /// Creates constrains of the current
+ /// \param theX the horizontal coordnate of the point
+ /// \param theY the vertical coordnate of the point
+ /// \param theMode the current operation selection mode. The feature attribute depends on the mode
+ void setConstraints(double theX, double theY, const PartSet_SelectionMode& theMode);
+
+ /// Returns the feature attribute name for the selection mode
+ /// \param theMode the current operation selection mode. The feature attribute depends on the mode
+ std::string getAttribute(const PartSet_SelectionMode& theMode) const;
+
+ /// Returns the next selection mode after the attribute
+ /// \param theAttribute the feature attribute name
+ /// \return next attribute selection mode
+ PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+
+ /// \brief Save the point to the line.
+ /// \param theFeature the line feature
+ /// \param theX the horizontal coordinate
+ /// \param theY the vertical coordinate
+ /// \param theAttribute the start or end attribute of the line
+ static void setLinePoint(FeaturePtr, double theX, double theY,
+ const std::string& theAttribute);
+
+protected:
+ /// Returns pointer to the root document.
+ boost::shared_ptr<ModelAPI_Document> document() const;
+
+ /// Returns the operation feature
+ /// \return the feature
+ FeaturePtr feature() const;
+
+ /// Creates a constraint on two points
+ /// \param thePoint1 the first point
+ /// \param thePoint1 the second point
+ void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
+ boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
+
+ /// \brief Get the line point 2d coordinates.
+ /// \param theFeature the line feature
+ /// \param theAttribute the start or end attribute of the line
+ /// \param theX the horizontal coordinate
+ /// \param theY the vertical coordinate
+ void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
+ double& theX, double& theY);
+ /// Find a point in the line with given coordinates
+ /// \param theFeature the line feature
+ /// \param theX the horizontal point coordinate
+ /// \param theY the vertical point coordinate
+ boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(FeaturePtr theFeature,
+ double theX, double theY);
+
+private:
+ FeaturePtr mySketch; ///< the sketch of the feature
+ FeaturePtr myFeature; ///< the feature
+};
+
+#endif
#include <Events_Loop.h>
#include <Model_Events.h>
+#include <SketchPlugin_Sketch.h>
+
#ifdef _DEBUG
#include <QDebug>
#endif
{
const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>
(theMessage);
- std::set<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aUpdMsg->features();
- std::set<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
- aLast = aFeatures.end();
+ std::set<FeaturePtr > aFeatures = aUpdMsg->features();
+ std::set<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
for (; anIt != aLast; anIt++) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = *anIt;
- if (myModule->workshop()->displayer()->IsVisible(aFeature) ||
+ FeaturePtr aFeature = *anIt;
+ if (myModule->workshop()->displayer()->isVisible(aFeature) ||
aType == EVENT_FEATURE_CREATED) {
myModule->visualizePreview(aFeature, true, false);
//if (aType == EVENT_FEATURE_CREATED)
myModule->activateFeature(aFeature, true);
}
}
- myModule->workshop()->displayer()->UpdateViewer();
+ myModule->workshop()->displayer()->updateViewer();
}
if (aType == EVENT_FEATURE_DELETED)
{
std::set<std::string>::const_iterator anIt = aGroups.begin(), aLast = aGroups.end();
for (; anIt != aLast; anIt++) {
std::string aGroup = *anIt;
- if (aGroup.compare("Sketch") == 0) { // Update only Sketch group
- myModule->workshop()->displayer()->EraseDeletedFeatures();
+ if (aGroup.compare(SKETCH_KIND) == 0) { // Update only Sketch group
+ myModule->workshop()->displayer()->eraseDeletedFeatures();
myModule->updateCurrentPreview(aGroup);
}
}
#include <PartSet_Module.h>
#include <PartSet_OperationSketch.h>
-#include <PartSet_OperationSketchLine.h>
+#include <PartSet_OperationCreateFeature.h>
#include <PartSet_OperationEditLine.h>
+#include <PartSet_OperationConstraint.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
#include <PartSet_Listener.h>
#include <PartSet_TestOCC.h>
+#include <PartSet_Presentation.h>
#include <ModuleBase_Operation.h>
#include <ModelAPI_Object.h>
#include <GeomAPI_Shape.h>
#include <AIS_ListOfInteractive.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
#include <QObject>
#include <QMouseEvent>
if (aPreviewOp)
{
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
- std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+ std::list<XGUI_ViewerPrs> aSelected = aDisplayer->getSelected();
+ std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted();
aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
}
if (aPreviewOp)
{
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
- std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+ std::list<XGUI_ViewerPrs> aSelected = aDisplayer->getSelected();
+ std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted();
aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
}
myWorkshop->viewer()->fitAll();
}
-void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<ModelAPI_Feature> theFeature)
+void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeature)
{
ModuleBase_Operation* anOperation = createOperation(theName.c_str());
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
{
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
// refill the features list with avoiding of the features, obtained only by vertex shape (TODO)
- std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected(TopAbs_VERTEX);
- std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted(TopAbs_VERTEX);
+ std::list<XGUI_ViewerPrs> aSelected = aDisplayer->getSelected(TopAbs_VERTEX);
+ std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted(TopAbs_VERTEX);
aPreviewOp->init(theFeature, aSelected, aHighlighted);
+ } else {
+ anOperation->setEditingFeature(theFeature);
}
sendOperation(anOperation);
myWorkshop->actionsMgr()->updateCheckState();
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
if (!isStop) {
std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
- boost::shared_ptr<ModelAPI_Feature> aFeature;
+ FeaturePtr aFeature;
for (; anIt != aLast; anIt++) {
activateFeature((*anIt).feature(), false);
}
}
- aDisplayer->StopSelection(theFeatures, isStop, false);
+ aDisplayer->stopSelection(theFeatures, isStop, false);
XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
aViewer->enableSelection(!isStop);
- aDisplayer->UpdateViewer();
+ aDisplayer->updateViewer();
}
void PartSet_Module::onSetSelection(const std::list<XGUI_ViewerPrs>& theFeatures)
{
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- aDisplayer->SetSelected(theFeatures, false);
- aDisplayer->UpdateViewer();
+ aDisplayer->setSelected(theFeatures, false);
+ aDisplayer->updateViewer();
}
void PartSet_Module::onCloseLocalContext()
{
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- aDisplayer->CloseLocalContexts();
+ aDisplayer->closeLocalContexts();
}
-void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
- int theMode)
+void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode)
{
bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
visualizePreview(theFeature, isDisplay, false);
if (!isDisplay) {
ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
- boost::shared_ptr<ModelAPI_Feature> aSketch;
+ FeaturePtr aSketch;
PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
if (aPrevOp) {
- std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
- aList = aPrevOp->subPreview();
+ std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> > aList = aPrevOp->subPreview();
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
- std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
+ std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
anIt = aList.begin(), aLast = aList.end();
for (; anIt != aLast; anIt++) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
+ FeaturePtr aFeature = (*anIt).first;
visualizePreview(aFeature, false, false);
}
- aDisplayer->UpdateViewer();
+ aDisplayer->updateViewer();
}
}
// get operation xml description
std::string aStdCmdId = theCmdId;
if (aStdCmdId == PartSet_OperationEditLine::Type())
- aStdCmdId = PartSet_OperationSketchLine::Type();
+ aStdCmdId = SKETCH_LINE_KIND;
std::string aPluginFileName = featureFile(aStdCmdId);
Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
aWdgReader.readAll();
std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
// create the operation
- ModuleBase_Operation* anOperation;
+ ModuleBase_Operation* anOperation = 0;
if (theCmdId == PartSet_OperationSketch::Type()) {
anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
}
- else if(theCmdId == PartSet_OperationSketchLine::Type() ||
- theCmdId == PartSet_OperationEditLine::Type()) {
+ else {
ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
- boost::shared_ptr<ModelAPI_Feature> aSketch;
+ FeaturePtr aSketch;
PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
if (aPrevOp)
aSketch = aPrevOp->sketch();
- if (theCmdId == PartSet_OperationSketchLine::Type())
- anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
- else
+ if (theCmdId == SKETCH_LINE_KIND)
+ anOperation = new PartSet_OperationCreateFeature(theCmdId.c_str(), this, aSketch);
+ else if (theCmdId == PartSet_OperationEditLine::Type())
anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
+ else if (theCmdId == PartSet_OperationConstraint::Type())
+ anOperation = new PartSet_OperationConstraint(theCmdId.c_str(), this, aSketch);
}
- else {
+
+ if (!anOperation) {
anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
}
anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
// connect the operation
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp) {
- connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)),
- this, SLOT(onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)));
- connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)),
- this, SLOT(onLaunchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)));
+ connect(aPreviewOp, SIGNAL(featureConstructed(FeaturePtr, int)),
+ this, SLOT(onFeatureConstructed(FeaturePtr, int)));
+ connect(aPreviewOp, SIGNAL(launchOperation(std::string, FeaturePtr)),
+ this, SLOT(onLaunchOperation(std::string, FeaturePtr)));
connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
this, SLOT(onMultiSelectionEnabled(bool)));
Events_Loop::loop()->send(aMessage);
}
-void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
const bool isUpdateViewer)
{
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
if (isDisplay) {
boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
- aDisplayer->Redisplay(theFeature,
- aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ theFeature, aPreviewOp->sketch(),
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+ aDisplayer->getAISObject(theFeature));
+
+ int aSelectionMode = -1;
+ if (theFeature->getKind() == SKETCH_CONSTRAINT_LENGTH_KIND) {
+ aSelectionMode = AIS_DSM_Text;
+ }
+ aDisplayer->redisplay(theFeature, anAIS, aSelectionMode, false);
}
else
- aDisplayer->Erase(theFeature, false);
+ aDisplayer->erase(theFeature, false);
if (isUpdateViewer)
- aDisplayer->UpdateViewer();
+ aDisplayer->updateViewer();
}
-void PartSet_Module::activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const bool isUpdateViewer)
+void PartSet_Module::activateFeature(FeaturePtr theFeature, const bool isUpdateViewer)
{
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp) {
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- aDisplayer->ActivateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
+ aDisplayer->activateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
isUpdateViewer);
}
}
if (!aPreviewOp)
return;
- boost::shared_ptr<ModelAPI_Feature> aFeature = aPreviewOp->feature();
+ FeaturePtr aFeature = aPreviewOp->feature();
if (!aFeature || aFeature->getKind() != theCmdId)
return;
- std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
- aList = aPreviewOp->subPreview();
+ std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> > aList = aPreviewOp->subPreview();
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
- std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
+ std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
anIt = aList.begin(), aLast = aList.end();
for (; anIt != aLast; anIt++) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
+ FeaturePtr aFeature = (*anIt).first;
boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
- aDisplayer->Redisplay(aFeature,
- aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
- aDisplayer->ActivateInLocalContext(aFeature, aModes, false);
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ aFeature, aPreviewOp->sketch(),
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+ aDisplayer->getAISObject(aFeature));
+ if (!anAIS.IsNull())
+ aDisplayer->redisplay(aFeature, anAIS, -1, false);
+ aDisplayer->activateInLocalContext(aFeature, aModes, false);
}
- aDisplayer->UpdateViewer();
+ aDisplayer->updateViewer();
}
void PartSet_Module::editFeature(FeaturePtr theFeature)
if (!theFeature)
return;
- if (theFeature->getKind() == "Sketch") {
+// if (theFeature->getKind() == SKETCH_KIND) {
FeaturePtr aFeature = theFeature;
if (XGUI_Tools::isModelObject(aFeature)) {
ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
onLaunchOperation(aFeature->getKind(), aFeature);
updateCurrentPreview(aFeature->getKind());
}
- }
+// }
}
/// \param theFeature the feature instance to be displayed
/// \param isDisplay the state whether the presentation should be displayed or erased
/// \param isUpdateViewer the flag whether the viewer should be updated
- void visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+ void visualizePreview(FeaturePtr theFeature, bool isDisplay,
const bool isUpdateViewer = true);
/// Activates the feature in the displayer
/// \param theFeature the feature instance to be displayed
/// \param isUpdateViewer the flag whether the viewer should be updated
- void activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ void activateFeature(FeaturePtr theFeature,
const bool isUpdateViewer);
/// Updates current operation preview, if it has it.
/// SLOT, to fit all current viewer
void onFitAllView();
- void onLaunchOperation(std::string theName, boost::shared_ptr<ModelAPI_Feature> theFeature);
+ void onLaunchOperation(std::string theName, FeaturePtr theFeature);
/// SLOT, to switch on/off the multi selection in the viewer
/// \param theEnabled the enabled state
/// SLOT, to visualize the feature in another local context mode
/// \param theFeature the feature to be put in another local context mode
/// \param theMode the mode appeared on the feature
- void onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ void onFeatureConstructed(FeaturePtr theFeature,
int theMode);
protected:
/// Creates a new operation
--- /dev/null
+// File: PartSet_OperationConstraint.h
+// Created: 20 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_OperationConstraint.h>
+
+#include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
+
+#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModuleBase_OperationDescription.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <SketchPlugin_Constraint.h>
+
+#include <Geom_Line.hxx>
+#include <gp_Lin.hxx>
+
+#include <XGUI_ViewerPrs.h>
+#include <XGUI_Constants.h>
+
+#include <SketchPlugin_Line.h>
+
+#include <V3d_View.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+#include <QMouseEvent>
+
+using namespace std;
+
+PartSet_OperationConstraint::PartSet_OperationConstraint(const QString& theId,
+ QObject* theParent,
+ FeaturePtr theFeature)
+: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
+{
+}
+
+PartSet_OperationConstraint::~PartSet_OperationConstraint()
+{
+}
+
+bool PartSet_OperationConstraint::isGranted(ModuleBase_IOperation* theOperation) const
+{
+ return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
+}
+
+void PartSet_OperationConstraint::init(FeaturePtr theFeature,
+ const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+{
+ //if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ // return;
+ // use the last point of the previous feature as the first of the new one
+ //boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ //myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+}
+
+FeaturePtr PartSet_OperationConstraint::sketch() const
+{
+ return mySketch;
+}
+
+void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+{
+ /*if (myPointSelectionMode == SM_DonePoint)
+ {
+ // if the point creation is finished, the next mouse release should commit the modification
+ // the next release can happens by double click in the viewer
+ commit();
+ restartOperation(PartSet_OperationConstraint::Type(), feature());
+ return;
+ }
+
+ double aX, anY;
+
+ bool isFoundPoint = false;
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+*/
+ if (theSelected.empty()) {
+ //PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ //isFoundPoint = true;
+ }
+ else {
+ XGUI_ViewerPrs aPrs = theSelected.front();
+ FeaturePtr aFeature = aPrs.feature();
+
+ setFeature(aFeature);
+ setValue(120);
+ flushUpdated();
+
+ /*const TopoDS_Shape& aShape = aPrs.shape();
+ if (!aShape.IsNull()) // the point is selected
+ {
+ if (aShape.ShapeType() == TopAbs_VERTEX) {
+ const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
+ if (!aVertex.IsNull()) {
+ aPoint = BRep_Tool::Pnt(aVertex);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ isFoundPoint = true;
+
+ setConstraints(aX, anY);
+ }
+ }
+ else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
+ {
+ FeaturePtr aFeature = aPrs.feature();
+ if (aFeature) {
+ double X0, X1, X2, X3;
+ double Y0, Y1, Y2, Y3;
+ getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
+ getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1);
+
+ switch (myPointSelectionMode) {
+ case SM_FirstPoint:
+ PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
+ break;
+ case SM_SecondPoint: {
+ getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+ PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
+ }
+ break;
+ default:
+ break;
+ }
+ isFoundPoint = true;
+ }
+ }
+ }*/
+ }
+
+ /*switch (myPointSelectionMode)
+ {
+ case SM_FirstPoint: {
+ setLinePoint(feature(), aX, anY, LINE_ATTR_START);
+ setLinePoint(feature(), aX, anY, LINE_ATTR_END);
+ flushUpdated();
+
+ //setPointSelectionMode(SM_SecondPoint);
+ }
+ break;
+ case SM_SecondPoint: {
+ setLinePoint(feature(), aX, anY, LINE_ATTR_END);
+ flushUpdated();
+
+ //setPointSelectionMode(SM_DonePoint);
+ }
+ break;
+ default:
+ break;
+ }*/
+}
+
+void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+{
+/* switch (myPointSelectionMode)
+ {
+ case SM_FirstPoint: {
+ double aX, anY;
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ setLinePoint(feature(), aX, anY, LINE_ATTR_START);
+ setLinePoint(feature(), aX, anY, LINE_ATTR_END);
+ flushUpdated();
+ emit focusActivated(LINE_ATTR_START);
+ }
+ break;
+ case SM_SecondPoint:
+ {
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ setLinePoint(aPoint, theView, LINE_ATTR_END);
+ flushUpdated();
+ emit focusActivated(LINE_ATTR_END);
+ }
+ break;
+ case SM_DonePoint:
+ {
+ commit();
+ restartOperation(PartSet_OperationConstraint::Type(), feature());
+ }
+ default:
+ break;
+ }*/
+}
+
+void PartSet_OperationConstraint::startOperation()
+{
+ PartSet_OperationSketchBase::startOperation();
+ //setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint);
+
+ emit multiSelectionEnabled(false);
+}
+
+void PartSet_OperationConstraint::abortOperation()
+{
+ emit featureConstructed(feature(), FM_Hide);
+ PartSet_OperationSketchBase::abortOperation();
+}
+
+void PartSet_OperationConstraint::stopOperation()
+{
+ PartSet_OperationSketchBase::stopOperation();
+ emit multiSelectionEnabled(true);
+}
+
+void PartSet_OperationConstraint::afterCommitOperation()
+{
+ PartSet_OperationSketchBase::afterCommitOperation();
+ emit featureConstructed(feature(), FM_Deactivation);
+}
+
+FeaturePtr PartSet_OperationConstraint::createFeature(const bool theFlushMessage)
+{
+ FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
+ if (sketch()) {
+ boost::shared_ptr<SketchPlugin_Feature> aFeature =
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
+
+ aFeature->addSub(aNewFeature);
+ }
+ /*if (myInitPoint) {
+ setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START);
+ setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END);
+
+ boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(LINE_ATTR_START));
+ createConstraint(myInitPoint, aPoint);
+ }*/
+
+ emit featureConstructed(aNewFeature, FM_Activation);
+ if (theFlushMessage)
+ flushCreated();
+ return aNewFeature;
+}
+
+void PartSet_OperationConstraint::setFeature(FeaturePtr theFeature)
+{
+ if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ return;
+
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ anAttr->setFeature(theFeature);
+}
+
+void PartSet_OperationConstraint::setValue(const double theValue)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+
+ boost::shared_ptr<ModelAPI_AttributeDouble> anAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ anAttr->setValue(theValue);
+
+}
--- /dev/null
+// File: PartSet_OperationConstraint.h
+// Created: 20 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_OperationConstraint_H
+#define PartSet_OperationConstraint_H
+
+#include "PartSet.h"
+
+#include <PartSet_OperationSketchBase.h>
+
+#include <SketchPlugin_ConstraintLength.h>
+
+#include <QObject>
+
+/*!
+ \class PartSet_OperationConstraint
+ * \brief The operation for the sketch constraint feature creation
+*/
+class PARTSET_EXPORT PartSet_OperationConstraint : public PartSet_OperationSketchBase
+{
+ Q_OBJECT
+
+public:
+ /// Returns the operation type key
+ static std::string Type() { return SKETCH_CONSTRAINT_LENGTH_KIND; }
+
+public:
+ /// Constructor
+ /// \param theId the feature identifier
+ /// \param theParent the operation parent
+ /// \param theFeature the parent feature
+ PartSet_OperationConstraint(const QString& theId, QObject* theParent,
+ FeaturePtr theSketchFeature);
+ /// Destructor
+ virtual ~PartSet_OperationConstraint();
+
+ /// Returns that this operator can be started above already running one.
+ /// The runned operation should be the sketch feature modified operation
+ /// \param theOperation the previous running operation
+ virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
+
+ /// Initializes some fields accorging to the feature
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void init(FeaturePtr theFeature,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
+
+ /// Returns the operation sketch feature
+ /// \returns the sketch instance
+ virtual FeaturePtr sketch() const;
+
+ /// Gives the current selected objects to be processed by the operation
+ /// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
+ /// Gives the current mouse point in the viewer
+ /// \param thePoint a point clicked in the viewer
+ /// \param theEvent the mouse event
+ virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+
+protected:
+ /// \brief Virtual method called when operation is started
+ /// Virtual method called when operation started (see start() method for more description)
+ /// After the parent operation body perform, set sketch feature to the created line feature
+ virtual void startOperation();
+
+ /// Virtual method called when operation aborted (see abort() method for more description)
+ /// Before the feature is aborted, it should be hidden from the viewer
+ virtual void abortOperation();
+
+ /// Virtual method called when operation stopped - committed or aborted.
+ /// Restore the multi selection state
+ virtual void stopOperation();
+
+ /// Virtual method called after operation committed (see commit() method for more description)
+ virtual void afterCommitOperation();
+
+ /// Creates an operation new feature
+ /// In addition to the default realization it appends the created line feature to
+ /// the sketch feature
+ /// \param theFlushMessage the flag whether the create message should be flushed
+ /// \returns the created feature
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+
+ /// Set the feature for the constraint
+ /// \param theFeature the line feature
+ void setFeature(FeaturePtr theFeature);
+
+ /// Set the value for the constraint
+ /// \param theValue the constraint value
+ void setValue(const double theValue);
+
+private:
+ FeaturePtr mySketch; ///< the sketch feature
+};
+
+#endif
--- /dev/null
+// File: PartSet_OperationCreateFeature.h
+// Created: 20 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_OperationCreateFeature.h>
+
+#include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
+#include <PartSet_FeaturePrs.h>
+
+#include <SketchPlugin_Feature.h>
+
+#include <ModuleBase_OperationDescription.h>
+
+#include <XGUI_ViewerPrs.h>
+#include <XGUI_Constants.h>
+
+#include <V3d_View.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+#include <QMouseEvent>
+
+using namespace std;
+
+PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& theId,
+ QObject* theParent,
+ FeaturePtr theFeature)
+: PartSet_OperationSketchBase(theId, theParent),
+ myPointSelectionMode(SM_FirstPoint)
+{
+ myFeaturePrs = new PartSet_FeaturePrs(theFeature);
+}
+
+PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
+{
+ delete myFeaturePrs;
+}
+
+bool PartSet_OperationCreateFeature::canBeCommitted() const
+{
+ return myPointSelectionMode == SM_DonePoint;
+}
+
+bool PartSet_OperationCreateFeature::isGranted(ModuleBase_IOperation* theOperation) const
+{
+ return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
+}
+
+std::list<int> PartSet_OperationCreateFeature::getSelectionModes(FeaturePtr theFeature) const
+{
+ std::list<int> aModes;
+ if (theFeature != feature())
+ aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
+ return aModes;
+}
+
+void PartSet_OperationCreateFeature::init(FeaturePtr theFeature,
+ const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+{
+ if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ return;
+ myInitFeature = theFeature;
+}
+
+FeaturePtr PartSet_OperationCreateFeature::sketch() const
+{
+ return myFeaturePrs->sketch();
+}
+
+void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+{
+ if (myPointSelectionMode == SM_DonePoint)
+ {
+ // if the point creation is finished, the next mouse release should commit the modification
+ // the next release can happens by double click in the viewer
+ commit();
+ restartOperation(feature()->getKind(), feature());
+ return;
+ }
+
+ double aX, anY;
+
+ bool isFoundPoint = false;
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ if (theSelected.empty()) {
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ isFoundPoint = true;
+ }
+ else {
+ XGUI_ViewerPrs aPrs = theSelected.front();
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (!aShape.IsNull()) // the point is selected
+ {
+ if (aShape.ShapeType() == TopAbs_VERTEX) {
+ const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
+ if (!aVertex.IsNull()) {
+ aPoint = BRep_Tool::Pnt(aVertex);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ isFoundPoint = true;
+
+ myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode);
+ }
+ }
+ /*else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
+ {
+ FeaturePtr aFeature = aPrs.feature();
+ if (aFeature) {
+ double X0, X1, X2, X3;
+ double Y0, Y1, Y2, Y3;
+ getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
+ getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1);
+
+ switch (myPointSelectionMode) {
+ case SM_FirstPoint:
+ PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
+ break;
+ case SM_SecondPoint: {
+ getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+ PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
+ }
+ break;
+ default:
+ break;
+ }
+ isFoundPoint = true;
+ }
+ }*/
+ }
+ }
+
+ switch (myPointSelectionMode)
+ {
+ case SM_FirstPoint:
+ case SM_SecondPoint: {
+ PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
+ flushUpdated();
+ setPointSelectionMode(aMode);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+{
+ switch (myPointSelectionMode)
+ {
+ case SM_FirstPoint:
+ case SM_SecondPoint:
+ {
+ double aX, anY;
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
+
+ flushUpdated();
+ emit focusActivated(myFeaturePrs->getAttribute(myPointSelectionMode));
+ }
+ break;
+ case SM_DonePoint:
+ {
+ commit();
+ restartOperation(feature()->getKind(), feature());
+ }
+ default:
+ break;
+ }
+}
+
+void PartSet_OperationCreateFeature::keyReleased(std::string theName, QKeyEvent* theEvent)
+{
+ int aKeyType = theEvent->key();
+ // the second point should be activated by any modification in the property panel
+ if (!theName.empty() /*&& aKeyType == Qt::Key_Return*/)
+ {
+ setPointSelectionMode(myFeaturePrs->getNextMode(theName), false);
+ }
+ keyReleased(theEvent->key());
+}
+
+void PartSet_OperationCreateFeature::keyReleased(const int theKey)
+{
+ switch (theKey) {
+ case Qt::Key_Return: {
+ if (myPointSelectionMode == SM_DonePoint)
+ {
+ commit();
+ // it start a new line creation at a free point
+ restartOperation(feature()->getKind(), FeaturePtr()/*feature()*/);
+ }
+ //else
+ // abort();
+ //restartOperation(feature()->getKind(), FeaturePtr());
+ }
+ break;
+ case Qt::Key_Escape: {
+ if (myPointSelectionMode == SM_DonePoint)
+ {
+ commit();
+ }
+ else
+ {
+ abort();
+ }
+ }
+ default:
+ break;
+ }
+}
+
+void PartSet_OperationCreateFeature::startOperation()
+{
+ PartSet_OperationSketchBase::startOperation();
+ setPointSelectionMode(!myInitFeature ? SM_FirstPoint : SM_SecondPoint);
+
+ emit multiSelectionEnabled(false);
+}
+
+void PartSet_OperationCreateFeature::abortOperation()
+{
+ emit featureConstructed(feature(), FM_Hide);
+ PartSet_OperationSketchBase::abortOperation();
+}
+
+void PartSet_OperationCreateFeature::stopOperation()
+{
+ PartSet_OperationSketchBase::stopOperation();
+ emit multiSelectionEnabled(true);
+}
+
+void PartSet_OperationCreateFeature::afterCommitOperation()
+{
+ PartSet_OperationSketchBase::afterCommitOperation();
+ emit featureConstructed(feature(), FM_Deactivation);
+}
+
+FeaturePtr PartSet_OperationCreateFeature::createFeature(const bool theFlushMessage)
+{
+ FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
+ if (sketch()) {
+ boost::shared_ptr<SketchPlugin_Feature> aFeature =
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
+
+ aFeature->addSub(aNewFeature);
+ }
+ myFeaturePrs->init(aNewFeature, myInitFeature);
+
+ emit featureConstructed(aNewFeature, FM_Activation);
+ if (theFlushMessage)
+ flushCreated();
+ return aNewFeature;
+}
+
+void PartSet_OperationCreateFeature::setPointSelectionMode(const PartSet_SelectionMode& theMode,
+ const bool isToEmitSignal)
+{
+ myPointSelectionMode = theMode;
+ if (isToEmitSignal) {
+ std::string aName = myFeaturePrs->getAttribute(theMode);
+ if (aName.empty() && theMode == SM_DonePoint) {
+ aName = XGUI::PROP_PANEL_OK;
+ }
+ emit focusActivated(aName);
+ }
+}
--- /dev/null
+// File: PartSet_OperationCreateFeature.h
+// Created: 20 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_OperationCreateFeature_H
+#define PartSet_OperationCreateFeature_H
+
+#include "PartSet.h"
+
+#include <PartSet_OperationSketchBase.h>
+#include <PartSet_Constants.h>
+
+#include <SketchPlugin_Line.h>
+
+#include <QObject>
+
+class PartSet_FeaturePrs;
+class GeomDataAPI_Point2D;
+class QMouseEvent;
+class QKeyEvent;
+
+/*!
+ \class PartSet_OperationCreateFeature
+ * \brief The operation for the sketch feature creation
+*/
+class PARTSET_EXPORT PartSet_OperationCreateFeature : public PartSet_OperationSketchBase
+{
+ Q_OBJECT
+
+public:
+
+public:
+ /// Constructor
+ /// \param theId the feature identifier
+ /// \param theParent the operation parent
+ /// \param theSketch the parent feature
+ PartSet_OperationCreateFeature(const QString& theId, QObject* theParent,
+ FeaturePtr theSketch);
+ /// Destructor
+ virtual ~PartSet_OperationCreateFeature();
+
+ /// Verifies whether this operator can be commited.
+ /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
+ virtual bool canBeCommitted() const;
+
+ /// Returns that this operator can be started above already running one.
+ /// The runned operation should be the sketch feature modified operation
+ /// \param theOperation the previous running operation
+ virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
+
+ /// Returns the operation local selection mode
+ /// \param theFeature the feature object to get the selection mode
+ /// \return the selection mode
+ virtual std::list<int> getSelectionModes(FeaturePtr theFeature) const;
+
+ /// Initializes some fields accorging to the feature
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void init(FeaturePtr theFeature,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
+
+ /// Returns the operation sketch feature
+ /// \returns the sketch instance
+ virtual FeaturePtr sketch() const;
+
+ /// Gives the current selected objects to be processed by the operation
+ /// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
+ /// Gives the current mouse point in the viewer
+ /// \param thePoint a point clicked in the viewer
+ /// \param theEvent the mouse event
+ virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+ /// Processes the key pressed in the view
+ /// \param theKey a key value
+ virtual void keyReleased(const int theKey);
+
+ virtual void keyReleased(std::string theName, QKeyEvent* theEvent);
+
+protected:
+ /// \brief Virtual method called when operation is started
+ /// Virtual method called when operation started (see start() method for more description)
+ /// After the parent operation body perform, set sketch feature to the created line feature
+ virtual void startOperation();
+
+ /// Virtual method called when operation aborted (see abort() method for more description)
+ /// Before the feature is aborted, it should be hidden from the viewer
+ virtual void abortOperation();
+
+ /// Virtual method called when operation stopped - committed or aborted.
+ /// Restore the multi selection state
+ virtual void stopOperation();
+
+ /// Virtual method called after operation committed (see commit() method for more description)
+ virtual void afterCommitOperation();
+
+ /// Creates an operation new feature
+ /// In addition to the default realization it appends the created line feature to
+ /// the sketch feature
+ /// \param theFlushMessage the flag whether the create message should be flushed
+ /// \returns the created feature
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+
+protected:
+ ///< Set the point selection mode. Emit signal about focus change if necessary.
+ /// \param theMode a new selection mode
+ /// \param isToEmitSignal the neccessity to emit signal
+ void setPointSelectionMode(const PartSet_SelectionMode& theMode,
+ const bool isToEmitSignal = true);
+
+private:
+ PartSet_FeaturePrs* myFeaturePrs; ///< the feature presentation
+ FeaturePtr myInitFeature; ///< the initial feature
+ PartSet_SelectionMode myPointSelectionMode; ///< point selection mode
+};
+
+#endif
PartSet_OperationEditLine::PartSet_OperationEditLine(const QString& theId,
QObject* theParent,
- boost::shared_ptr<ModelAPI_Feature> theFeature)
+ FeaturePtr theFeature)
: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
{
}
return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
}
-std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
+std::list<int> PartSet_OperationEditLine::getSelectionModes(FeaturePtr theFeature) const
{
return PartSet_OperationSketchBase::getSelectionModes(theFeature);
}
-void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+void PartSet_OperationEditLine::init(FeaturePtr theFeature,
const std::list<XGUI_ViewerPrs>& theSelected,
const std::list<XGUI_ViewerPrs>& theHighlighted)
{
myFeatures = theSelected;
}
-boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::sketch() const
+FeaturePtr PartSet_OperationEditLine::sketch() const
{
return mySketch;
}
{
if (myFeatures.size() == 1)
{
- boost::shared_ptr<ModelAPI_Feature> aFeature;
+ FeaturePtr aFeature;
if (!theHighlighted.empty())
aFeature = theHighlighted.front().feature();
if (!(theEvent->buttons() & Qt::LeftButton))
return;
- gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
blockSelection(true);
if (myCurPoint.myIsInitialized) {
double aCurX, aCurY;
- PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
+ PartSet_Tools::convertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
double aX, anY;
- PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
+ PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
double aDeltaX = aX - aCurX;
double aDeltaY = anY - aCurY;
std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
for (; anIt != aLast; anIt++) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
+ FeaturePtr aFeature = (*anIt).feature();
if (!aFeature || aFeature == feature())
continue;
moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START);
commit();
std::list<XGUI_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
for (; anIt != aLast; anIt++) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
+ FeaturePtr aFeature = (*anIt).feature();
if (aFeature)
emit featureConstructed(aFeature, FM_Deactivation);
}
}
}
-boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature(const bool /*theFlushMessage*/)
+FeaturePtr PartSet_OperationEditLine::createFeature(const bool /*theFlushMessage*/)
{
// do nothing in order to do not create a new feature
- return boost::shared_ptr<ModelAPI_Feature>();
+ return FeaturePtr();
}
-void PartSet_OperationEditLine::moveLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+void PartSet_OperationEditLine::moveLinePoint(FeaturePtr theFeature,
double theDeltaX, double theDeltaY,
const std::string& theAttribute)
{
- if (!theFeature || theFeature->getKind() != "SketchLine")
+ if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
return;
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
{
static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
- std::list<boost::shared_ptr<ModelAPI_Feature> > aFeatures;
+ std::list<FeaturePtr > aFeatures;
std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
for (; anIt != aLast; anIt++) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
+ FeaturePtr aFeature = (*anIt).feature();
if (!aFeature)
continue;
/// \param theParent the operation parent
/// \param theFeature the parent feature
PartSet_OperationEditLine(const QString& theId, QObject* theParent,
- boost::shared_ptr<ModelAPI_Feature> theFeature);
+ FeaturePtr theFeature);
/// Destructor
virtual ~PartSet_OperationEditLine();
/// Returns the operation local selection mode
/// \param theFeature the feature object to get the selection mode
/// \return the selection mode
- virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
+ virtual std::list<int> getSelectionModes(FeaturePtr theFeature) const;
/// Initializes some fields accorging to the feature
/// \param theFeature the feature
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ virtual void init(FeaturePtr theFeature,
const std::list<XGUI_ViewerPrs>& theSelected,
const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+ virtual FeaturePtr sketch() const;
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
/// Returns NULL feature. This is an operation of edition, not creation.
/// \param theFlushMessage the flag whether the create message should be flushed
/// \returns the created feature
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true);
protected:
/// Emits a signal about the selection blocking. Emits a signal to change the selection.
/// \param theDeltaX the delta for X coordinate is moved
/// \param theDeltaY the delta for Y coordinate is moved
/// \param theAttribute the start or end attribute of the line
- void moveLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ void moveLinePoint(FeaturePtr theFeature,
double theDeltaX, double theDeltaY,
const std::string& theAttribute);
/// Sends the features
void sendFeatures();
private:
- boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
+ FeaturePtr mySketch; ///< the sketch feature
std::list<XGUI_ViewerPrs> myFeatures; ///< the features to apply the edit operation
Point myCurPoint; ///< the current 3D point clicked or moved
- gp_Pnt myCurPressed; ///< the current 3D point clicked or moved
bool myIsBlockedSelection; ///< the state of the last state of selection blocked signal
};
#include <AIS_Shape.hxx>
#include <AIS_ListOfInteractive.hxx>
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_DimensionOwner.hxx>
+#include <AIS_LengthDimension.hxx>
#include <V3d_View.hxx>
#ifdef _DEBUG
{
}
-std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
+std::list<int> PartSet_OperationSketch::getSelectionModes(FeaturePtr theFeature) const
{
std::list<int> aModes;
if (!hasSketchPlane())
aModes.push_back(TopAbs_FACE);
else
aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
+
return aModes;
}
-void PartSet_OperationSketch::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+void PartSet_OperationSketch::init(FeaturePtr theFeature,
const std::list<XGUI_ViewerPrs>& /*theSelected*/,
const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
{
setFeature(theFeature);
}
-boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketch::sketch() const
+FeaturePtr PartSet_OperationSketch::sketch() const
{
return feature();
}
return;
if (theHighlighted.size() == 1) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = theHighlighted.front().feature();
+ FeaturePtr aFeature = theHighlighted.front().feature();
if (aFeature)
restartOperation(PartSet_OperationEditLine::Type(), aFeature);
}
}
}
+#include <QLineEdit>
+void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted)
+{
+ if (!hasSketchPlane()) {
+ }
+ else {
+ if (!theSelected.empty()) {
+ XGUI_ViewerPrs aPrs = theSelected.front();
+ if (!aPrs.owner().IsNull()) {
+ Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aPrs.owner());
+ if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
+ Handle(SelectMgr_SelectableObject) anObject = anOwner->Selectable();
+ double aValue = 0;
+ if (!anObject.IsNull()) {
+ Handle(AIS_LengthDimension) aLenDim = Handle(AIS_LengthDimension)::DownCast(anObject);
+ if (!aLenDim.IsNull())
+ aValue = aLenDim->GetValue();
+ }
+
+ QLineEdit* aLine = new QLineEdit();
+ QPoint aViewPos = theEvent->globalPos();
+ QPoint aLinePos(aViewPos.x(), aViewPos.y());
+ aLine->move(aLinePos);
+ aLine->setText(QString::number(aValue));
+ aLine->show();
+ }
+ }
+ }
+ }
+}
+
void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
{
if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty())
return;
if (myFeatures.size() != 1) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
+ FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(),
theView, feature(), myFeatures);
if (aFeature)
restartOperation(PartSet_OperationEditLine::Type(), aFeature);
}
}
-std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
+std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >
PartSet_OperationSketch::subPreview() const
{
- std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> > aPreviewMap;
+ std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> > aPreviewMap;
boost::shared_ptr<SketchPlugin_Feature> aFeature;
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
- std::list<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aRefList->list();
- std::list<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
+ std::list<FeaturePtr > aFeatures = aRefList->list();
+ std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(),
aLast = aFeatures.end();
for (; anIt != aLast; anIt++) {
aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
boost::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
// X axis is preferable to be dirX on the sketch
- const double tol = 1e-7;
+ const double tol = Precision::Confusion();
bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
boost::shared_ptr<GeomAPI_Dir> aTempDir(isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
boost::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
#include "PartSet.h"
#include <PartSet_OperationSketchBase.h>
+
+#include <SketchPlugin_Sketch.h>
+
#include <QObject>
+class Handle_AIS_InteractiveObject;
+
/*!
\class PartSet_OperationSketch
* \brief The operation for the sketch feature creation
Q_OBJECT
public:
/// Returns the operation type key
- static std::string Type() { return "Sketch"; }
+ static std::string Type() { return SKETCH_KIND; }
public:
/// Constructor
/// Returns the operation local selection mode
/// \param theFeature the feature object to get the selection mode
/// \return the selection mode
- virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
+ virtual std::list<int> getSelectionModes(FeaturePtr theFeature) const;
/// Initializes some fields accorging to the feature
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ virtual void init(FeaturePtr theFeature,
const std::list<XGUI_ViewerPrs>& theSelected,
const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+ virtual FeaturePtr sketch() const;
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
const std::list<XGUI_ViewerPrs>& theSelected,
const std::list<XGUI_ViewerPrs>& theHighlighted);
+ /// Processes the mouse release in the point
+ /// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
+
/// Gives the current mouse point in the viewer
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
/// Returns the map of the operation previews including the nested feature previews
/// \return the map of feature to the feature preview
- virtual std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
+ virtual std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >
subPreview() const;
/// Virtual method called when operation stopped - committed or aborted.
}
boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
- boost::shared_ptr<ModelAPI_Feature> theFeature)
+ FeaturePtr theFeature)
{
boost::shared_ptr<SketchPlugin_Feature> aFeature =
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
return aFeature->preview();
}
-std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
+std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >
PartSet_OperationSketchBase::subPreview() const
{
- return std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >();
+ return std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >();
}
-std::list<int> PartSet_OperationSketchBase::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
+std::list<int> PartSet_OperationSketchBase::getSelectionModes(FeaturePtr theFeature) const
{
std::list<int> aModes;
aModes.push_back(TopAbs_VERTEX);
aModes.push_back(TopAbs_EDGE);
return aModes;
}
-boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
+FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
{
- boost::shared_ptr<ModelAPI_Feature> aFeature = ModuleBase_Operation::createFeature(theFlushMessage);
+ FeaturePtr aFeature = ModuleBase_Operation::createFeature(theFlushMessage);
if (aFeature)
emit featureConstructed(aFeature, FM_Activation);
return aFeature;
}
void PartSet_OperationSketchBase::restartOperation(const std::string& theType,
- boost::shared_ptr<ModelAPI_Feature> theFeature)
+ FeaturePtr theFeature)
{
emit launchOperation(theType, theFeature);
}
/// Returns the feature preview shape
/// \param theFeature the feature object to obtain the preview
- static boost::shared_ptr<GeomAPI_Shape> preview(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ static boost::shared_ptr<GeomAPI_Shape> preview(FeaturePtr theFeature);
/// Returns the map of the operation previews including the nested feature previews
/// \return the map of feature to the feature preview
- virtual std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> > subPreview() const;
+ virtual std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> > subPreview() const;
/// Returns the operation local selection mode
/// \param theFeature the feature object to get the selection mode
/// \return the selection mode
- virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const = 0;
+ virtual std::list<int> getSelectionModes(FeaturePtr theFeature) const;
/// Initializes some fields accorging to the feature
/// \param theSelected the list of selected presentations
/// \param theHighlighted the list of highlighted presentations
- virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ virtual void init(FeaturePtr theFeature,
const std::list<XGUI_ViewerPrs>& theSelected,
const std::list<XGUI_ViewerPrs>& theHighlighted) {}
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual boost::shared_ptr<ModelAPI_Feature> sketch() const = 0;
+ virtual FeaturePtr sketch() const = 0;
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
/// \param theType a type of an operation started
/// theFeature the operation argument
void restartOperation(const std::string& theType,
- boost::shared_ptr<ModelAPI_Feature> theFeature = boost::shared_ptr<ModelAPI_Feature>());
+ FeaturePtr theFeature = FeaturePtr());
signals:
/// signal about the request to launch operation
/// theName the operation name
/// theFeature the operation argument
- void launchOperation(std::string theName, boost::shared_ptr<ModelAPI_Feature> theFeature);
+ void launchOperation(std::string theName, FeaturePtr theFeature);
/// signal about the focus activated
/// theName the attribute name
void focusActivated(const std::string& theAttibuteName);
/// Signal about the feature construing is finished
/// \param theFeature the result feature
/// \param theMode the mode of the feature modification
- void featureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ void featureConstructed(FeaturePtr theFeature,
int theMode);
/// Signal about the features should be selected
/// \param theSelected the list of selected presentations
/// the sketch feature
/// \param theFlushMessage the flag whether the create message should be flushed
/// \returns the created feature
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true);
};
#endif
+++ /dev/null
-// File: PartSet_OperationSketchLine.h
-// Created: 20 Apr 2014
-// Author: Natalia ERMOLAEVA
-
-#include <PartSet_OperationSketchLine.h>
-
-#include <PartSet_Tools.h>
-#include <PartSet_OperationSketch.h>
-
-#include <SketchPlugin_Feature.h>
-#include <SketchPlugin_Sketch.h>
-
-#include <GeomDataAPI_Point2D.h>
-
-#include <ModuleBase_OperationDescription.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_AttributeRefAttr.h>
-#include <ModelAPI_AttributeRefList.h>
-
-#include <SketchPlugin_Constraint.h>
-
-#include <Geom_Line.hxx>
-#include <gp_Lin.hxx>
-
-#include <XGUI_ViewerPrs.h>
-#include <XGUI_Constants.h>
-
-#include <SketchPlugin_Line.h>
-
-#include <V3d_View.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Tool.hxx>
-
-#ifdef _DEBUG
-#include <QDebug>
-#endif
-
-#include <QMouseEvent>
-
-using namespace std;
-
-PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId,
- QObject* theParent,
- boost::shared_ptr<ModelAPI_Feature> theFeature)
-: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature),
- myPointSelectionMode(SM_FirstPoint)
-{
-}
-
-PartSet_OperationSketchLine::~PartSet_OperationSketchLine()
-{
-}
-
-bool PartSet_OperationSketchLine::canBeCommitted() const
-{
- return myPointSelectionMode == SM_DonePoint;
-}
-
-bool PartSet_OperationSketchLine::isGranted(ModuleBase_IOperation* theOperation) const
-{
- return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
-}
-
-std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
-{
- std::list<int> aModes;
- if (theFeature != feature())
- aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
- return aModes;
-}
-
-void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::list<XGUI_ViewerPrs>& /*theSelected*/,
- const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
-{
- if (!theFeature || theFeature->getKind() != "SketchLine")
- return;
- // use the last point of the previous feature as the first of the new one
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-}
-
-boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::sketch() const
-{
- return mySketch;
-}
-
-void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<XGUI_ViewerPrs>& theSelected,
- const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
-{
- if (myPointSelectionMode == SM_DonePoint)
- {
- // if the point creation is finished, the next mouse release should commit the modification
- // the next release can happens by double click in the viewer
- commit();
- restartOperation(PartSet_OperationSketchLine::Type(), feature());
- return;
- }
-
- double aX, anY;
-
- bool isFoundPoint = false;
- gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
- if (theSelected.empty()) {
- PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
- isFoundPoint = true;
- }
- else {
- XGUI_ViewerPrs aPrs = theSelected.front();
- const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull()) // the point is selected
- {
- if (aShape.ShapeType() == TopAbs_VERTEX) {
- const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
- if (!aVertex.IsNull()) {
- aPoint = BRep_Tool::Pnt(aVertex);
- PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
- isFoundPoint = true;
-
- setConstraints(aX, anY);
- }
- }
- else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
- {
- boost::shared_ptr<ModelAPI_Feature> aFeature = aPrs.feature();
- if (aFeature) {
- double X0, X1, X2, X3;
- double Y0, Y1, Y2, Y3;
- getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
- getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
- PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, X1, Y1);
-
- switch (myPointSelectionMode) {
- case SM_FirstPoint:
- PartSet_Tools::ProjectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
- break;
- case SM_SecondPoint: {
- getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
- PartSet_Tools::IntersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
- }
- break;
- default:
- break;
- }
- isFoundPoint = true;
- }
- }
- }
- }
-
- switch (myPointSelectionMode)
- {
- case SM_FirstPoint: {
- setLinePoint(feature(), aX, anY, LINE_ATTR_START);
- setLinePoint(feature(), aX, anY, LINE_ATTR_END);
- flushUpdated();
-
- setPointSelectionMode(SM_SecondPoint);
- }
- break;
- case SM_SecondPoint: {
- setLinePoint(feature(), aX, anY, LINE_ATTR_END);
- flushUpdated();
-
- setPointSelectionMode(SM_DonePoint);
- }
- break;
- default:
- break;
- }
-}
-
-void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
-{
- switch (myPointSelectionMode)
- {
- case SM_FirstPoint: {
- double aX, anY;
- gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
- PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
- setLinePoint(feature(), aX, anY, LINE_ATTR_START);
- setLinePoint(feature(), aX, anY, LINE_ATTR_END);
- flushUpdated();
- emit focusActivated(LINE_ATTR_START);
- }
- break;
- case SM_SecondPoint:
- {
- gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
- setLinePoint(aPoint, theView, LINE_ATTR_END);
- flushUpdated();
- emit focusActivated(LINE_ATTR_END);
- }
- break;
- case SM_DonePoint:
- {
- commit();
- restartOperation(PartSet_OperationSketchLine::Type(), feature());
- }
- default:
- break;
- }
-}
-
-void PartSet_OperationSketchLine::keyReleased(std::string theName, QKeyEvent* theEvent)
-{
- int aKeyType = theEvent->key();
- // the second point should be activated by any modification in the property panel
- if (!theName.empty() /*&& aKeyType == Qt::Key_Return*/) {
- if (theName == LINE_ATTR_START) {
- setPointSelectionMode(SM_SecondPoint, false);
- }
- else if (theName == LINE_ATTR_END) {
- setPointSelectionMode(SM_DonePoint, false);
- }
- }
- keyReleased(theEvent->key());
-}
-
-void PartSet_OperationSketchLine::keyReleased(const int theKey)
-{
- switch (theKey) {
- case Qt::Key_Return: {
- if (myPointSelectionMode == SM_DonePoint)
- {
- commit();
- restartOperation(PartSet_OperationSketchLine::Type(), feature());
- }
- //else
- // abort();
- //emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr<ModelAPI_Feature>());
- }
- break;
- case Qt::Key_Escape: {
- if (myPointSelectionMode == SM_DonePoint)
- {
- commit();
- }
- else
- abort();
- }
- default:
- break;
- }
-}
-
-void PartSet_OperationSketchLine::startOperation()
-{
- PartSet_OperationSketchBase::startOperation();
- setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint);
-
- emit multiSelectionEnabled(false);
-}
-
-void PartSet_OperationSketchLine::abortOperation()
-{
- emit featureConstructed(feature(), FM_Hide);
- PartSet_OperationSketchBase::abortOperation();
-}
-
-void PartSet_OperationSketchLine::stopOperation()
-{
- PartSet_OperationSketchBase::stopOperation();
- emit multiSelectionEnabled(true);
-}
-
-void PartSet_OperationSketchLine::afterCommitOperation()
-{
- PartSet_OperationSketchBase::afterCommitOperation();
- emit featureConstructed(feature(), FM_Deactivation);
-}
-
-boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature(const bool theFlushMessage)
-{
- boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature(false);
- if (sketch()) {
- boost::shared_ptr<SketchPlugin_Feature> aFeature =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
-
- aFeature->addSub(aNewFeature);
- }
- if (myInitPoint) {
- setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START);
- setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END);
-
- boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aData->attribute(LINE_ATTR_START));
- createConstraint(myInitPoint, aPoint);
- }
-
- emit featureConstructed(aNewFeature, FM_Activation);
- if (theFlushMessage)
- flushCreated();
- return aNewFeature;
-}
-
-void PartSet_OperationSketchLine::createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
- boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
-{
- boost::shared_ptr<ModelAPI_Document> aDoc = document();
- boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature("SketchConstraintCoincidence");
-
- if (sketch()) {
- boost::shared_ptr<SketchPlugin_Feature> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
- aSketch->addSub(aFeature);
- }
-
- boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
-
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
- aRef1->setAttr(thePoint1);
-
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
- aRef2->setAttr(thePoint2);
-
- if (aFeature) // TODO: generate an error if feature was not created
- aFeature->execute();
-}
-
-void PartSet_OperationSketchLine::setConstraints(double theX, double theY)
-{
- std::string aPointArg;
- switch (myPointSelectionMode)
- {
- case SM_FirstPoint:
- aPointArg = LINE_ATTR_START;
- break;
- case SM_SecondPoint:
- aPointArg = LINE_ATTR_END;
- break;
- default:
- break;
- }
-
- boost::shared_ptr<ModelAPI_Feature> aSkFeature = feature();
-
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aData->attribute(aPointArg));
- aData = sketch()->data();
- boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
-
- std::list<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aRefList->list();
- std::list<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
- aLast = aFeatures.end();
- for (; anIt != aLast; anIt++) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = *anIt;
- boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = findLinePoint(aFeature, theX, theY);
- if (aFPoint)
- createConstraint(aFPoint, aPoint);
- }
-}
-
-void PartSet_OperationSketchLine::getLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::string& theAttribute,
- double& theX, double& theY)
-{
- if (!theFeature || theFeature->getKind() != "SketchLine")
- return;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
- theX = aPoint->x();
- theY = aPoint->y();
-}
-
-boost::shared_ptr<GeomDataAPI_Point2D> PartSet_OperationSketchLine::findLinePoint(
- boost::shared_ptr<ModelAPI_Feature> theFeature,
- double theX, double theY)
-{
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
- if (!theFeature || theFeature->getKind() != "SketchLine")
- return aPoint2D;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
- if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
- aPoint2D = aPoint;
- else {
- aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
- if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
- aPoint2D = aPoint;
- }
- return aPoint2D;
-}
-
-void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
- double theX, double theY,
- const std::string& theAttribute)
-{
- if (!theFeature)
- return;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
- aPoint->setValue(theX, theY);
-}
-
-void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
- Handle(V3d_View) theView,
- const std::string& theAttribute)
-{
- double aX, anY;
- PartSet_Tools::ConvertTo2D(thePoint, sketch(), theView, aX, anY);
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
- aPoint->setValue(aX, anY);
-}
-
-void PartSet_OperationSketchLine::setPointSelectionMode(const PointSelectionMode& theMode,
- const bool isToEmitSignal)
-{
- myPointSelectionMode = theMode;
- if (isToEmitSignal) {
- std::string aName;
- switch (theMode) {
- case SM_FirstPoint:
- aName = LINE_ATTR_START;
- break;
- case SM_SecondPoint:
- aName = LINE_ATTR_END;
- break;
- case SM_DonePoint:
- aName = XGUI::PROP_PANEL_OK;
- break;
- default:
- break;
- }
- emit focusActivated(aName);
- }
-}
+++ /dev/null
-// File: PartSet_OperationSketchLine.h
-// Created: 20 Apr 2014
-// Author: Natalia ERMOLAEVA
-
-#ifndef PartSet_OperationSketchLine_H
-#define PartSet_OperationSketchLine_H
-
-#include "PartSet.h"
-
-#include <PartSet_OperationSketchBase.h>
-#include <QObject>
-
-class GeomDataAPI_Point2D;
-class QMouseEvent;
-class QKeyEvent;
-
-/*!
- \class PartSet_OperationSketchLine
- * \brief The operation for the sketch feature creation
-*/
-class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase
-{
- Q_OBJECT
-
-public:
- /// Returns the operation type key
- static std::string Type() { return "SketchLine"; }
-
-public:
- /// Constructor
- /// \param theId the feature identifier
- /// \param theParent the operation parent
- /// \param theFeature the parent feature
- PartSet_OperationSketchLine(const QString& theId, QObject* theParent,
- boost::shared_ptr<ModelAPI_Feature> theSketchFeature);
- /// Destructor
- virtual ~PartSet_OperationSketchLine();
-
- /// Verifies whether this operator can be commited.
- /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
- virtual bool canBeCommitted() const;
-
- /// Returns that this operator can be started above already running one.
- /// The runned operation should be the sketch feature modified operation
- /// \param theOperation the previous running operation
- virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
-
- /// Returns the operation local selection mode
- /// \param theFeature the feature object to get the selection mode
- /// \return the selection mode
- virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
-
- /// Initializes some fields accorging to the feature
- /// \param theSelected the list of selected presentations
- /// \param theHighlighted the list of highlighted presentations
- virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::list<XGUI_ViewerPrs>& theSelected,
- const std::list<XGUI_ViewerPrs>& theHighlighted);
-
- /// Returns the operation sketch feature
- /// \returns the sketch instance
- virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
-
- /// Gives the current selected objects to be processed by the operation
- /// \param theEvent the mouse event
- /// \param theView a viewer to have the viewer the eye position
- /// \param theSelected the list of selected presentations
- /// \param theHighlighted the list of highlighted presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected,
- const std::list<XGUI_ViewerPrs>& theHighlighted);
- /// Gives the current mouse point in the viewer
- /// \param thePoint a point clicked in the viewer
- /// \param theEvent the mouse event
- virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
- /// Processes the key pressed in the view
- /// \param theKey a key value
- virtual void keyReleased(const int theKey);
-
- virtual void keyReleased(std::string theName, QKeyEvent* theEvent);
-
- /// \brief Save the point to the line.
- /// \param theFeature the line feature
- /// \param theX the horizontal coordinate
- /// \param theY the vertical coordinate
- /// \param theAttribute the start or end attribute of the line
- static void setLinePoint(boost::shared_ptr<ModelAPI_Feature>, double theX, double theY,
- const std::string& theAttribute);
-
-protected:
- /// \brief Virtual method called when operation is started
- /// Virtual method called when operation started (see start() method for more description)
- /// After the parent operation body perform, set sketch feature to the created line feature
- virtual void startOperation();
-
- /// Virtual method called when operation aborted (see abort() method for more description)
- /// Before the feature is aborted, it should be hidden from the viewer
- virtual void abortOperation();
-
- /// Virtual method called when operation stopped - committed or aborted.
- /// Restore the multi selection state
- virtual void stopOperation();
-
- /// Virtual method called after operation committed (see commit() method for more description)
- virtual void afterCommitOperation();
-
- /// Creates an operation new feature
- /// In addition to the default realization it appends the created line feature to
- /// the sketch feature
- /// \param theFlushMessage the flag whether the create message should be flushed
- /// \returns the created feature
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
-
- /// Creates a constraint on two points
- /// \param thePoint1 the first point
- /// \param thePoint1 the second point
- void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
- boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
-
- /// Creates constrains of the current
- /// \param theX the horizontal coordnate of the point
- /// \param theY the vertical coordnate of the point
- void setConstraints(double theX, double theY);
-
-protected:
- /// \brief Get the line point 2d coordinates.
- /// \param theFeature the line feature
- /// \param theAttribute the start or end attribute of the line
- /// \param theX the horizontal coordinate
- /// \param theY the vertical coordinate
- void getLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature, const std::string& theAttribute,
- double& theX, double& theY);
- /// Find a point in the line with given coordinates
- /// \param theFeature the line feature
- /// \param theX the horizontal point coordinate
- /// \param theY the vertical point coordinate
- boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
- double theX, double theY);
-
- /// \brief Save the point to the line.
- /// \param thePoint the 3D point in the viewer
- /// \param theAttribute the start or end attribute of the line
- void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute);
-
-protected:
- ///< Structure to lists the possible types of point selection modes
- enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_DonePoint};
-
- ///< Set the point selection mode. Emit signal about focus change if necessary.
- /// \param theMode a new selection mode
- /// \param isToEmitSignal the neccessity to emit signal
- void setPointSelectionMode(const PointSelectionMode& theMode, const bool isToEmitSignal = true);
-
-private:
- boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
- boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
- PointSelectionMode myPointSelectionMode; ///< point selection mode
-};
-
-#endif
--- /dev/null
+// File: PartSet_Presentation.h
+// Created: 02 June 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_Presentation.h>
+#include <PartSet_Tools.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
+
+#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_ConstraintLength.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_LengthDimension.hxx>
+#include <AIS_Shape.hxx>
+
+#include <gp_Pln.hxx>
+#include <gp_Pnt.hxx>
+
+const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color
+const int SKETCH_WIDTH = 4; /// the plane edge width
+
+Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation(
+ FeaturePtr theFeature,
+ FeaturePtr theSketch,
+ const TopoDS_Shape& theShape,
+ Handle_AIS_InteractiveObject thePrevPrs)
+{
+ Handle(AIS_InteractiveObject) anAIS;
+
+ if (theFeature->getKind() == SKETCH_CONSTRAINT_LENGTH_KIND)
+ anAIS = createSketchConstraintLength(theFeature, theSketch, thePrevPrs);
+ else {
+ anAIS = createFeature(theFeature, theShape, thePrevPrs);
+ if (theFeature->getKind() == SKETCH_KIND)
+ {
+ Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+ aShapeAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR));
+ aShapeAIS->SetWidth(SKETCH_WIDTH);
+ aShapeAIS->Redisplay();
+ }
+ }
+
+ return anAIS;
+}
+
+Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature(
+ FeaturePtr theFeature,
+ const TopoDS_Shape& theShape,
+ Handle_AIS_InteractiveObject thePrevPrs)
+{
+ Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
+ if (!anAIS.IsNull())
+ {
+ Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+ if (!aShapeAIS.IsNull()) {
+ // if the AIS object is displayed in the opened local context in some mode, additional
+ // AIS sub objects are created there. They should be rebuild for correct selecting.
+ // It is possible to correct it by closing local context before the shape set and opening
+ // after. Another workaround to thrown down the selection and reselecting the AIS.
+ // If there was a problem here, try the first solution with close/open local context.
+ aShapeAIS->Set(theShape);
+ aShapeAIS->Redisplay(Standard_True);
+ }
+ }
+ else
+ {
+ anAIS = new AIS_Shape(theShape);
+ }
+ return anAIS;
+}
+
+Handle(AIS_InteractiveObject) PartSet_Presentation::createSketchConstraintLength(
+ FeaturePtr theFeature,
+ FeaturePtr theSketch,
+ Handle(AIS_InteractiveObject) thePrevPrs)
+{
+ if (!theFeature || !theSketch)
+ return thePrevPrs;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/);
+
+ aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ if (!anAttr)
+ return thePrevPrs;
+ FeaturePtr aFeature = anAttr->feature();
+ if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
+ return thePrevPrs;
+
+ aData = aFeature->data();
+ if (!aData->isValid())
+ return thePrevPrs;
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPointStart =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ boost::shared_ptr<GeomDataAPI_Point2D> aPointEnd =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+
+ gp_Pnt aPoint1, aPoint2;
+ PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1);
+ PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2);
+
+ //Build dimension here
+ gp_Pnt aP1 = aPoint1;
+ gp_Pnt aP2 = aPoint2;
+
+ Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
+ if (anAIS.IsNull())
+ {
+ Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (aP1, aP2, aPlane);
+
+ Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
+ anAspect->MakeArrows3d (Standard_False);
+ anAspect->MakeText3d(false/*is text 3d*/);
+ anAspect->TextAspect()->SetHeight(28);
+ anAspect->MakeTextShaded(false/*is test shaded*/);
+ aLenDim->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/);
+ /*if (isUnitsDisplayed)
+ {
+ aLenDim->SetDisplayUnits (aDimDlg->GetUnits ());
+ }*/
+ aLenDim->SetDimensionAspect (anAspect);
+ aLenDim->SetFlyout(12);
+
+ anAIS = aLenDim;
+ }
+ else {
+ // update presentation
+ Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
+ if (!aDimAIS.IsNull()) {
+ aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
+ aDimAIS->Redisplay(Standard_True);
+ }
+ }
+ return anAIS;
+}
--- /dev/null
+// File: PartSet_Presentation.h
+// Created: 02 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_Presentation_H
+#define PartSet_Presentation_H
+
+#include "PartSet.h"
+
+#include <TopoDS_Shape.hxx>
+
+#include <ModelAPI_Feature.h>
+
+#include <boost/shared_ptr.hpp>
+
+class Handle_AIS_InteractiveObject;
+
+/*!
+ \class PartSet_Presentation
+ * \brief The operation for the sketch feature creation
+*/
+class PARTSET_EXPORT PartSet_Presentation
+{
+public:
+ /// Creates AIS presentation for the given feature
+ /// \param theFeature a feature
+ /// \return the presentation
+ static Handle_AIS_InteractiveObject createPresentation(
+ FeaturePtr theFeature,
+ FeaturePtr theSketch,
+ const TopoDS_Shape& theShape,
+ Handle_AIS_InteractiveObject thePrevPrs);
+protected:
+ static Handle_AIS_InteractiveObject createFeature(
+ FeaturePtr theFeature,
+ const TopoDS_Shape& theShape,
+ Handle_AIS_InteractiveObject thePrevPrs);
+
+ static Handle_AIS_InteractiveObject createSketchConstraintLength(
+ FeaturePtr theFeature,
+ FeaturePtr theSketch,
+ Handle_AIS_InteractiveObject thePrevPrs);
+};
+
+#endif
#include <XGUI_Displayer.h>
#include <XGUI_ViewerPrs.h>
#include <XGUI_ViewerProxy.h>
-#include <PartSet_OperationSketchLine.h>
+#include <PartSet_FeaturePrs.h>
+#include <PartSet_Presentation.h>
+#include <PartSet_OperationSketchBase.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Document.h>
static double myTestDelta;
-static boost::shared_ptr<ModelAPI_Feature> myTestFeature;
+static FeaturePtr myTestFeature;
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
theWorkshop->viewer()->activeView());
PartSet_TestOCC::changeTestLine(theWorkshop);
}
- Handle(AIS_InteractiveObject) anIO = theWorkshop->displayer()->GetAISObject(myTestFeature);
+ Handle(AIS_InteractiveObject) anIO = theWorkshop->displayer()->getAISObject(myTestFeature);
if (!anIO.IsNull()) {
theWorkshop->viewer()->AISContext()->MoveTo(0, 0, theWorkshop->viewer()->activeView());
theWorkshop->viewer()->AISContext()->Select(0, 0, 2500, 2500, theWorkshop->viewer()->activeView());
ModuleBase_Operation* anOperation = theWorkshop->operationMgr()->currentOperation();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
- boost::shared_ptr<ModelAPI_Feature> aSketch;
+ FeaturePtr aSketch;
if (aPreviewOp) {
// create a line
boost::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_PluginManager::get()->rootDocument();
- boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature(
- PartSet_OperationSketchLine::Type().c_str());
+ FeaturePtr aFeature = aDoc->addFeature(SKETCH_LINE_KIND);
if (aFeature) // TODO: generate an error if feature was not created
aFeature->execute();
boost::dynamic_pointer_cast<SketchPlugin_Feature>(aPreviewOp->sketch());
aSketch->addSub(aFeature);
- PartSet_OperationSketchLine::setLinePoint(aFeature, 100, 100, LINE_ATTR_START);
- PartSet_OperationSketchLine::setLinePoint(aFeature, 150, 300, LINE_ATTR_END);
+ PartSet_FeaturePrs::setLinePoint(aFeature, 100, 100, LINE_ATTR_START);
+ PartSet_FeaturePrs::setLinePoint(aFeature, 150, 300, LINE_ATTR_END);
- boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
+ boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
XGUI_Displayer* aDisplayer = theWorkshop->displayer();
- aDisplayer->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ aFeature, aSketch,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), NULL);
+ if (!anAIS.IsNull())
+ aDisplayer->redisplay(aFeature, anAIS, -1, false);
+
std::list<int> aModes;
aModes.push_back(TopAbs_VERTEX);
aModes.push_back(TopAbs_EDGE);
- aDisplayer->ActivateInLocalContext(aFeature, aModes, true);
+ aDisplayer->activateInLocalContext(aFeature, aModes, true);
// change the line
/*double aDelta = -200;
for (int i = 0; i < 20; i++) {
aDelta = aDelta - i*2;
- PartSet_OperationSketchLine::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
- PartSet_OperationSketchLine::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END);
- boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
+ PartSet_FeaturePrs::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
+ PartSet_FeaturePrs::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END);
- theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), true);
+ boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ aFeature, aSketch,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), NULL);
+ if (!anAIS.IsNull())
+ aDisplayer->redisplay(aFeature, anAIS, -1, true);
int aVal = 90;
for (int j = 0; j < 10000000; j++)
//aModes.clear();
//aModes.push_back(TopAbs_VERTEX);
//aModes.push_back(TopAbs_EDGE);
- //aDisplayer->ActivateInLocalContext(aFeature, aModes, true);
+ //aDisplayer->activateInLocalContext(aFeature, aModes, true);
myTestFeature = aFeature;
std::list<XGUI_ViewerPrs> aPrs;
- aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape()));
- aDisplayer->SetSelected(aPrs, true);
+ aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape(), NULL));
+ aDisplayer->setSelected(aPrs, true);
}
}
// change the line
if (!myTestFeature)
return;
- boost::shared_ptr<ModelAPI_Feature> aFeature = myTestFeature;
+ FeaturePtr aFeature = myTestFeature;
myTestDelta = myTestDelta - 50;
double aDelta = myTestDelta;
- PartSet_OperationSketchLine::setLinePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START);
- PartSet_OperationSketchLine::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
- boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
-
- theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), true);
+ PartSet_FeaturePrs::setLinePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START);
+ PartSet_FeaturePrs::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
+ boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
+
+ Handle(AIS_InteractiveObject) aPrevAIS;
+ FeaturePtr aSketch;//NULL
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ aFeature, aSketch,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+ aPrevAIS);
+ if (!anAIS.IsNull())
+ theWorkshop->displayer()->redisplay(aFeature, anAIS, -1, true);
//std::list<int> aModes;
//aModes.clear();
//aModes.push_back(TopAbs_VERTEX);
//aModes.push_back(TopAbs_EDGE);
- //aDisplayer->ActivateInLocalContext(aFeature, aModes, true);
+ //aDisplayer->activateInLocalContext(aFeature, aModes, true);
/*std::list<XGUI_ViewerPrs> aPrs;
aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape()));
- theWorkshop->displayer()->SetSelected(aPrs, true);*/
+ theWorkshop->displayer()->setSelected(aPrs, true);*/
- theWorkshop->displayer()->UpdateViewer();
+ theWorkshop->displayer()->updateViewer();
}
void PartSet_TestOCC::moveMouse(Handle(AIS_InteractiveContext) theContext, Handle(V3d_View) theView)
const double PRECISION_TOLERANCE = 0.000001;
-gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
+gp_Pnt PartSet_Tools::convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
{
if (theView.IsNull())
return gp_Pnt();
return ResultPoint;
}
-void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
+void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
Handle(V3d_View) theView, double& theX, double& theY)
{
if (!theSketch)
theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
}
-void PartSet_Tools::IntersectLines(double theX0, double theY0, double theX1, double theY1,
+void PartSet_Tools::convertTo3D(const double theX, const double theY,
+ FeaturePtr theSketch,
+ gp_Pnt& thePoint)
+{
+ if (!theSketch)
+ return;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+
+ boost::shared_ptr<GeomDataAPI_Point> aC =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::shared_ptr<GeomDataAPI_Dir> aX =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ boost::shared_ptr<GeomDataAPI_Dir> aY =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+
+ boost::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(
+ aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY));
+
+ boost::shared_ptr<GeomAPI_Pnt> aPoint = boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
+ thePoint = gp_Pnt(aPoint->x(), aPoint->y(), aPoint->z());
+}
+
+void PartSet_Tools::intersectLines(double theX0, double theY0, double theX1, double theY1,
double theX2, double theY2, double theX3, double theY3,
double& theX, double& theY)
{
//It is not possible to use Precision::Confusion(), because it is e-0.8, but V is sometimes e-6
Standard_Real aPrec = PRECISION_TOLERANCE;
if (fabs(theX - theX0) < aPrec && fabs(theY - theY0) < aPrec) {
- ProjectPointOnLine(theX2, theY2, theX3, theY3, theX1, theY1, theX, theY);
+ projectPointOnLine(theX2, theY2, theX3, theY3, theX1, theY1, theX, theY);
}
}
-void PartSet_Tools::ProjectPointOnLine(double theX1, double theY1, double theX2, double theY2,
+void PartSet_Tools::projectPointOnLine(double theX1, double theY1, double theX2, double theY2,
double thePointX, double thePointY, double& theX, double& theY)
{
theX = theY = 0;
}
}
-boost::shared_ptr<ModelAPI_Feature> PartSet_Tools::NearestFeature(QPoint thePoint,
+FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint,
Handle_V3d_View theView,
- boost::shared_ptr<ModelAPI_Feature> theSketch,
+ FeaturePtr theSketch,
const std::list<XGUI_ViewerPrs>& theFeatures)
{
double aX, anY;
- gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, theView);
- PartSet_Tools::ConvertTo2D(aPoint, theSketch, theView, aX, anY);
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
+ PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, anY);
- boost::shared_ptr<ModelAPI_Feature> aFeature;
+ FeaturePtr aFeature;
std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
- boost::shared_ptr<ModelAPI_Feature> aDeltaFeature;
+ FeaturePtr aDeltaFeature;
double aMinDelta = -1;
XGUI_ViewerPrs aPrs;
for (; anIt != aLast; anIt++) {
aPrs = *anIt;
if (!aPrs.feature())
continue;
- double aDelta = DistanceToPoint(aPrs.feature(), aX, anY);
+ double aDelta = distanceToPoint(aPrs.feature(), aX, anY);
if (aMinDelta < 0 || aMinDelta > aDelta) {
aMinDelta = aDelta;
aDeltaFeature = aPrs.feature();
return aDeltaFeature;
}
-double PartSet_Tools::DistanceToPoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+double PartSet_Tools::distanceToPoint(FeaturePtr theFeature,
double theX, double theY)
{
double aDelta = 0;
- if (theFeature->getKind() != "SketchLine")
+ if (theFeature->getKind() != SKETCH_LINE_KIND)
return aDelta;
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
double aX, anY;
- PartSet_Tools::ProjectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY);
+ PartSet_Tools::projectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY);
aDelta = gp_Pnt(theX, theY, 0).Distance(gp_Pnt(aX, anY, 0));
#include <QPoint>
+#include <ModelAPI_Feature.h>
+
#include <boost/shared_ptr.hpp>
#include <list>
class Handle_V3d_View;
-class ModelAPI_Feature;
class XGUI_ViewerPrs;
/*!
/// Converts the 2D screen point to the 3D point on the view according to the point of view
/// \param thePoint a screen point
/// \param theView a 3D view
- static gp_Pnt ConvertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
+ static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
/// \brief Converts the 3D point to the projected coodinates on the sketch plane.
/// \param thePoint the 3D point in the viewer
/// \param theSketch the sketch feature
/// \param theX the X coordinate
/// \param theY the Y coordinate
- static void ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
+ static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
Handle(V3d_View) theView, double& theX, double& theY);
+ /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
+ /// \param theX the X coordinate
+ /// \param theY the Y coordinate
+ /// \param theSketch the sketch feature
+ /// \param thePoint the 3D point in the viewer
+ static void convertTo3D(const double theX, const double theY,
+ FeaturePtr theSketch,
+ gp_Pnt& thePoint);
+
/// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3),
/// where vi - {xi,yi}. If the v0 is on the second line, the result is a projection of the v1 to this line
/// \param theX0 the horizontal coordinate of 0 point
/// \param theY3 the vertical coordinate of 3 point
/// \param theX the output horizontal coordinate of the intersection point
/// \param theY the outpup vertical coordinate of the intersection point
- static void IntersectLines(double theX0, double theY0, double theX1, double theY1,
+ static void intersectLines(double theX0, double theY0, double theX1, double theY1,
double theX2, double theY2, double theX3, double theY3,
double& theX, double& theY);
/// \param theY1 the vertical coordinate of the first line point
/// \param theX2 the horizontal coordinate of the second line point
/// \param theY2 the vertical coordinate of the second line point
- static void ProjectPointOnLine(double theX1, double theY1, double theX2, double theY2,
+ static void projectPointOnLine(double theX1, double theY1, double theX2, double theY2,
double thePointX, double thePointY, double& theX, double& theY);
/// Returns a feature that is under the mouse point
/// \param theView a 3D view
/// \param theSketch the sketch feature
/// \param theFeatures the list of selected presentations
- static boost::shared_ptr<ModelAPI_Feature> NearestFeature(QPoint thePoint, Handle_V3d_View theView,
- boost::shared_ptr<ModelAPI_Feature> theSketch,
+ static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView,
+ FeaturePtr theSketch,
const std::list<XGUI_ViewerPrs>& theFeatures);
private:
/// Return the distance between the feature and the point
/// \param theFeature feature object
/// \param theX the horizontal coordinate of the point
/// \param theX the vertical coordinate of the point
- static double DistanceToPoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ static double distanceToPoint(FeaturePtr theFeature,
double theX, double theY);
};
#include "PartSetPlugin.h"
#include <ModelAPI_Feature.h>
+/// Part kind
+const std::string PARTSET_PART_KIND("Part");
+
/// part reference attribute
const std::string PART_ATTR_DOC_REF = "PartDocument";
public:
/// Returns the kind of a feature
PARTSETPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "Part"; return MY_KIND;}
+ {static std::string MY_KIND = PARTSET_PART_KIND; return MY_KIND;}
/// Returns to which group in the document must be added feature
PARTSETPLUGIN_EXPORT virtual const std::string& getGroup()
ModelAPI_PluginManager::get()->registerPlugin(this);
}
-boost::shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
+FeaturePtr PartSetPlugin_Plugin::createFeature(string theFeatureID)
{
- if (theFeatureID == "Part") {
- return boost::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_Part);
+ if (theFeatureID == PARTSET_PART_KIND) {
+ return FeaturePtr(new PartSetPlugin_Part);
}
if (theFeatureID == "duplicate") {
- return boost::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_Duplicate);
+ return FeaturePtr(new PartSetPlugin_Duplicate);
}
if (theFeatureID == "remove") {
- return boost::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_Remove);
+ return FeaturePtr(new PartSetPlugin_Remove);
}
// feature of such kind is not found
- return boost::shared_ptr<ModelAPI_Feature>();
+ return FeaturePtr();
}
#include "PartSetPlugin.h"
#include "ModelAPI_Plugin.h"
+#include "ModelAPI_Feature.h"
class PARTSETPLUGIN_EXPORT PartSetPlugin_Plugin: public ModelAPI_Plugin
{
public:
/// Creates the feature object of this plugin by the feature string ID
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+ virtual FeaturePtr createFeature(std::string theFeatureID);
public:
/// Is needed for python wrapping by swig
boost::shared_ptr<ModelAPI_Document> aCurrent;
boost::shared_ptr<PartSetPlugin_Part> a;
for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = aRoot->feature(getGroup(), a, true);
- if (aFeature->getKind() == "Part") {
+ FeaturePtr aFeature = aRoot->feature(getGroup(), a, true);
+ if (aFeature->getKind() == PARTSET_PART_KIND) {
boost::shared_ptr<PartSetPlugin_Part> aPart =
boost::static_pointer_cast<PartSetPlugin_Part>(aFeature);
if (aPart->data()->docRef(PART_ATTR_DOC_REF)->value() == aPManager->currentDocument()) {
#include "PartSetPlugin.h"
#include <ModelAPI_Feature.h>
+/// Extrusion kind
+const std::string PARTSET_REMOVE_KIND("Remove");
+
/**\class PartSetPlugin_Remove
* \ingroup DataModel
* \brief Feature for creation of the new part in PartSet.
public:
/// Returns the kind of a feature
PARTSETPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "Remove"; return MY_KIND;}
+ {static std::string MY_KIND = PARTSET_REMOVE_KIND; return MY_KIND;}
/// Returns to which group in the document must be added feature
PARTSETPLUGIN_EXPORT virtual const std::string& getGroup()
ModelAPI
)
+SET(XML_RESOURCES
+ plugin-Sketch.xml
+)
+
ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
-ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES})
INCLUDE_DIRECTORIES(
../GeomDataAPI
)
-SET(XML_RESOURCES
- plugin-Sketch.xml
-)
-
INSTALL(TARGETS SketchPlugin DESTINATION plugins)
INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
#include "SketchPlugin.h"
#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
+
+/// Arc feature kind
+const std::string SKETCH_ARC_KIND("SketchArc");
/// Central 2D point of the circle which contains the arc
const std::string ARC_ATTR_CENTER("ArcCenter");
public:
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchArc"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_ARC_KIND; 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// 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) {};
+ const FeaturePtr& theFeature) {};
/// Use plugin manager for features creation
SketchPlugin_Arc();
#include "SketchPlugin.h"
#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
+
+/// Circle feature kind
+const std::string SKETCH_CIRCLE_KIND("SketchCircle");
/// 2D point - center of the circle
const std::string CIRCLE_ATTR_CENTER("CircleCenter");
public:
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchCircle"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_CIRCLE_KIND; 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// 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) {};
+ const FeaturePtr& theFeature) {};
/// Use plugin manager for features creation
SketchPlugin_Circle();
#include "SketchPlugin.h"
#include "SketchPlugin_Feature.h"
+#include <SketchPlugin_Sketch.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <list>
class SketchPlugin_Constraint: public SketchPlugin_Feature
{
public:
- /// \brief Returns the kind of a feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchConstraint"; return MY_KIND;}
-
/// \brief 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/** \brief 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) {}
+ const FeaturePtr& theFeature) {}
protected:
/// \brief Use plugin manager for features creation
#include "SketchPlugin.h"
#include "SketchPlugin_Constraint.h"
+#include <SketchPlugin_Sketch.h>
#include <list>
+/// Coincidence constraint kind
+const std::string SKETCH_CONSTRAINT_COINCIDENCE_KIND("SketchConstraintCoincidence");
/** \class SketchPlugin_ConstraintCoincidence
* \ingroup DataModel
public:
/// \brief Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchConstraintCoincidence"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_CONSTRAINT_COINCIDENCE_KIND; return MY_KIND;}
/// \brief 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#include "SketchPlugin.h"
#include "SketchPlugin_Constraint.h"
+#include <SketchPlugin_Sketch.h>
#include <list>
+/// Distance constraint kind
+const std::string SKETCH_CONSTRAINT_DISTANCE_KIND("SketchConstraintDistance");
/** \class SketchPlugin_ConstraintDistance
* \ingroup DataModel
public:
/// \brief Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchConstraintDistance"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_CONSTRAINT_DISTANCE_KIND; return MY_KIND;}
/// \brief 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#include "SketchPlugin.h"
#include "SketchPlugin_Constraint.h"
+#include <SketchPlugin_Sketch.h>
#include <list>
+/// Length constraint kind
+const std::string SKETCH_CONSTRAINT_LENGTH_KIND("SketchConstraintLength");
/** \class SketchPlugin_ConstraintLength
* \ingroup DataModel
public:
/// \brief Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchConstraintLength"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_CONSTRAINT_LENGTH_KIND; return MY_KIND;}
/// \brief 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#define SketchPlugin_ConstraintParallel_HeaderFile
#include "SketchPlugin.h"
+#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Constraint.h"
+/// Parallel constraint kind
+const std::string SKETCH_CONSTRAINT_PARALLEL_KIND("SketchConstraintParallel");
/** \class SketchPlugin_ConstraintParallel
* \ingroup DataModel
public:
/// \brief Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchConstraintParallel"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_CONSTRAINT_PARALLEL_KIND; return MY_KIND;}
/// \brief 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#define SketchPlugin_ConstraintPerpendicular_HeaderFile
#include "SketchPlugin.h"
+#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Constraint.h"
+/// Perpendicular constraint kind
+const std::string SKETCH_CONSTRAINT_PERPENDICULAR_KIND("SketchConstraintPerpendicular");
/** \class SketchPlugin_ConstraintPerpendicular
* \ingroup DataModel
public:
/// \brief Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchConstraintPerpendicular"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_CONSTRAINT_PERPENDICULAR_KIND; return MY_KIND;}
/// \brief 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#define SketchPlugin_ConstraintRadius_HeaderFile
#include "SketchPlugin.h"
+#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Constraint.h"
+/// Radius constraint kind
+const std::string SKETCH_CONSTRAINT_RADIUS_KIND("SketchConstraintRadius");
+
/** \class SketchPlugin_ConstraintRadius
* \ingroup DataModel
public:
/// \brief Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchConstraintRadius"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_CONSTRAINT_RADIUS_KIND; return MY_KIND;}
/// \brief 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::
dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a, true));
if (aSketch) {
- std::list<boost::shared_ptr<ModelAPI_Feature> > aList =
+ std::list<FeaturePtr > aList =
aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
- std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
+ std::list<FeaturePtr >::iterator aSub = aList.begin();
for(; aSub != aList.end(); aSub++) {
if ((*aSub)->data()->isEqual(data())) {
mySketch = aSketch.get();
/// 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;
+ const FeaturePtr& theFeature) = 0;
/// Returns true if this feature must be displayed in the history (top level of Part tree)
SKETCHPLUGIN_EXPORT virtual bool isInHistory() {return false;}
#include "SketchPlugin.h"
#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
#include <list>
+/// Line feature kind
+const std::string SKETCH_LINE_KIND("SketchLine");
+
/// Start 2D point of the line
const std::string LINE_ATTR_START("StartPoint");
/// End 2D point of the line
public:
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchLine"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_LINE_KIND; 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// 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) {};
+ const FeaturePtr& theFeature) {};
/// Use plugin manager for features creation
SketchPlugin_Line();
ModelAPI_PluginManager::get()->registerPlugin(this);
}
-boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Plugin::createFeature(string theFeatureID)
+FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID)
{
- if (theFeatureID == "Sketch") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_Sketch);
+ if (theFeatureID == SKETCH_KIND) {
+ return FeaturePtr(new SketchPlugin_Sketch);
}
- else if (theFeatureID == "SketchPoint") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_Point);
+ else if (theFeatureID == SKETCH_POINT_KIND) {
+ return FeaturePtr(new SketchPlugin_Point);
}
- else if (theFeatureID == "SketchLine") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_Line);
+ else if (theFeatureID == SKETCH_LINE_KIND) {
+ return FeaturePtr(new SketchPlugin_Line);
}
- else if (theFeatureID == "SketchCircle") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_Circle);
+ else if (theFeatureID == SKETCH_CIRCLE_KIND) {
+ return FeaturePtr(new SketchPlugin_Circle);
}
- else if (theFeatureID == "SketchConstraintCoincidence") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintCoincidence);
+ else if (theFeatureID == SKETCH_CONSTRAINT_COINCIDENCE_KIND) {
+ return FeaturePtr(new SketchPlugin_ConstraintCoincidence);
}
- else if (theFeatureID == "SketchConstraintDistance") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintDistance);
+ else if (theFeatureID == SKETCH_CONSTRAINT_DISTANCE_KIND) {
+ return FeaturePtr(new SketchPlugin_ConstraintDistance);
}
- else if (theFeatureID == "SketchConstraintLength") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintLength);
+ else if (theFeatureID == SKETCH_CONSTRAINT_LENGTH_KIND) {
+ return FeaturePtr(new SketchPlugin_ConstraintLength);
}
- else if (theFeatureID == "SketchConstraintParallel") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintParallel);
+ else if (theFeatureID == SKETCH_CONSTRAINT_PARALLEL_KIND) {
+ return FeaturePtr(new SketchPlugin_ConstraintParallel);
}
- else if (theFeatureID == "SketchConstraintPerpendicular") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintPerpendicular);
+ else if (theFeatureID == SKETCH_CONSTRAINT_PERPENDICULAR_KIND) {
+ return FeaturePtr(new SketchPlugin_ConstraintPerpendicular);
}
- else if (theFeatureID == "SketchConstraintRadius") {
- return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintRadius);
+ else if (theFeatureID == SKETCH_CONSTRAINT_RADIUS_KIND) {
+ return FeaturePtr(new SketchPlugin_ConstraintRadius);
}
// feature of such kind is not found
- return boost::shared_ptr<ModelAPI_Feature>();
+ return FeaturePtr();
}
#include "SketchPlugin.h"
#include "ModelAPI_Plugin.h"
+#include "ModelAPI_Feature.h"
class SKETCHPLUGIN_EXPORT SketchPlugin_Plugin: public ModelAPI_Plugin
{
public:
/// Creates the feature object of this plugin by the feature string ID
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+ virtual FeaturePtr createFeature(std::string theFeatureID);
public:
/// Is needed for python wrapping by swig
#define SketchPlugin_Point_HeaderFile
#include "SketchPlugin.h"
+#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Feature.h"
#include <list>
+/// Point feature kind
+const std::string SKETCH_POINT_KIND("SketchPoint");
+
/// Coordinates of the point
const std::string POINT_ATTR_COORD("PointCoordindates");
public:
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "SketchPoint"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_POINT_KIND; 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;}
+ {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// 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) {};
+ const FeaturePtr& theFeature) {};
/// Use plugin manager for features creation
SketchPlugin_Point();
return getPreview();
}
-const void SketchPlugin_Sketch::addSub(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature)
{
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature)->setSketch(this);
data()->reflist(SKETCH_ATTR_FEATURES)->append(theFeature);
#include <GeomAPI_Pnt.h>
#include <list>
+/// Sketch feature kind
+const std::string SKETCH_KIND("Sketch");
+
/// Origin point of the sketcher in 3D space
const std::string SKETCH_ATTR_ORIGIN("Origin");
/// Vector X inside of the sketch plane
public:
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
- {static std::string MY_KIND = "Sketch"; return MY_KIND;}
+ {static std::string MY_KIND = SKETCH_KIND; return MY_KIND;}
/// Returns to which group in the document must be added feature
SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
/// 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);
+ const FeaturePtr& theFeature);
/// Converts a 2D sketch space point into point in 3D space
SKETCHPLUGIN_EXPORT boost::shared_ptr<GeomAPI_Pnt> to3D(
<plugin>
<workbench id="Sketch">
<group id="Basic">
- <feature id="Sketch" nested="SketchLine" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+ <feature id="Sketch" nested="SketchLine SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
<label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/>
<!--icon=":pictures/x_point.png"-->
</feature>
</feature>
<feature id="SketchConstraintCoincidence" title="Points coincidence" tooltip="Create constraint for the coincidence of two points" internal="1"/>
<feature id="SketchConstraintDistance" title="Distance between objects" tooltip="Create constraint for the distance from a point to an object" internal="1"/>
- <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment" internal="1"/>
+ <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment">
+ <label title="Select a line entity on which to calculate lenght" tooltip="Select a line entity on which to calculate lenght"/>
+ </feature>
<feature id="SketchConstraintRadius" title="Radius of a circle or an arc" tooltip="Create constraint for the given radius of a circle or an arc" internal="1"/>
<feature id="SketchConstraintParallel" title="Parallelism of a lines" tooltip="Create constraint defining two parallel lines" internal="1"/>
<feature id="SketchConstraintPerpendicular" title="Orthgonality of a lines" tooltip="Create constraint defining two perpendicular lines" internal="1"/>
#include "SketchSolver_Constraint.h"
#include <SketchSolver_Solver.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintParallel.h>
+#include <SketchPlugin_ConstraintPerpendicular.h>
+#include <SketchPlugin_ConstraintRadius.h>
+
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Data.h>
}
// Constraint for distance between point and another entity
- if (aConstraintKind.compare("SketchConstraintDistance") == 0)
+ if (aConstraintKind.compare(SKETCH_CONSTRAINT_DISTANCE_KIND) == 0)
{
int aNbPoints = 0;
int aNbEntities = 0;
theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
);
if (!anAttr) continue;
- if (anAttr->isFeature())
+ if (anAttr->isFeature() && anAttr->feature())
{ // verify posiible entities
const std::string& aKind = anAttr->feature()->getKind();
- if (aKind.compare("SketchPoint") == 0)
+ if (aKind.compare(SKETCH_POINT_KIND) == 0)
{
myAttributesList[aNbPoints++] = CONSTRAINT_ATTRIBUTES[indAttr];
continue;
}
- else if(aKind.compare("SketchLine") == 0)
+ else if(aKind.compare(SKETCH_LINE_KIND) == 0)
{
// entities are placed starting from CONSTRAINT_ATTR_ENTITY_C attribute
myAttributesList[2 + aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr];
}
// Constraint for the given length of a line
- if (aConstraintKind.compare("SketchConstraintLength") == 0)
+ if (aConstraintKind.compare(SKETCH_CONSTRAINT_LENGTH_KIND) == 0)
{
int aNbLines = 0;
for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++)
theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
);
if (!anAttr) continue;
- if (anAttr->isFeature() && anAttr->feature()->getKind().compare("SketchLine") == 0)
+ if (anAttr->isFeature() && anAttr->feature() &&
+ anAttr->feature()->getKind().compare(SKETCH_LINE_KIND) == 0)
{
myAttributesList[aNbLines++] = CONSTRAINT_ATTRIBUTES[indAttr];
break;
}
// Constraint for two parallel/perpendicular lines
- bool isParallel = (aConstraintKind.compare("SketchConstraintParallel") == 0);
- bool isPerpendicular = (aConstraintKind.compare("SketchConstraintPerpendicular") == 0);
+ bool isParallel = (aConstraintKind.compare(SKETCH_CONSTRAINT_PARALLEL_KIND) == 0);
+ bool isPerpendicular = (aConstraintKind.compare(SKETCH_CONSTRAINT_PERPENDICULAR_KIND) == 0);
if (isParallel || isPerpendicular)
{
int aNbEntities = 2; // lines in SolveSpace constraints should started from CONSTRAINT_ATTR_ENTITY_C attribute
);
if (!anAttr || !anAttr->isFeature()) continue;
const std::string& aKind = anAttr->feature()->getKind();
- if (aKind.compare("SketchLine") == 0)
+ if (aKind.compare(SKETCH_LINE_KIND) == 0)
{
myAttributesList[aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr];
continue;
}
// Constraint for radius of a circle or an arc of circle
- if (aConstraintKind.compare("SketchConstraintRadius") == 0)
+ if (aConstraintKind.compare(SKETCH_CONSTRAINT_RADIUS_KIND) == 0)
{
int aNbEntities = 2; // lines in SolveSpace constraints should started from CONSTRAINT_ATTR_ENTITY_C attribute
for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++)
);
if (!anAttr || !anAttr->isFeature()) continue;
const std::string& aKind = anAttr->feature()->getKind();
- if (aKind.compare("SketchCircle") == 0 || aKind.compare("SketchArc") == 0)
+ if (aKind.compare(SKETCH_CIRCLE_KIND) == 0 || aKind.compare(SKETCH_ARC_KIND) == 0)
{
myAttributesList[aNbEntities++] = CONSTRAINT_ATTRIBUTES[indAttr];
continue;
#include <Model_Events.h>
#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_Circle.h>
if (!aConstrAttr) continue;
// For the length constraint the start and end points of the line should be added to the entities list instead of line
- if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare("SketchConstraintLength") == 0)
+ if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare(SKETCH_CONSTRAINT_LENGTH_KIND) == 0)
{
boost::shared_ptr<ModelAPI_Data> aData = aConstrAttr->feature()->data();
aConstrEnt[indAttr] = changeEntity(aData->attribute(LINE_ATTR_START));
// Purpose: create/update the element defined by the feature affected by any constraint
// ============================================================================
Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
- boost::shared_ptr<ModelAPI_Feature> theEntity)
+ FeaturePtr theEntity)
{
// If the entity is already in the group, try to find it
- std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>::const_iterator
+ std::map<FeaturePtr, Slvs_hEntity>::const_iterator
aEntIter = myEntityFeatMap.find(theEntity);
// defines that the entity already exists
const bool isEntExists = (myEntityFeatMap.find(theEntity) != myEntityFeatMap.end());
const std::string& aFeatureKind = aFeature->getKind();
// Line
- if (aFeatureKind.compare("SketchLine") == 0)
+ if (aFeatureKind.compare(SKETCH_LINE_KIND) == 0)
{
Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(LINE_ATTR_START));
Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(LINE_ATTR_END));
return aLineEntity.h;
}
// Circle
- else if (aFeatureKind.compare("SketchCircle") == 0)
+ else if (aFeatureKind.compare(SKETCH_CIRCLE_KIND) == 0)
{
Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_CENTER));
Slvs_hEntity aRadius = changeEntity(aFeature->data()->attribute(CIRCLE_ATTR_RADIUS));
return aCircleEntity.h;
}
// Arc
- else if (aFeatureKind.compare("SketchArc") == 0)
+ else if (aFeatureKind.compare(SKETCH_ARC_KIND) == 0)
{
Slvs_hEntity aCenter = changeEntity(aFeature->data()->attribute(ARC_ATTR_CENTER));
Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(ARC_ATTR_START));
return anArcEntity.h;
}
// Point (it has low probability to be an attribute of constraint, so it is checked at the end)
- else if (aFeatureKind.compare("SketchPoint") == 0)
+ else if (aFeatureKind.compare(SKETCH_POINT_KIND) == 0)
{
Slvs_hEntity aPoint = changeEntity(aFeature->data()->attribute(POINT_ATTR_COORD));
bool SketchSolver_ConstraintGroup::addWorkplane(
boost::shared_ptr<SketchPlugin_Feature> theSketch)
{
- if (myWorkplane.h || theSketch->getKind().compare("Sketch") != 0)
+ if (myWorkplane.h || theSketch->getKind().compare(SKETCH_KIND) != 0)
return false; // the workplane already exists or the function parameter is not Sketch
mySketch = theSketch;
{
if (!aConstrIter->first->data()->isValid())
{
- if (aConstrIter->first->getKind().compare("SketchConstraintCoincidence") == 0)
+ if (aConstrIter->first->getKind().compare(SKETCH_CONSTRAINT_COINCIDENCE_KIND) == 0)
isCCRemoved = true;
std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::reverse_iterator
aCopyIter = aConstrIter++;
}
else anEntAttrIter++;
}
- std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>::iterator
+ std::map<FeaturePtr, Slvs_hEntity>::iterator
anEntFeatIter = myEntityFeatMap.begin();
while (anEntFeatIter != myEntityFeatMap.end())
{
if (anEntToRemove.find(anEntFeatIter->second) != anEntToRemove.end())
{
- std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>::iterator
+ std::map<FeaturePtr, Slvs_hEntity>::iterator
aRemovedIter = anEntFeatIter;
anEntFeatIter++;
myEntityFeatMap.erase(aRemovedIter);
* \return identifier of changed entity or 0 if entity could not be changed
*/
Slvs_hEntity changeEntity(boost::shared_ptr<ModelAPI_Attribute> theEntity);
- Slvs_hEntity changeEntity(boost::shared_ptr<ModelAPI_Feature> theEntity);
+ Slvs_hEntity changeEntity(FeaturePtr theEntity);
/** \brief Adds or updates a normal in the group
*
myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints
std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>
myEntityAttrMap; ///< The map between "attribute" parameters of constraints and their equivalent SolveSpace entities
- std::map<boost::shared_ptr<ModelAPI_Feature>, Slvs_hEntity>
+ std::map<FeaturePtr, Slvs_hEntity>
myEntityFeatMap; ///< The map between "feature" parameters of constraints and their equivalent SolveSpace entities
// Conincident items
theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED))
{
const Model_FeatureUpdatedMessage* anUpdateMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
- std::set< boost::shared_ptr<ModelAPI_Feature> > aFeatures = anUpdateMsg->features();
+ std::set< FeaturePtr > aFeatures = anUpdateMsg->features();
bool isModifiedEvt = theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED);
if (!isModifiedEvt)
{
- std::set< boost::shared_ptr<ModelAPI_Feature> >::iterator aFeatIter;
+ std::set< FeaturePtr >::iterator aFeatIter;
for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++)
{
// Only sketches and constraints can be added by Create event
const std::string& aFeatureKind = (*aFeatIter)->getKind();
- if (aFeatureKind.compare("Sketch") == 0)
+ if (aFeatureKind.compare(SKETCH_KIND) == 0)
{
boost::shared_ptr<SketchPlugin_Feature> aSketch =
boost::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
const Model_FeatureDeletedMessage* aDeleteMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
const std::set<std::string>& aFeatureGroups = aDeleteMsg->groups();
- // Find "Sketch" in groups. The constraint groups should be updated when an object removed from Sketch
+ // Find SKETCH_KIND in groups. The constraint groups should be updated when an object removed from Sketch
std::set<std::string>::const_iterator aFGrIter;
for (aFGrIter = aFeatureGroups.begin(); aFGrIter != aFeatureGroups.end(); aFGrIter++)
- if (aFGrIter->compare("Sketch") == 0)
+ if (aFGrIter->compare(SKETCH_KIND) == 0)
break;
if (aFGrIter != aFeatureGroups.end())
std::vector<std::string> anAttrList;
const std::string& aFeatureKind = theFeature->getKind();
// Point
- if (aFeatureKind.compare("SketchPoint") == 0)
+ if (aFeatureKind.compare(SKETCH_POINT_KIND) == 0)
anAttrList.push_back(POINT_ATTR_COORD);
// Line
- else if (aFeatureKind.compare("SketchLine") == 0)
+ else if (aFeatureKind.compare(SKETCH_LINE_KIND) == 0)
{
anAttrList.push_back(LINE_ATTR_START);
anAttrList.push_back(LINE_ATTR_END);
}
// Circle
- else if (aFeatureKind.compare("SketchCircle") == 0)
+ else if (aFeatureKind.compare(SKETCH_CIRCLE_KIND) == 0)
{
anAttrList.push_back(CIRCLE_ATTR_CENTER);
anAttrList.push_back(CIRCLE_ATTR_RADIUS);
}
// Arc
- else if (aFeatureKind.compare("SketchArc") == 0)
+ else if (aFeatureKind.compare(SKETCH_ARC_KIND) == 0)
{
anAttrList.push_back(ARC_ATTR_CENTER);
anAttrList.push_back(ARC_ATTR_START);
boost::shared_ptr<ModelAPI_AttributeRefList> aWPFeatures =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aWP->data()->attribute(SKETCH_ATTR_FEATURES));
- std::list< boost::shared_ptr<ModelAPI_Feature> > aFeaturesList = aWPFeatures->list();
- std::list< boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIter;
+ std::list< FeaturePtr > aFeaturesList = aWPFeatures->list();
+ std::list< FeaturePtr >::const_iterator anIter;
for (anIter = aFeaturesList.begin(); anIter != aFeaturesList.end(); anIter++)
if (*anIter == theConstraint)
return aWP; // workplane is found
-INCLUDE(FindCAS)
SET(CMAKE_AUTOMOC ON)
XGUI_ViewerPrs.h
XGUI_PropertyPanel.h
XGUI_ContextMenuMgr.h
+ XGUI_ModuleConnector.h
)
SET(PROJECT_AUTOMOC
XGUI_ViewerPrs.cpp
XGUI_PropertyPanel.cpp
XGUI_ContextMenuMgr.cpp
+ XGUI_ModuleConnector.cpp
)
SET(PROJECT_RESOURCES
${PROJECT_SOURCE_DIR}/src/ModelAPI
${PROJECT_SOURCE_DIR}/src/Model
${PROJECT_SOURCE_DIR}/src/ModuleBase
+ ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
${CAS_INCLUDE_DIRS})
LINK_DIRECTORIES($ENV{PYTHON_LIB_DIR})
#include "XGUI_SelectionMgr.h"
#include "XGUI_Displayer.h"
+#include "PartSetPlugin_Part.h"
+
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
FeaturePtr aFeature = aFeatures.first();
//Process Feature
if (aFeature) {
- if (aFeature->getKind() == "Part") {
+ if (aFeature->getKind() == PARTSET_PART_KIND) {
ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
DocumentPtr aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
if (aMgr->currentDocument() == aFeaDoc)
aMenu->addAction(action("EDIT_CMD"));
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- if (aDisplayer->IsVisible(aFeature))
+ if (aDisplayer->isVisible(aFeature))
aMenu->addAction(action("HIDE_CMD"));
else
aMenu->addAction(action("SHOW_CMD"));
#include <AIS_LocalContext.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
#include <AIS_Shape.hxx>
{
}
-bool XGUI_Displayer::IsVisible(boost::shared_ptr<ModelAPI_Feature> theFeature)
+bool XGUI_Displayer::isVisible(FeaturePtr theFeature)
{
return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end();
}
-void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const bool isUpdateViewer)
-{
-}
+//void XGUI_Displayer::Display(FeaturePtr theFeature,
+// const bool isUpdateViewer)
+//{
+//}
-/*void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
+/*void XGUI_Displayer::Display(FeaturePtr theFeature,
const TopoDS_Shape& theShape, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
aContext->Display(anAIS, Standard_False);
if (isUpdateViewer)
- UpdateViewer();
+ updateViewer();
}*/
-std::list<XGUI_ViewerPrs> XGUI_Displayer::GetSelected(const int theShapeTypeToSkip)
+std::list<XGUI_ViewerPrs> XGUI_Displayer::getSelected(const int theShapeTypeToSkip)
{
- std::set<boost::shared_ptr<ModelAPI_Feature> > aPrsFeatures;
+ std::set<FeaturePtr > aPrsFeatures;
std::list<XGUI_ViewerPrs> aPresentations;
Handle(AIS_InteractiveContext) aContext = AISContext();
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
TopoDS_Shape aShape = aContext->SelectedShape();
+
if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
continue;
- boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
+ FeaturePtr aFeature = getFeature(anIO);
if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
continue;
- aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+ Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
+ aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, anOwner));
aPrsFeatures.insert(aFeature);
}
return aPresentations;
}
-std::list<XGUI_ViewerPrs> XGUI_Displayer::GetHighlighted(const int theShapeTypeToSkip)
+std::list<XGUI_ViewerPrs> XGUI_Displayer::getHighlighted(const int theShapeTypeToSkip)
{
- std::set<boost::shared_ptr<ModelAPI_Feature> > aPrsFeatures;
+ std::set<FeaturePtr > aPrsFeatures;
std::list<XGUI_ViewerPrs> aPresentations;
Handle(AIS_InteractiveContext) aContext = AISContext();
if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
continue;
- boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
+ FeaturePtr aFeature = getFeature(anIO);
if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
continue;
- aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+ aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, NULL));
aPrsFeatures.insert(aFeature);
}
return aPresentations;
}
-void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
+void XGUI_Displayer::erase(FeaturePtr theFeature,
const bool isUpdateViewer)
{
if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
myFeature2AISObjectMap.erase(theFeature);
if (isUpdateViewer)
- UpdateViewer();
+ updateViewer();
}
-void XGUI_Displayer::Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape, const bool isUpdateViewer)
+bool XGUI_Displayer::redisplay(FeaturePtr theFeature,
+ Handle(AIS_InteractiveObject) theAIS,
+ const int theSelectionMode,
+ const bool isUpdateViewer)
{
+ bool isCreated = false;
Handle(AIS_InteractiveContext) aContext = AISContext();
// Open local context if there is no one
if (!aContext->HasOpenedContext()) {
//aContext->SetPixelTolerance(MOUSE_SENSITIVITY_IN_PIXEL);
}
// display or redisplay presentation
- Handle(AIS_Shape) anAIS;
- if (IsVisible(theFeature)) {
- anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
- if (!anAIS.IsNull()) {
- // if the AIS object is displayed in the opened local context in some mode, additional
- // AIS sub objects are created there. They should be rebuild for correct selecting.
- // It is possible to correct it by closing local context before the shape set and opening
- // after. Another workaround to thrown down the selection and reselecting the AIS.
- // If there was a problem here, try the first solution with close/open local context.
- anAIS->Set(theShape);
- anAIS->Redisplay(Standard_True);
- aContext->RecomputeSelectionOnly(anAIS);
- }
+ if (isVisible(theFeature) && !myFeature2AISObjectMap[theFeature].IsNull()) {
+ aContext->RecomputeSelectionOnly(theAIS);
}
else {
- anAIS = new AIS_Shape(theShape);
- myFeature2AISObjectMap[theFeature] = anAIS;
- aContext->Display(anAIS, false);
+ myFeature2AISObjectMap[theFeature] = theAIS;
+ if (theSelectionMode < 0)
+ {
+ aContext->Display(theAIS, false);
+ }
+ else
+ {
+ aContext->Display(theAIS, 0, theSelectionMode, false);
+ }
+ isCreated = true;
}
if (isUpdateViewer)
- UpdateViewer();
+ updateViewer();
+
+ return isCreated;
}
-void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
+void XGUI_Displayer::activateInLocalContext(FeaturePtr theFeature,
const std::list<int>& theModes, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
}
// display or redisplay presentation
Handle(AIS_Shape) anAIS;
- if (IsVisible(theFeature))
+ if (isVisible(theFeature))
anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
// Activate selection of objects from prs
}
if (isUpdateViewer)
- UpdateViewer();
+ updateViewer();
}
-void XGUI_Displayer::StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
+void XGUI_Displayer::stopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_Shape) anAIS;
std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
- boost::shared_ptr<ModelAPI_Feature> aFeature;
+ FeaturePtr aFeature;
for (; anIt != aLast; anIt++) {
aFeature = (*anIt).feature();
- if (IsVisible(aFeature))
+ if (isVisible(aFeature))
anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]);
if (anAIS.IsNull())
continue;
}
}
if (isUpdateViewer)
- UpdateViewer();
+ updateViewer();
}
-void XGUI_Displayer::SetSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer)
+void XGUI_Displayer::setSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
- boost::shared_ptr<ModelAPI_Feature> aFeature;
+ FeaturePtr aFeature;
Handle(AIS_Shape) anAIS;
// we need to unhighligth objects manually in the current local context
for (; anIt != aLast; anIt++) {
aFeature = (*anIt).feature();
- if (IsVisible(aFeature))
+ if (isVisible(aFeature))
anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]);
if (anAIS.IsNull())
continue;
}
if (isUpdateViewer)
- UpdateViewer();
+ updateViewer();
}
-void XGUI_Displayer::EraseAll(const bool isUpdateViewer)
+/*void XGUI_Displayer::EraseAll(const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) ic = AISContext();
}
myFeature2AISObjectMap.clear();
if (isUpdateViewer)
- UpdateViewer();
-}
+ updateViewer();
+}*/
-void XGUI_Displayer::EraseDeletedFeatures(const bool isUpdateViewer)
+void XGUI_Displayer::eraseDeletedFeatures(const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
aFLast = myFeature2AISObjectMap.end();
- std::list<boost::shared_ptr<ModelAPI_Feature>> aRemoved;
+ std::list<FeaturePtr> aRemoved;
for (; aFIt != aFLast; aFIt++)
{
- boost::shared_ptr<ModelAPI_Feature> aFeature = (*aFIt).first;
+ FeaturePtr aFeature = (*aFIt).first;
if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
if (!anAIS.IsNull()) {
}
}
}
- std::list<boost::shared_ptr<ModelAPI_Feature>>::const_iterator anIt = aRemoved.begin(),
+ std::list<FeaturePtr>::const_iterator anIt = aRemoved.begin(),
aLast = aRemoved.end();
for (; anIt != aLast; anIt++) {
myFeature2AISObjectMap.erase(myFeature2AISObjectMap.find(*anIt));
}
if (isUpdateViewer)
- UpdateViewer();
+ updateViewer();
}
-void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
+void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
{
- CloseAllContexts(true);
+ closeAllContexts(true);
}
-Handle(AIS_InteractiveObject) XGUI_Displayer::GetAISObject(
- boost::shared_ptr<ModelAPI_Feature> theFeature) const
+Handle(AIS_InteractiveObject) XGUI_Displayer::getAISObject(
+ FeaturePtr theFeature) const
{
Handle(AIS_InteractiveObject) anIO;
if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end())
return anIO;
}
-boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(Handle(AIS_InteractiveObject) theIO) const
+FeaturePtr XGUI_Displayer::getFeature(Handle(AIS_InteractiveObject) theIO) const
{
- boost::shared_ptr<ModelAPI_Feature> aFeature;
+ FeaturePtr aFeature;
FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
aFLast = myFeature2AISObjectMap.end();
for (; aFIt != aFLast && !aFeature; aFIt++) {
return aFeature;
}
-void XGUI_Displayer::CloseAllContexts(const bool isUpdateViewer)
+void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) ic = AISContext();
if (!ic.IsNull()) {
ic->CloseAllContexts(false);
if (isUpdateViewer)
- UpdateViewer();
+ updateViewer();
}
}
-void XGUI_Displayer::UpdateViewer()
+void XGUI_Displayer::updateViewer()
{
Handle(AIS_InteractiveContext) ic = AISContext();
if (!ic.IsNull())
#include <AIS_InteractiveContext.hxx>
#include <NCollection_List.hxx>
+#include <ModelAPI_Feature.h>
+
#include <XGUI_ViewerPrs.h>
#include <map>
/// Returns the feature visibility state.
/// \param theFeature a feature instance
- bool IsVisible(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ bool isVisible(FeaturePtr theFeature);
/// Display the feature. Obtain the visualized object from the feature.
/// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const bool isUpdateViewer = true);
+ //void Display(FeaturePtr theFeature, const bool isUpdateViewer = true);
/// Display the feature and a shape. This shape would be associated to the given feature
/// \param theFeature a feature instance
/// \param theShape a shape
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- //void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
+ //void Display(FeaturePtr theFeature, const TopoDS_Shape& theShape,
// const bool isUpdateViewer = true);
/// Returns a list of viewer selected presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
- std::list<XGUI_ViewerPrs> GetSelected(const int theShapeTypeToSkip = -1);
+ std::list<XGUI_ViewerPrs> getSelected(const int theShapeTypeToSkip = -1);
/// Returns a list of viewer highlited presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
- std::list<XGUI_ViewerPrs> GetHighlighted(const int theShapeTypeToSkip = -1);
+ std::list<XGUI_ViewerPrs> getHighlighted(const int theShapeTypeToSkip = -1);
/// Display the shape and activate selection of sub-shapes
/// \param theFeature a feature instance
- /// \param theShape a shape
- /// \param theMode a local selection mode
+ /// \param theAIS an AIS object
+ /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ /// \returns true if the presentation is created
+ bool redisplay(FeaturePtr theFeature,
+ Handle(AIS_InteractiveObject) theAIS,
+ const int theSelectionMode, const bool isUpdateViewer = true);
+
+ /// Redisplay the shape and activate selection of sub-shapes
+ /// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape, const bool isUpdateViewer = true);
+ //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
/// Display the shape and activate selection of sub-shapes
/// \param theFeature a feature instance
/// \param theShape a shape
/// \param theMode a list of local selection modes
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void ActivateInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ void activateInLocalContext(FeaturePtr theFeature,
const std::list<int>& theModes, const bool isUpdateViewer = true);
/// Stop the current selection and color the given features to the selection color
/// \param theFeatures a list of features to be disabled
/// \param theToStop the boolean state whether it it stopped or non stopped
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
+ void stopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
const bool isUpdateViewer);
/// Set the features are selected
/// \param theFeatures a list of features to be selected
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void SetSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer);
+ void setSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer);
/// Erase the feature and a shape.
/// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void Erase(boost::shared_ptr<ModelAPI_Feature> theFeature, const bool isUpdateViewer = true);
+ void erase(FeaturePtr theFeature, const bool isUpdateViewer = true);
/// Erase all presentations
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void EraseAll(const bool isUpdateViewer = true);
+ //void EraseAll(const bool isUpdateViewer = true);
/// Erase AIS interactive objects, which has an empty feature in the internal map
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void EraseDeletedFeatures(const bool isUpdateViewer = true);
+ void eraseDeletedFeatures(const bool isUpdateViewer = true);
/// Deactivates selection of sub-shapes
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void CloseLocalContexts(const bool isUpdateViewer = true);
+ void closeLocalContexts(const bool isUpdateViewer = true);
/// Updates the viewer
- void UpdateViewer();
+ void updateViewer();
/// Searches the interactive object by feature
- /// \param feature the feature or NULL if it not visualized
+ /// \param theFeature the feature or NULL if it not visualized
/// \return theIO an interactive object
- Handle(AIS_InteractiveObject) GetAISObject(boost::shared_ptr<ModelAPI_Feature>) const;
+ Handle(AIS_InteractiveObject) getAISObject(FeaturePtr theFeature) const;
protected:
/// Searches the feature by interactive object
/// \param theIO an interactive object
/// \return feature the feature or NULL if it not visualized
- boost::shared_ptr<ModelAPI_Feature> GetFeature(Handle(AIS_InteractiveObject) theIO) const;
+ FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const;
/// Deactivate local selection
/// \param isUpdateViewer the state wether the viewer should be updated immediatelly
- void CloseAllContexts(const bool isUpdateViewer);
+ void closeAllContexts(const bool isUpdateViewer);
/// Returns currently installed AIS_InteractiveContext
Handle(AIS_InteractiveContext) AISContext() const;
protected:
XGUI_Workshop* myWorkshop;
- typedef std::map<boost::shared_ptr<ModelAPI_Feature>, Handle(AIS_InteractiveObject) > FeatureToAISMap;
+ typedef std::map<FeaturePtr, Handle(AIS_InteractiveObject) > FeatureToAISMap;
FeatureToAISMap myFeature2AISObjectMap;
};
--- /dev/null
+// File: XGUI_ModuleConnector.cpp
+// Created: 3 June 2014
+// Author: Vitaly Smetannikov
+
+
+#include "XGUI_ModuleConnector.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_ViewerProxy.h"
+#include "XGUI_SelectionMgr.h"
+
+
+
+XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
+: ModuleBase_IWorkshop(theWorkshop), myWorkshop(theWorkshop)
+{
+ XGUI_SelectionMgr* aSelector = myWorkshop->selector();
+ connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
+}
+
+XGUI_ModuleConnector::~XGUI_ModuleConnector()
+{
+}
+
+Handle(AIS_InteractiveContext) XGUI_ModuleConnector::AISContext() const
+{
+ return myWorkshop->viewer()->AISContext();
+}
+
+
+QFeatureList XGUI_ModuleConnector::selectedFeatures() const
+{
+ return myWorkshop->selector()->selectedFeatures();
+}
\ No newline at end of file
--- /dev/null
+// File: XGUI_ModuleConnector.h
+// Created: 3 June 2014
+// Author: Vitaly Smetannikov
+
+#ifndef XGUI_ModuleConnector_H
+#define XGUI_ModuleConnector_H
+
+
+#include "XGUI.h"
+#include "XGUI_Constants.h"
+
+#include <ModuleBase_IWorkshop.h>
+
+class Handle_AIS_InteractiveContext;
+class XGUI_Workshop;
+
+/**
+* Implementation of IWorkshop interface which provides access to Workshop sevices at module level
+*/
+class XGUI_EXPORT XGUI_ModuleConnector: public ModuleBase_IWorkshop
+{
+ Q_OBJECT
+public:
+ XGUI_ModuleConnector(XGUI_Workshop* theWorkshop);
+
+ virtual ~XGUI_ModuleConnector();
+
+ //! Returns AIS_InteractiveContext from current OCCViewer
+ virtual Handle(AIS_InteractiveContext) AISContext() const;
+
+ //! Returns list of currently selected data objects
+ QFeatureList selectedFeatures() const;
+
+private:
+ XGUI_Workshop* myWorkshop;
+};
+
+#endif
\ No newline at end of file
aLabelWgt->setFrameShape(myTreeView->frameShape());
aLabelWgt->setFrameShadow(myTreeView->frameShadow());
- connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
+ connect(myTreeView, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr)));
connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr)));
myActiveDocLbl->setProperty("OldText", myActiveDocLbl->text());
}
}
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::onSelectionChanged()
+{
+ myFeaturesList = myTreeView->selectedFeatures();
+ emit selectionChanged();
}
\ No newline at end of file
//! Called on Edit command request
void onEditItem();
+ void onSelectionChanged();
+
private:
void closeDocNameEditing(bool toSave);
return myCustomWidget;
}
-void XGUI_PropertyPanel::updateContentWidget(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
{
foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
eachWidget->restoreValue(theFeature);
virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
public slots:
- void updateContentWidget(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ void updateContentWidget(FeaturePtr theFeature);
/// slot to set the focus to the widget visualized an attribute with the given name
/// \param theAttributteName
void onFocusActivated(const std::string& theAttributeName);
}
//******************************************************************
-bool isModelObject(boost::shared_ptr<ModelAPI_Feature> theFeature)
+bool isModelObject(FeaturePtr theFeature)
{
return theFeature && !theFeature->data();
}
//******************************************************************
-std::string featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature)
+std::string featureInfo(FeaturePtr theFeature)
{
std::ostringstream aStream;
if (theFeature)
#include <QString>
#include <QRect>
+#include <ModelAPI_Feature.h>
+
#include <boost/shared_ptr.hpp>
class TopoDS_Shape;
-class ModelAPI_Feature;
/*!
\brief Return directory part of the file path.
Returns true if the feature is a model object
\param theFeature a feature
*/
- bool XGUI_EXPORT isModelObject(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ bool XGUI_EXPORT isModelObject(FeaturePtr theFeature);
/*!
Returns the string presentation of the given feature
\param theFeature a feature
*/
- std::string XGUI_EXPORT featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
}
#endif
XGUI_Workshop* myWorkshop;
};
-#endif
\ No newline at end of file
+#endif
#include "XGUI_ViewerPrs.h"
+#include "SelectMgr_EntityOwner.hxx"
+
XGUI_ViewerPrs::XGUI_ViewerPrs()
{
}
-XGUI_ViewerPrs::XGUI_ViewerPrs(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape)
-: myFeature(theFeature), myShape(theShape)
+XGUI_ViewerPrs::XGUI_ViewerPrs(FeaturePtr theFeature,
+ const TopoDS_Shape& theShape,
+ Handle(SelectMgr_EntityOwner) theOwner)
+: myFeature(theFeature), myShape(theShape), myOwner(theOwner)
{
}
{
}
-void XGUI_ViewerPrs::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void XGUI_ViewerPrs::setFeature(FeaturePtr theFeature)
{
myFeature = theFeature;
}
-void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape)
+FeaturePtr XGUI_ViewerPrs::feature() const
{
- myShape = theShape;
+ return myFeature;
}
-boost::shared_ptr<ModelAPI_Feature> XGUI_ViewerPrs::feature() const
+void XGUI_ViewerPrs::setOwner(Handle(SelectMgr_EntityOwner) theOwner)
{
- return myFeature;
+ myOwner = theOwner;
+}
+
+Handle(SelectMgr_EntityOwner) XGUI_ViewerPrs::owner() const
+{
+ return myOwner;
+}
+
+void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape)
+{
+ myShape = theShape;
}
const TopoDS_Shape& XGUI_ViewerPrs::shape() const
#include <boost/shared_ptr.hpp>
#include <TopoDS_Shape.hxx>
+#include <SelectMgr_EntityOwner.hxx>
-class ModelAPI_Feature;
+#include <ModelAPI_Feature.h>
/**\class XGUI_ViewerPrs
* \ingroup GUI
- * \brief Presentation. Provides container to have feature and the shape
+ * \brief Presentation. Provides container to have feature, shape and/or selection owner.
*/
class XGUI_EXPORT XGUI_ViewerPrs
{
/// Constructor
XGUI_ViewerPrs();
/// Constructor
- XGUI_ViewerPrs(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape);
+ /// \param theFeature a model feature
+ /// \param theShape a viewer shape
+ /// \param theOwner a selection owner
+ XGUI_ViewerPrs(FeaturePtr theFeature,
+ const TopoDS_Shape& theShape,
+ Handle_SelectMgr_EntityOwner theOwner);
/// Destructor
virtual ~XGUI_ViewerPrs();
/// Sets the feature.
/// \param theFeature a feature instance
- void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ void setFeature(FeaturePtr theFeature);
+
+ /// Returns the feature.
+ /// \return a feature instance
+ FeaturePtr feature() const;
+
+ /// Returns the presentation owner
+ /// \param the owner
+ void setOwner(Handle_SelectMgr_EntityOwner theOwner);
+
+ /// Returns the presentation owner
+ /// \return an owner
+ Handle_SelectMgr_EntityOwner owner() const;
/// Sets the shape
/// \param theShape a shape instance
void setShape(const TopoDS_Shape& theShape);
- /// Returns the feature.
- /// \return a feature instance
- boost::shared_ptr<ModelAPI_Feature> feature() const;
-
/// Returns the shape
/// \return a shape instance
const TopoDS_Shape& shape() const;
private:
- boost::shared_ptr<ModelAPI_Feature> myFeature; /// the feature
+ FeaturePtr myFeature; /// the feature
+ Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner
TopoDS_Shape myShape; /// the shape
};
#include "XGUI_ViewerProxy.h"
#include "XGUI_PropertyPanel.h"
#include "XGUI_ContextMenuMgr.h"
+#include "XGUI_ModuleConnector.h"
#include <Model_Events.h>
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
+#include <PartSetPlugin_Part.h>
+
#include <Events_Loop.h>
#include <Events_Error.h>
#include <ModuleBase_Operation.h>
this, SLOT(onContextMenuCommand(const QString&, bool)));
myViewerProxy = new XGUI_ViewerProxy(this);
+
+ myModuleConnector = new XGUI_ModuleConnector(this);
connect(myOperationMgr, SIGNAL(operationStarted()), SLOT(onOperationStarted()));
connect(myOperationMgr, SIGNAL(operationResumed()), SLOT(onOperationStarted()));
bool aHasPart = false;
for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
FeaturePtr aFeature = (*aIt);
- if (aFeature->getKind() == "Part") {
+ if (aFeature->getKind() == PARTSET_PART_KIND) {
aHasPart = true;
break;
}
showPropertyPanel();
- ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation);
+ ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation, myModuleConnector);
QWidget* aContent = myPropertyPanel->contentWidget();
qDeleteAll(aContent->children());
aFactory.createWidget(aContent);
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
aMgr->rootDocument()->startOperation();
foreach (FeaturePtr aFeature, theList) {
- if (aFeature->getKind() == "Part") {
+ if (aFeature->getKind() == PARTSET_PART_KIND) {
DocumentPtr aDoc;
if (!XGUI_Tools::isModelObject(aFeature)) {
aDoc = aFeature->data()->docRef("PartDocument")->value();
class XGUI_ViewerProxy;
class XGUI_PropertyPanel;
class XGUI_ContextMenuMgr;
+class XGUI_ModuleConnector;
class ModuleBase_Operation;
XGUI_ErrorDialog* myErrorDlg;
XGUI_ViewerProxy* myViewerProxy;
XGUI_ContextMenuMgr* myContextMenuMgr;
+ XGUI_ModuleConnector* myModuleConnector;
QString myCurrentDir;
static QMap<QString, QString> myIcons;