mkdir %ROOT_DIR%\build
cd %ROOT_DIR%\build
-cmake %SRC_DIR% -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
+cmake %SRC_DIR% -G "Visual Studio 10" -DPYTHON_EXECUTABLE=%PYTHONHOME%\python_d.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
start "" %MSVC_EXE% NewGEOM.sln
if "%SOLVESPACE_ROOT_DIR%" == "" (
SET SOLVESPACE_ROOT_DIR=%ROOT_DIR%\products\solvespace-2.0
- SET PATH=%SOLVESPACE_ROOT_DIR%\lib;"%PATH%"
)
+SET PATH=%SOLVESPACE_ROOT_DIR%\lib;%PATH%
cd %SALOME_ROOT_DIR%\WORK
call set_env.bat %1
call env_Salome.bat
-SuitApp.exe LightApp --modules=NewGeom
+@SET NewGEOM_ROOT_DIR=%ROOT_DIR%\install
+@SET SalomeAppConfig=%ROOT_DIR%\install\share\salome\resources\newgeom;%GUI_ROOT_DIR%\share\salome\resources\gui
+
+start %PYTHONBIN% "%KERNEL_ROOT_DIR%\bin\salome\envSalome.py" "%PYTHONBIN%" "%KERNEL_ROOT_DIR%\bin\salome\runSalome.py" %*
bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode)
{
- std::string prop = getProperty(theNode, FEATURE_INTERNAL);
+ std::string prop = getProperty(theNode, ATTRIBUTE_INTERNAL);
std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
if (prop.empty() || prop == "false" || prop == "0") {
return false;
const static char* FEATURE_TEXT = "title";
const static char* FEATURE_KEYSEQUENCE = "keysequence";
const static char* FEATURE_NESTED = "nested";
-const static char* FEATURE_INTERNAL = "internal";
-const static char* FEATURE_OBLIGATORY = "obligatory";
+
+const static char* ATTRIBUTE_INTERNAL = "internal";
+const static char* ATTRIBUTE_OBLIGATORY = "obligatory";
+const static char* ATTRIBUTE_CONCEALMENT = "concealment";
// TODO: Rename
const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param";
const static char* ANY_WDG_TOOLTIP = FEATURE_TOOLTIP;
new Events_Message(aChangedEvent, this)));
}
}
+
+void Config_Prop::setDefaultValue(const std::string& theValue)
+{
+ if (theValue != myDefaultValue) {
+ myDefaultValue = theValue;
+ }
+}
* \param theSection - name of section (domain of using) of the property.
* \param theName - name (title) of the value.
* \param theType - type of the value.
- * \param theValue - initial value of the property.
+ * \param theDefaultValue - default value of the property. This is an initial property value
*/
Config_Prop(const std::string& theSection, const std::string& theName,
- const std::string& theTitle, PropType theType, const std::string& theValue)
+ const std::string& theTitle, PropType theType, const std::string& theDefaultValue)
{
mySection = theSection;
myName = theName;
myTitle = theTitle;
myType = theType;
- myValue = theValue;
+ myValue = theDefaultValue;
+ myDefaultValue = theDefaultValue;
}
std::string section() const
}
CONFIG_EXPORT void setValue(const std::string& theValue);
+
+ std::string defaultValue() const
+ {
+ return myDefaultValue;
+ }
+
+ CONFIG_EXPORT void setDefaultValue(const std::string& theValue);
bool operator==(const Config_Prop* theProp) const
{
std::string myTitle;
PropType myType;
std::string myValue;
+ std::string myDefaultValue;
};
typedef std::list<Config_Prop*> Config_Properties;
Config_Properties Config_PropManager::myProps;
-bool Config_PropManager::registerProp(const std::string& theSection, const std::string& theName,
- const std::string& theTitle, Config_Prop::PropType theType,
- const std::string& theValue)
+Config_Prop* Config_PropManager::registerProp(const std::string& theSection, const std::string& theName,
+ const std::string& theTitle, Config_Prop::PropType theType,
+ const std::string& theDefaultValue)
{
Config_Prop* aProp = findProp(theSection, theName);
+
if (aProp) {
+ if (aProp->value() == "") {
+ aProp->setValue(theDefaultValue);
+ }
+ if (aProp->defaultValue() == "") {
+ aProp->setDefaultValue(theDefaultValue);
+ }
if (aProp->type() == Config_Prop::Disabled) {
aProp->setType(theType);
aProp->setTitle(theTitle);
- return true;
}
- return false;
}
- aProp = new Config_Prop(theSection, theName, theTitle, theType, theValue);
- myProps.push_back(aProp);
- return true;
+ else {
+ aProp = new Config_Prop(theSection, theName, theTitle, theType, theDefaultValue);
+ myProps.push_back(aProp);
+ }
+ return aProp;
}
Config_Prop* Config_PropManager::findProp(const std::string& theSection, const std::string& theName)
* \param theSection - name of section (domain of using) of the property.
* \param theName - name (title) of the value.
* \param theType - type of the value.
- * \param theValue - initial value of the property
+ * \param theDefValue - default and initial value of the property
* Returns True if the property succesfully registered
*/
- CONFIG_EXPORT static bool registerProp(const std::string& theSection, const std::string& theName,
- const std::string& theTitle, Config_Prop::PropType theType, const std::string& theValue);
+ CONFIG_EXPORT static Config_Prop* registerProp(const std::string& theSection, const std::string& theName,
+ const std::string& theTitle, Config_Prop::PropType theType, const std::string& theDefValue = "");
CONFIG_EXPORT static Config_Prop* findProp(
const std::string& theSection, const std::string& theName);
boost::shared_ptr<GeomAPI_Shape> aFace =
boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
+ if (!aFace)
+ return;
boost::shared_ptr<GeomAPI_Shape> aContext =
boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->context());
theResultBody->generated(aTopFace, _FIRST_TAG);
}
-}
\ No newline at end of file
+}
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
using namespace std;
void FeaturesPlugin_Group::initAttributes()
{
- data()->addAttribute(FeaturesPlugin_Group::NAME_ID(), ModelAPI_AttributeString::type());
- data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeString::type());
+ //data()->addAttribute(FeaturesPlugin_Group::NAME_ID(), ModelAPI_AttributeString::type());
+ data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::type());
}
void FeaturesPlugin_Group::execute()
{
- AttributeStringPtr aNameAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeString>(
- data()->attribute(FeaturesPlugin_Group::NAME_ID()));
- if (!aNameAttr)
- return;
- std::string aName = aNameAttr->value();
- data()->setName(aName);
+ //AttributeStringPtr aNameAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeString>(
+ // data()->attribute(FeaturesPlugin_Group::NAME_ID()));
+ //if (!aNameAttr)
+ // return;
+ //std::string aName = aNameAttr->value();
+ //data()->setName(aName);
}
return MY_GROUP_ID;
}
/// attribute name of group name
- inline static const std::string& NAME_ID()
- {
- static const std::string MY_GROUP_NAME_ID("group_name");
- return MY_GROUP_NAME_ID;
- }
+ //inline static const std::string& NAME_ID()
+ //{
+ // static const std::string MY_GROUP_NAME_ID("group_name");
+ // return MY_GROUP_NAME_ID;
+ //}
/// attribute name of selected entities list
inline static const std::string& LIST_ID()
{
icon=":icons/sketch.png"
tooltip="Select a face for extrusion"
activate="true"
- shape_types="face wire edge"
+ shape_types="face"
use_subshapes="true"
+ concealment="true"
/>
- <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="0" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
+ <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="1" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
<validator id="GeomValidators_Positive"/>
</doublevalue>
<boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
<source>
- <stringvalue
- id="group_name"
- label="Name"
- tooltip="Name of the group" />
<multi_selector id="group_list"
tooltip="List of selected objects"
type_choice="Vertices Edges Faces Solids" />
GeomAPI_Pln.h
GeomAPI_Shape.h
GeomAPI_Edge.h
- GeomAPI_Wire.h
+ GeomAPI_PlanarEdges.h
GeomAPI_AISObject.h
GeomAPI_IPresentable.h
GeomAPI_Curve.h
GeomAPI_Pln.cpp
GeomAPI_Shape.cpp
GeomAPI_Edge.cpp
- GeomAPI_Wire.cpp
+ GeomAPI_PlanarEdges.cpp
GeomAPI_AISObject.cpp
GeomAPI_Curve.cpp
)
#include <AIS_PerpendicularRelation.hxx>
#include <AIS_RadiusDimension.hxx>
#include <AIS_Shape.hxx>
+#include <AIS_FixRelation.hxx>
const double tolerance = 1e-7;
}
}
+
+void GeomAPI_AISObject::createFixed(boost::shared_ptr<GeomAPI_Shape> theShape,
+ boost::shared_ptr<GeomAPI_Pln> thePlane)
+{
+ Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl<gp_Pln>());
+ Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+ if (anAIS.IsNull()) {
+ Handle(AIS_FixRelation) aFixPrs =
+ new AIS_FixRelation(theShape->impl<TopoDS_Shape>(), aPlane);
+
+ setImpl(new Handle(AIS_InteractiveObject)(aFixPrs));
+ } else {
+ Handle(AIS_PerpendicularRelation) aFixPrs =
+ Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
+ if (!aFixPrs.IsNull()) {
+ aFixPrs->SetFirstShape(theShape->impl<TopoDS_Shape>());
+ aFixPrs->SetPlane(aPlane);
+ aFixPrs->Redisplay(Standard_True);
+ }
+ }
+}
+
+
+
void GeomAPI_AISObject::setColor(const int& theColor)
{
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
boost::shared_ptr<GeomAPI_Shape> theLine2,
boost::shared_ptr<GeomAPI_Pln> thePlane);
+ /** \brief Creates AIS_FixedRelation object for an object
+ * \param[in] theShape the object
+ * \param[in] thePlane the plane which contains the lines
+ */
+ void createFixed(boost::shared_ptr<GeomAPI_Shape> theShape,
+ boost::shared_ptr<GeomAPI_Pln> thePlane);
+
/** \brief Assigns the color for the shape
* \param[in] theColor index of the color
*/
--- /dev/null
+// File: GeomAPI_PlanarEdges.cpp
+// Created: 06 Oct 2014
+// Author: Sergey BELASH
+
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_PlanarEdges.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepTools_WireExplorer.hxx>
+#include <TopExp_Explorer.hxx>
+
+#include <list>
+
+GeomAPI_PlanarEdges::GeomAPI_PlanarEdges() : GeomAPI_Shape()
+{
+ TopoDS_Compound aBigWireImpl;
+ BRep_Builder aBuilder;
+ aBuilder.MakeCompound(aBigWireImpl);
+ this->setImpl(new TopoDS_Shape(aBigWireImpl));
+}
+
+void GeomAPI_PlanarEdges::addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge)
+{
+ const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
+ if (anEdge.ShapeType() != TopAbs_EDGE)
+ return;
+ TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+ BRep_Builder aBuilder;
+ aBuilder.Add(aWire, anEdge);
+}
+
+std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_PlanarEdges::getEdges()
+{
+ TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+ //BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
+ TopExp_Explorer aWireExp(aShape, TopAbs_EDGE);
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
+ for (; aWireExp.More(); aWireExp.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
+ anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
+ aResult.push_back(anEdge);
+ }
+ return aResult;
+}
--- /dev/null
+// File: GeomAPI_PlanarEdges.hxx
+// Created: 24 Jul 2014
+// Author: Artem ZHIDKOV
+
+#ifndef GEOMAPI_WIRE_H_
+#define GEOMAPI_WIRE_H_
+
+#include "GeomAPI.h"
+#include "GeomAPI_Edge.h"
+#include "GeomAPI_Pnt.h"
+#include "GeomAPI_Dir.h"
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
+
+/**\class GeomAPI_PlanarEdges
+ * \ingroup DataModel
+ * \brief Interface to the edge object
+ */
+
+class GeomAPI_PlanarEdges : public GeomAPI_Shape
+{
+ public:
+ /// Creation of empty (null) shape
+ GEOMAPI_EXPORT GeomAPI_PlanarEdges();
+
+ GEOMAPI_EXPORT virtual bool isVertex() const
+ {
+ return false;
+ }
+
+ /// Returns whether the shape is an edge
+ GEOMAPI_EXPORT virtual bool isEdge() const
+ {
+ return false;
+ }
+
+ GEOMAPI_EXPORT void addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge);
+ GEOMAPI_EXPORT std::list<boost::shared_ptr<GeomAPI_Shape> > getEdges();
+
+ /// Returns True if the wire is defined in a plane
+ GEOMAPI_EXPORT bool hasPlane() const { return myOrigin && myNorm && myDirX && myDirY; }
+
+ /// Set/Get origin point
+ GEOMAPI_EXPORT void setOrigin(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin)
+ { myOrigin = theOrigin; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Pnt> origin() const { return myOrigin; }
+
+ /// Set/Get X direction vector
+ GEOMAPI_EXPORT void setDirX(const boost::shared_ptr<GeomAPI_Dir>& theDirX) { myDirX = theDirX; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirX() const { return myDirX; }
+
+ /// Set/Get Y direction vector
+ GEOMAPI_EXPORT void setDirY(const boost::shared_ptr<GeomAPI_Dir>& theDirY) { myDirY = theDirY; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirY() const { return myDirY; }
+
+ /// Set/Get Normal direction vector
+ GEOMAPI_EXPORT void setNorm(const boost::shared_ptr<GeomAPI_Dir>& theNorm) { myNorm = theNorm; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> norm() const { return myNorm; }
+
+private:
+ boost::shared_ptr<GeomAPI_Pnt> myOrigin;
+ boost::shared_ptr<GeomAPI_Dir> myDirX;
+ boost::shared_ptr<GeomAPI_Dir> myDirY;
+ boost::shared_ptr<GeomAPI_Dir> myNorm;
+};
+
+#endif
+
};
+<<<<<<< HEAD
typedef std::list<boost::shared_ptr<GeomAPI_Shape>> ListOfShape;
+=======
+//! Pointer on attribute object
+typedef boost::shared_ptr<GeomAPI_Shape> GeomShapePtr;
+
+>>>>>>> 01cda8378dd1cff425f88438e8c0085122ed7495
#endif
+++ /dev/null
-// File: GeomAPI_Wire.cpp
-// Created: 06 Oct 2014
-// Author: Sergey BELASH
-
-#include <GeomAPI_Interface.h>
-#include <GeomAPI_Wire.h>
-
-#include <Standard_TypeDef.hxx>
-#include <TopAbs_ShapeEnum.hxx>
-
-#include <TopoDS.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Wire.hxx>
-#include <BRep_Builder.hxx>
-#include <BRepTools_WireExplorer.hxx>
-
-#include <list>
-
-GeomAPI_Wire::GeomAPI_Wire() : GeomAPI_Shape()
-{
- TopoDS_Compound aBigWireImpl;
- BRep_Builder aBuilder;
- aBuilder.MakeCompound(aBigWireImpl);
- this->setImpl(new TopoDS_Shape(aBigWireImpl));
-}
-
-void GeomAPI_Wire::addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge)
-{
- const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
- if (anEdge.ShapeType() != TopAbs_EDGE)
- return;
- TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
- BRep_Builder aBuilder;
- aBuilder.Add(aWire, anEdge);
-}
-
-std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_Wire::getEdges()
-{
- TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
- BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
- std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
- for (; aWireExp.More(); aWireExp.Next()) {
- boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
- anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
- aResult.push_back(anEdge);
- }
- return aResult;
-}
+++ /dev/null
-// File: GeomAPI_Wire.hxx
-// Created: 24 Jul 2014
-// Author: Artem ZHIDKOV
-
-#ifndef GEOMAPI_WIRE_H_
-#define GEOMAPI_WIRE_H_
-
-#include <GeomAPI.h>
-#include <GeomAPI_Edge.h>
-
-#include <boost/smart_ptr/shared_ptr.hpp>
-
-#include <list>
-
-/**\class GeomAPI_Wire
- * \ingroup DataModel
- * \brief Interface to the edge object
- */
-
-class GEOMAPI_EXPORT GeomAPI_Wire : public GeomAPI_Shape
-{
- public:
- /// Creation of empty (null) shape
- GeomAPI_Wire();
-
- virtual bool isVertex() const
- {
- return false;
- }
-
- /// Returns whether the shape is an edge
- virtual bool isEdge() const
- {
- return false;
- }
-
- void addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge);
- std::list<boost::shared_ptr<GeomAPI_Shape> > getEdges();
-
-};
-
-#endif
-
// Author: Artem ZHIDKOV
#include <GeomAlgoAPI_SketchBuilder.h>
-#include <GeomAPI_Wire.h>
+#include <GeomAPI_PlanarEdges.h>
#include <set>
const boost::shared_ptr<GeomAPI_Shape>& theWire,
std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces)
{
- boost::shared_ptr<GeomAPI_Wire> aWire = boost::dynamic_pointer_cast<GeomAPI_Wire>(theWire);
+ boost::shared_ptr<GeomAPI_PlanarEdges> aWire = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(theWire);
if(!aWire)
return;
// Filter wires, return only faces.
Model_AttributeString.h
Model_AttributeInteger.h
Model_AttributeSelection.h
+ Model_AttributeSelectionList.h
Model_Events.h
Model_Update.h
Model_Validator.h
Model_AttributeString.cpp
Model_AttributeInteger.cpp
Model_AttributeSelection.cpp
+ Model_AttributeSelectionList.cpp
Model_Events.cpp
Model_Update.cpp
Model_Validator.cpp
Config
GeomData
GeomAPI
+ GeomAlgoAPI
${CAS_OCAF}
${CAS_TKCAF}
${CAS_SHAPE}
../Config
../GeomData
../GeomDataAPI
+ ../GeomAlgoAPI
../GeomAPI
${CAS_INCLUDE_DIRS}
)
owner()->data()->sendAttributeUpdated(this);
}
-int Model_AttributeRefList::size()
+int Model_AttributeRefList::size() const
{
return myRef->Extent();
}
return aResult;
}
+ObjectPtr Model_AttributeRefList::object(const int theIndex) const
+{
+ boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(
+ owner()->document());
+ if (aDoc) {
+ const TDF_LabelList& aList = myRef->List();
+ int anIndex = 0;
+ for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) {
+ if (anIndex == theIndex)
+ return aDoc->object(aLIter.Value());
+ }
+ }
+ return ObjectPtr();
+}
+
Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
{
myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
MODEL_EXPORT virtual void remove(ObjectPtr theObject);
/// Returns number of features in the list
- MODEL_EXPORT virtual int size();
+ MODEL_EXPORT virtual int size() const;
/// Returns the list of features
MODEL_EXPORT virtual std::list<ObjectPtr> list();
+ /// Returns the list of features
+ MODEL_EXPORT virtual ObjectPtr object(const int theIndex) const;
+
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel);
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
- if (aDoc) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
myRef->Set(aData->label().Father()); // references to the feature label
- boost::shared_dynamic_cast<Model_Document>(owner()->document())->objectIsReferenced(theObject);
owner()->data()->sendAttributeUpdated(this);
}
if (owner()) {
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
- if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
}
}
}
ModelAPI_AttributeReference::setObject(theObject);
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
- if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
}
}
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
TDF_Label aLab = myRef->Get();
- if (aDoc && !aLab.IsNull()) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
}
#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_CompositeFeature.h>
#include <GeomAPI_Shape.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAlgoAPI_SketchBuilder.h>
+#include <Events_Error.h>
#include <TNaming_Selector.hxx>
#include <TNaming_NamedShape.hxx>
+#include <TNaming_Tool.hxx>
+#include <TNaming_Builder.hxx>
#include <TopoDS_Shape.hxx>
+#include <TDataStd_IntPackedMap.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TDF_LabelMap.hxx>
+#include <BRep_Tool.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <TColStd_MapOfTransient.hxx>
using namespace std;
if (!isOldContext)
myRef.setValue(theContext);
- // perform the selection
- TNaming_Selector aSel(myRef.myRef->Label());
- TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
- TopoDS_Shape aContext;
+ if (theContext->groupName() == ModelAPI_ResultBody::group())
+ selectBody(theContext, theSubShape);
+ else if (theContext->groupName() == ModelAPI_ResultConstruction::group())
+ selectConstruction(theContext, theSubShape);
- ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
- if (aBody)
- aContext = aBody->shape()->impl<TopoDS_Shape>();
- else {
- ResultConstructionPtr aConstr = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
- if (aConstr)
- aContext = aConstr->shape()->impl<TopoDS_Shape>();
- else
- throw std::invalid_argument("a result with shape is expected");
- }
- aSel.Select(aNewShape, aContext);
myIsInitialized = true;
-
owner()->data()->sendAttributeUpdated(this);
}
boost::shared_ptr<GeomAPI_Shape> aResult;
if (myIsInitialized) {
Handle(TNaming_NamedShape) aSelection;
- if (myRef.myRef->Label().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
+ if (selectionLabel().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
TopoDS_Shape aSelShape = aSelection->Get();
- aResult->setImpl(&aSelShape);
+ aResult = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
+ aResult->setImpl(new TopoDS_Shape(aSelShape));
}
}
return aResult;
void Model_AttributeSelection::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
{
+ ModelAPI_AttributeSelection::setObject(theObject);
myRef.setObject(theObject);
}
+
+bool Model_AttributeSelection::update()
+{
+ ResultPtr aContext = context();
+ if (!aContext) return false;
+ if (aContext->groupName() == ModelAPI_ResultBody::group()) {
+ // body: just a named shape, use selection mechanism from OCCT
+ TNaming_Selector aSelector(selectionLabel());
+ TDF_LabelMap aScope; // empty means the whole document
+ return aSelector.Solve(aScope) == Standard_True;
+
+ } else if (aContext->groupName() == ModelAPI_ResultConstruction::group()) {
+ // construction: identification by the results indexes, recompute faces and
+ // take the face that more close by the indexes
+ boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext)->shape());
+ if (aWirePtr && aWirePtr->hasPlane()) {
+ // If this is a wire with plane defined thin it is a sketch-like object
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
+ GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
+ aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces);
+ if (aFaces.empty()) // no faces, update can not work correctly
+ return false;
+ // if there is no edges indexes, any face can be used: take the first
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>(owner()->data());
+ TDF_Label aLab = aData->label();
+ Handle(TDataStd_IntPackedMap) aSubIds;
+ boost::shared_ptr<GeomAPI_Shape> aNewSelected;
+ if (!aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0) {
+ aNewSelected = *(aFaces.begin());
+ } else { // searching for most looks-like initial face by the indexes
+ // prepare edges of the current resut for the fast searching
+ TColStd_MapOfTransient allCurves;
+ FeaturePtr aContextFeature = owner()->document()->feature(aContext);
+ CompositeFeaturePtr aComposite =
+ boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
+ if (!aComposite) // must be composite at least for the current implementation
+ return false;
+ const int aSubNum = aComposite->numberOfSubs();
+ for(int a = 0; a < aSubNum; a++) {
+ if (aSubIds->Contains(aComposite->subFeatureId(a))) {
+ FeaturePtr aSub = aComposite->subFeature(a);
+ const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResults.cbegin();
+ for(; aRes != aResults.cend(); aRes++) {
+ ResultConstructionPtr aConstr =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
+ if (aConstr->shape() && aConstr->shape()->isEdge()) {
+ const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
+ TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
+ if (!anEdge.IsNull()) {
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ allCurves.Add(aCurve);
+ }
+ }
+ }
+ }
+ }
+ // iterate new result faces and searching for these edges
+ std::list<boost::shared_ptr<GeomAPI_Shape> >::iterator aFacesIter = aFaces.begin();
+ double aBestFound = 0; // best percentage of found edges
+ for(; aFacesIter != aFaces.end(); aFacesIter++) {
+ int aFound = 0, aNotFound = 0;
+ TopExp_Explorer anEdgesExp((*aFacesIter)->impl<TopoDS_Shape>(), TopAbs_EDGE);
+ for(; anEdgesExp.More(); anEdgesExp.Next()) {
+ TopoDS_Edge anEdge = TopoDS::Edge(anEdgesExp.Current());
+ if (!anEdge.IsNull()) {
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ if (allCurves.Contains(aCurve)) {
+ aFound++;
+ } else {
+ aNotFound++;
+ }
+ }
+ }
+ if (aFound + aNotFound != 0) {
+ double aPercentage = double(aFound) / double(aFound + aNotFound);
+ if (aPercentage > aBestFound) {
+ aBestFound = aPercentage;
+ aNewSelected = *aFacesIter;
+ }
+ }
+ }
+ if (aNewSelected) { // store this new selection
+ selectConstruction(aContext, aNewSelected);
+ return true;
+ }
+ }
+ }
+ }
+ return false; // unknown case
+}
+
+
+void Model_AttributeSelection::selectBody(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ // perform the selection
+ TNaming_Selector aSel(selectionLabel());
+ TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
+ TopoDS_Shape aContext;
+
+ ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
+ if (aBody)
+ aContext = aBody->shape()->impl<TopoDS_Shape>();
+ else {
+ ResultConstructionPtr aConstr = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
+ if (aConstr) {
+ aContext = aConstr->shape()->impl<TopoDS_Shape>();
+ } else {
+ Events_Error::send("A result with shape is expected");
+ return;
+ }
+ }
+ aSel.Select(aNewShape, aContext);
+}
+
+void Model_AttributeSelection::selectConstruction(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ FeaturePtr aContextFeature = owner()->document()->feature(theContext);
+ CompositeFeaturePtr aComposite =
+ boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
+ if (!aComposite || aComposite->numberOfSubs() == 0) {
+ return; // saving of context is enough: result construction contains exactly the needed shape
+ }
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(owner()->data());
+ TDF_Label aLab = aData->label();
+ // identify the reuslts of sub-object of the composite by edges
+ const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
+ TColStd_MapOfTransient allCurves;
+ for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) {
+ TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExp.Current());
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ allCurves.Add(aCurve);
+ }
+ // iterate and store the result ids of sub-elements
+ Handle(TDataStd_IntPackedMap) aRefs = TDataStd_IntPackedMap::Set(aLab);
+ const int aSubNum = aComposite->numberOfSubs();
+ for(int a = 0; a < aSubNum; a++) {
+ FeaturePtr aSub = aComposite->subFeature(a);
+ const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResults.cbegin();
+ // there may be many shapes (circle and center): register if at least one is in selection
+ for(; aRes != aResults.cend(); aRes++) {
+ ResultConstructionPtr aConstr =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
+ if (aConstr->shape() && aConstr->shape()->isEdge()) {
+ const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
+ TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
+ if (!anEdge.IsNull()) {
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ if (allCurves.Contains(aCurve)) {
+ boost::shared_ptr<Model_Data> aSubData = boost::dynamic_pointer_cast<Model_Data>(aSub->data());
+ TDF_Label aSubLab = aSubData->label();
+ aRefs->Add(aComposite->subFeatureId(a));
+ }
+ }
+ }
+ }
+ }
+ // store the selected as primitive
+ TNaming_Builder aBuilder(selectionLabel());
+ aBuilder.Generated(aSubShape);
+}
+
+TDF_Label Model_AttributeSelection::selectionLabel()
+{
+ return myRef.myRef->Label().FindChild(1);
+}
/// Returns the context of the selection (the whole shape owner)
MODEL_EXPORT virtual ResultPtr context();
+ /// Sets the feature object
MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
+ /// Updates the underlied selection due to the changes in the referenced objects
+ /// \returns false if update is failed
+ MODEL_EXPORT virtual bool update();
+
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
+ /// Performs the selection for the body result (TNaming Selection)
+
+ /// Performs the selection for the body result (TNaming selection)
+ virtual void selectBody(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+ /// Performs the selection for the construction result (selection by index)
+ virtual void selectConstruction(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+ /// Returns the label where TNaming_Selection results are stored
+ /// Note: there must be no attributes stored at the same label because Selector clears this lab
+ TDF_Label selectionLabel();
friend class Model_Data;
+ friend class Model_AttributeSelectionList;
};
#endif
--- /dev/null
+// File: Model_AttributeSelectionList.h
+// Created: 22 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#include "Model_AttributeSelectionList.h"
+#include "Model_AttributeSelection.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+
+#include <TDF_ChildIterator.hxx>
+
+using namespace std;
+
+void Model_AttributeSelectionList::append(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ int aNewTag = mySize->Get() + 1;
+ TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
+
+ boost::shared_ptr<Model_AttributeSelection> aNewAttr =
+ boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
+ if (owner()) {
+ aNewAttr->setObject(owner());
+ }
+ mySubs.push_back(aNewAttr);
+ mySize->Set(aNewTag);
+ aNewAttr->setValue(theContext, theSubShape);
+ owner()->data()->sendAttributeUpdated(this);
+}
+
+int Model_AttributeSelectionList::size()
+{
+ return mySize->Get();
+}
+
+boost::shared_ptr<ModelAPI_AttributeSelection>
+ Model_AttributeSelectionList::value(const int theIndex)
+{
+ return mySubs[theIndex];
+}
+
+void Model_AttributeSelectionList::clear()
+{
+ if (!mySubs.empty()) {
+ mySize->Set(0);
+ mySubs.clear();
+ TDF_ChildIterator aSubIter(mySize->Label());
+ for(; aSubIter.More(); aSubIter.Next()) {
+ aSubIter.Value().ForgetAllAttributes(Standard_True);
+ }
+ owner()->data()->sendAttributeUpdated(this);
+ }
+}
+
+Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
+{
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
+ if (!myIsInitialized) {
+ mySize = TDataStd_Integer::Set(theLabel, 0);
+ } else { // recollect mySubs
+ int aNum = mySize->Get();
+ TDF_ChildIterator aSubIter(theLabel);
+ for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) {
+ TDF_Label aChildLab = aSubIter.Value();
+ boost::shared_ptr<Model_AttributeSelection> aNewAttr =
+ boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
+ if (owner())
+ aNewAttr->setObject(owner());
+ mySubs.push_back(aNewAttr);
+ }
+ }
+}
+
+void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+{
+ ModelAPI_AttributeSelectionList::setObject(theObject);
+ std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
+ for(; aSubIter != mySubs.end(); aSubIter++) {
+ (*aSubIter)->setObject(theObject);
+ }
+}
--- /dev/null
+// File: Model_AttributeSelectionList.h
+// Created: 22 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_AttributeSelectionList_H_
+#define Model_AttributeSelectionList_H_
+
+#include "Model.h"
+#include "Model_AttributeSelection.h"
+#include <ModelAPI_AttributeSelectionList.h>
+#include <TDataStd_Integer.hxx>
+#include <vector>
+
+/**\class Model_AttributeSelectionList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to the sub-shapes with
+ * possibility to manage them.
+ */
+
+class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
+{
+ Handle(TDataStd_Integer) mySize; ///< Contains size of this list
+ std::vector<boost::shared_ptr<Model_AttributeSelection> > mySubs; /// the selection attributes
+public:
+ /// Adds the new reference to the end of the list
+ MODEL_EXPORT virtual void append(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+ /// Returns the number ofselection attributes in the list
+ MODEL_EXPORT virtual int size();
+
+ /// Returns the attribute selection by the index (zero based)
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex);
+
+ /// Returns all attributes
+ MODEL_EXPORT virtual void clear();
+
+ /// Sets the feature object
+ MODEL_EXPORT virtual void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject);
+
+protected:
+ /// Objects are created for features automatically
+ MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
+ /// Performs the selection for the body result (TNaming Selection)
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_AttributeBoolean.h>
#include <Model_AttributeString.h>
#include <Model_AttributeSelection.h>
+#include <Model_AttributeSelectionList.h>
#include <Model_Events.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
anAttr = new Model_AttributeReference(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeSelection::type()) {
anAttr = new Model_AttributeSelection(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeSelectionList::type()) {
+ anAttr = new Model_AttributeSelectionList(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeRefAttr::type()) {
anAttr = new Model_AttributeRefAttr(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeRefList::type()) {
boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::document(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeDocRef>();
boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeDouble>();
boost::shared_ptr<ModelAPI_AttributeInteger> Model_Data::integer(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeInteger>();
boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeString> Model_Data::string(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeString>();
boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeReference>();
boost::shared_ptr<ModelAPI_AttributeSelection> Model_Data::selection(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeSelection>();
return aRes;
}
+boost::shared_ptr<ModelAPI_AttributeSelectionList>
+ Model_Data::selectionList(const std::string& theID)
+{
+ std::map<std::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_AttributeSelectionList>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeSelectionList> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
+
boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeRefAttr>();
boost::shared_ptr<ModelAPI_AttributeRefList> Model_Data::reflist(const std::string& theID)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeRefList>();
const std::string& Model_Data::id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr)
{
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr =
+ myAttrs.begin();
for (; anAttr != myAttrs.end(); anAttr++) {
if (anAttr->second == theAttr)
return anAttr->first;
return myLab.IsAttribute(kMustBeUpdatedGUID) == Standard_True;
}
-bool Model_Data::referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+int Model_Data::featureId() const
{
- // collect results of this feature first to check references quickly in the cycle
- std::set<ObjectPtr> aFeatureObjs;
- aFeatureObjs.insert(theFeature);
- std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter =
- theFeature->results().cbegin();
- for(; aRIter != theFeature->results().cend(); aRIter++) {
- if (*aRIter)
- aFeatureObjs.insert(*aRIter);
- }
+ return myLab.Father().Tag(); // tag of the feature label
+}
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
- myAttrs.begin();
- for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
- if (anAttrsIter->second->attributeType() == ModelAPI_AttributeRefAttr::type()) {
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttrsIter->second);
- if (aRefAttr && aRefAttr->isObject()) { // check referenced object
- if (aFeatureObjs.find(aRefAttr->object()) != aFeatureObjs.end())
- return true;
- } else { // check object of referenced attribute
- boost::shared_ptr<ModelAPI_Attribute> anAttr = aRefAttr->attr();
- if (anAttr && aFeatureObjs.find(anAttr->owner()) != aFeatureObjs.end())
- return true;
- }
- } else if (anAttrsIter->second->attributeType() == ModelAPI_AttributeReference::type()) {
- boost::shared_ptr<ModelAPI_AttributeReference> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttrsIter->second);
- if (aFeatureObjs.find(aRef->value()) != aFeatureObjs.end()) {
- return true;
+void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID)
+{
+ // TODO: the concealment state update
+ myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
+}
+
+void Model_Data::referencesToObjects(
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs)
+{
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+ std::list<ObjectPtr> aReferenced; // not inside of cycle to avoid excess memory menagement
+ for(; anAttr != myAttrs.end(); anAttr++) {
+ std::string aType = anAttr->second->attributeType();
+ if (aType == ModelAPI_AttributeReference::type()) { // reference to object
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeReference>(anAttr->second);
+ aReferenced.push_back(aRef->value());
+ theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+ } else if (aType == ModelAPI_AttributeRefAttr::type()) { // reference to attribute or object
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(anAttr->second);
+ aReferenced.push_back(aRef->isObject() ? aRef->object() : aRef->attr()->owner());
+ } else if (aType == ModelAPI_AttributeRefList::type()) { // list of references
+ aReferenced = boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr->second)->list();
+ } else if (aType == ModelAPI_AttributeSelection::type()) { // selection attribute
+ boost::shared_ptr<ModelAPI_AttributeSelection> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeSelection>(anAttr->second);
+ aReferenced.push_back(aRef->context());
+ theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+ } else if (aType == ModelAPI_AttributeSelectionList::type()) { // list of selection attributes
+ boost::shared_ptr<ModelAPI_AttributeSelectionList> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeSelectionList>(anAttr->second);
+ for(int a = aRef->size() - 1; a >= 0; a--) {
+ aReferenced.push_back(aRef->value(a)->context());
}
+ } else
+ continue; // nothing to do, not reference
+
+ if (!aReferenced.empty()) {
+ theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+ aReferenced.clear();
}
}
- return false;
}
#include <map>
#include <list>
#include <string>
+#include <set>
class ModelAPI_Attribute;
/// needed here to emit signal that object changed on change of the attribute
ObjectPtr myObject;
+ /// List of attributes referenced to owner (updated only during the transaction change)
+ std::set<AttributePtr> myRefsToMe;
+
Model_Data();
/// Returns label of this feature
}
friend class Model_Document;
+ friend class Model_Update;
friend class Model_AttributeReference;
friend class Model_AttributeRefAttr;
friend class Model_AttributeRefList;
+ friend class Model_AttributeSelection;
public:
/// Returns the name of the feature visible by the user in the object browser
/// Returns the attribute that contains selection to a shape
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection>
selection(const std::string& theID);
+ /// Returns the attribute that contains selection to a shape
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelectionList>
+ selectionList(const std::string& theID);
/// Returns the attribute that contains reference to an attribute of a feature
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
refattr(const std::string& theID);
/// Returns true if feature must be updated (re-executed) on rebuild
MODEL_EXPORT virtual bool mustBeUpdated();
- /// Returns true if this data attributes are referenced to the given feature or its results
- MODEL_EXPORT virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature);
+ /// Returns the identifier of feature-owner, unique in this document
+ MODEL_EXPORT virtual int featureId() const;
+
+private:
+ // removes all information about back references
+ inline void eraseBackReferences() {myRefsToMe.clear();}
+ // adds a back reference (with identifier which attribute references to this object
+ void addBackReference(FeaturePtr theFeature, std::string theAttrID);
+ // returns all objects referenced to this
+ const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
+ // returns all references by attributes of this data
+ // \param the returned list of pairs: id of referenced attribute and list of referenced objects
+ void referencesToObjects(std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
};
#endif
#include <Model_ResultPart.h>
#include <Model_ResultConstruction.h>
#include <Model_ResultBody.h>
+#include <ModelAPI_Validator.h>
#include <Events_Loop.h>
#include <Events_Error.h>
myDoc->SetUndoLimit(UNDO_LIMIT);
// to avoid the problem that feature is created in the current, not this, document
Model_Session::get()->setActiveDocument(anApp->getDocument(myID));
- synchronizeFeatures();
+ synchronizeFeatures(false, true);
}
return !isError;
}
if (!myDoc->HasOpenCommand() && myNestedNum != -1)
boost::static_pointer_cast<Model_Session>(Model_Session::get())
->setCheckTransactions(false); // for nested transaction commit
+ synchronizeBackRefs();
Events_Loop* aLoop = Events_Loop::loop();
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
if (!myDoc->HasOpenCommand() && myNestedNum != -1)
boost::static_pointer_cast<Model_Session>(Model_Session::get())
myNestedNum = -1;
myDoc->AbortCommand();
}
- synchronizeFeatures(true);
+ synchronizeFeatures(true, false); // references were not changed since transaction start
// abort for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
myNestedNum--;
if (!myIsEmptyTr[myTransactionsAfterSave])
myDoc->Undo();
- synchronizeFeatures(true);
+ synchronizeFeatures(true, true);
// undo for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
if (!myIsEmptyTr[myTransactionsAfterSave])
myDoc->Redo();
myTransactionsAfterSave++;
- synchronizeFeatures(true);
+ synchronizeFeatures(true, true);
// redo for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
// check the feature: it must have no depended objects on it
std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
for(; aResIter != theFeature->results().cend(); aResIter++) {
- if (myConcealedResults.find(*aResIter) != myConcealedResults.end()) {
- Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
- return;
- }
- }
- NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator anObjIter(myObjs);
- for(; anObjIter.More(); anObjIter.Next()) {
- DataPtr aData = anObjIter.Value()->data();
- if (aData->referencesTo(theFeature)) {
- Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>((*aResIter)->data());
+ if (aData && !aData->refsToMe().empty()) {
+ Events_Error::send(
+ "Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
return;
}
}
// erase all attributes under the label of feature
aFeatureLabel.ForgetAllAttributes();
// remove it from the references array
- RemoveFromRefArray(featuresLabel(), aFeatureLabel);
-
+ if (theFeature->isInHistory()) {
+ RemoveFromRefArray(featuresLabel(), aFeatureLabel);
+ }
// event: feature is deleted
ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
- /* this is in "erase"
- // results of this feature must be redisplayed
- static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
- std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
- for (; aRIter != aResults.cend(); aRIter++) {
- boost::shared_ptr<ModelAPI_Result> aRes = *aRIter;
- aRes->setData(boost::shared_ptr<ModelAPI_Data>()); // deleted flag
- ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
- ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), aRes->groupName());
- }
- */
}
FeaturePtr Model_Document::feature(TDF_Label& theLabel)
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
for (; aRIter != aResults.cend(); aRIter++) {
if ((*aRIter)->groupName() != theGroupID) continue;
- bool isIn = theHidden;
+ bool isIn = theHidden && (*aRIter)->isInHistory();
if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
- isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
+ isIn = !(*aRIter)->isConcealed();
}
if (isIn) {
if (anIndex == theIndex)
if ((*aRIter)->groupName() != theGroupID) continue;
bool isIn = theHidden;
if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
- isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
+ isIn = !(*aRIter)->isConcealed();
}
if (isIn)
aResult++;
// check this is unique, if not, increase index by 1
for (aFIter.Initialize(myObjs); aFIter.More();) {
FeaturePtr aFeature = aFIter.Value();
- bool isSameName = aFeature->isInHistory() && aFeature->data()->name() == aName;
+ bool isSameName = aFeature->data()->name() == aName;
if (!isSameName) { // check also results to avoid same results names (actual for Parts)
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
for (; aRIter != aResults.cend(); aRIter++) {
- isSameName = (*aRIter)->isInHistory() && (*aRIter)->data()->name() == aName;
+ isSameName = (*aRIter)->data()->name() == aName;
}
}
if (isSameName) {
}
}
-void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
+void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences)
{
boost::shared_ptr<ModelAPI_Document> aThis =
Model_Application::getApplication()->getDocument(myID);
aFIter.Next();
}
+ if (theUpdateReferences) {
+ synchronizeBackRefs();
+ }
+
myExecuteFeatures = false;
aLoop->activateFlushes(true);
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
boost::static_pointer_cast<Model_Session>(Model_Session::get())
->setCheckTransactions(true);
myExecuteFeatures = true;
}
+void Model_Document::synchronizeBackRefs()
+{
+ // first cycle: erase all data about back-references
+ NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeatures(myObjs);
+ for(; aFeatures.More(); aFeatures.Next()) {
+ FeaturePtr aFeature = aFeatures.Value();
+ boost::shared_ptr<Model_Data> aFData =
+ boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
+ if (aFData) {
+ aFData->eraseBackReferences();
+ }
+ const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for (; aRIter != aResults.cend(); aRIter++) {
+ boost::shared_ptr<Model_Data> aResData =
+ boost::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
+ if (aResData) {
+ aResData->eraseBackReferences();
+ }
+ }
+ }
+
+ // second cycle: set new back-references: only features may have reference, iterate only them
+ ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+ for(aFeatures.Initialize(myObjs); aFeatures.More(); aFeatures.Next()) {
+ FeaturePtr aFeature = aFeatures.Value();
+ boost::shared_ptr<Model_Data> aFData =
+ boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
+ if (aFData) {
+ std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
+ aFData->referencesToObjects(aRefs);
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRefsIter = aRefs.begin();
+ for(; aRefsIter != aRefs.end(); aRefsIter++) {
+ std::list<ObjectPtr>::iterator aRefTo = aRefsIter->second.begin();
+ for(; aRefTo != aRefsIter->second.end(); aRefTo++) {
+ if (*aRefTo) {
+ boost::shared_ptr<Model_Data> aRefData =
+ boost::dynamic_pointer_cast<Model_Data>((*aRefTo)->data());
+ aRefData->addBackReference(aFeature, aRefsIter->first); // here the Concealed flag is updated
+ }
+ }
+ }
+ }
+ }
+}
+
TDF_Label Model_Document::resultLabel(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theResultIndex)
{
}
}
-void Model_Document::objectIsReferenced(const ObjectPtr& theObject)
-{
- // only bodies are concealed now
- ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
- if (aResult) {
- if (myConcealedResults.find(aResult) != myConcealedResults.end()) {
- Events_Error::send(std::string("The object '") + aResult->data()->name() +
- "' is already referenced");
- } else {
- myConcealedResults.insert(aResult);
- boost::shared_ptr<ModelAPI_Document> aThis =
- Model_Application::getApplication()->getDocument(myID);
- ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_ResultBody::group());
-
- static Events_Loop* aLoop = Events_Loop::loop();
- static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
- aECreator->sendUpdated(aResult, EVENT_DISP);
- }
- }
-}
-
-void Model_Document::objectIsNotReferenced(const ObjectPtr& theObject)
-{
- // only bodies are concealed now
- ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
- if (aResult) {
- std::set<ResultPtr>::iterator aFind = myConcealedResults.find(aResult);
- if (aFind != myConcealedResults.end()) {
- ResultPtr aFeature = *aFind;
- myConcealedResults.erase(aFind);
- boost::shared_ptr<ModelAPI_Document> aThis =
- Model_Application::getApplication()->getDocument(myID);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
- ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent, false);
- } else {
- Events_Error::send(std::string("The object '") + aResult->data()->name() +
- "' was not referenced '");
- }
- }
-}
-
Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper)
{
return TDF_LabelMapHasher::HashCode(theLab, theUpper);
///! On abort, undo or redo it is not necessary: results in document are updated automatically
bool executeFeatures() {return myExecuteFeatures;}
- ///! Reutrns true is result was conecaled because of usage it by other object
- virtual bool isConcealed(const boost::shared_ptr<ModelAPI_Object>& theResult) {
- return myConcealedResults.find(boost::dynamic_pointer_cast<ModelAPI_Result>(theResult))
- != myConcealedResults.end();
- }
-
protected:
//! Returns (creates if needed) the features label
void setUniqueName(FeaturePtr theFeature);
//! Synchronizes myFeatures list with the updated document
- void synchronizeFeatures(const bool theMarkUpdated = false);
+ //! \param theMarkUpdated causes the "update" event for all features
+ //! \param theUpdateReferences causes the update of back-references
+ void synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences);
+ //! Synchronizes the BackReferences list in Data of Features and Results
+ void synchronizeBackRefs();
//! Creates new document with binary file format
Model_Document(const std::string theID, const std::string theKind);
//! Updates the results list of the feature basing on the current data tree
void updateResults(FeaturePtr theFeature);
- //! Stores information that there is a reference to this object
- void objectIsReferenced(const ObjectPtr& theObject);
- //! Removes information that there is a reference to this object
- void objectIsNotReferenced(const ObjectPtr& theObject);
-
//! Returns all sub documents
const std::set<std::string>& subDocuments() const {return mySubs;}
/// All features managed by this document (not only in history of OB)
/// For optimization mapped by labels
NCollection_DataMap<TDF_Label, FeaturePtr> myObjs;
- /// Results that are referenced and must be concealed for object browser
- std::set<ResultPtr> myConcealedResults;
///< set of identifiers of sub-documents of this document
std::set<std::string> mySubs;
Model_ResultBody::Model_ResultBody()
{
+ setIsConcealed(false);
}
void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
Model_ResultConstruction::Model_ResultConstruction()
{
myIsInHistory = true;
+ setIsConcealed(false);
}
void Model_ResultConstruction::setIsInHistory(const bool isInHistory)
Model_ResultPart::Model_ResultPart()
{
+ setIsConcealed(false);
}
void Model_ResultPart::setData(boost::shared_ptr<ModelAPI_Data> theData)
aRT->SetRelocation(aSourceRoot, aTargetRoot);
TDF_CopyTool::Copy(aDS, aRT);
- aNew->synchronizeFeatures();
+ aNew->synchronizeFeatures(false, true);
return aNew;
}
#include <Model_Update.h>
#include <Model_Document.h>
+#include <Model_Data.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_CompositeFeature.h>
#include <Events_Loop.h>
#include <Events_LongOp.h>
#include <Events_Error.h>
aDocs = ModelAPI_Session::get()->allOpenedDocuments();
}
}
- // collect all documents involved into the update
+ // collect all documents involved into the update process
set<boost::shared_ptr<ModelAPI_Object> >::iterator aFIter = myInitial.begin();
for (; aFIter != myInitial.end(); aFIter++) {
aDocs.push_back((*aFIter)->document());
bool aMustbeUpdated = myInitial.find(theFeature) != myInitial.end();
if (theFeature) { // only real feature contains references to other objects
if (theFeature->data()->mustBeUpdated()) aMustbeUpdated = true;
- // references
- list<boost::shared_ptr<ModelAPI_Attribute> > aRefs = theFeature->data()->attributes(
- ModelAPI_AttributeReference::type());
- list<boost::shared_ptr<ModelAPI_Attribute> >::iterator aRefsIter = aRefs.begin();
- for (; aRefsIter != aRefs.end(); aRefsIter++) {
- boost::shared_ptr<ModelAPI_Object> aSub = boost::dynamic_pointer_cast<
- ModelAPI_AttributeReference>(*aRefsIter)->value();
- if (updateObject(aSub)) {
- aMustbeUpdated = true;
- }
- }
- // reference to attribute or object
- list<boost::shared_ptr<ModelAPI_Attribute> > aRefAttrs = theFeature->data()->attributes(
- ModelAPI_AttributeRefAttr::type());
- for (aRefsIter = aRefAttrs.begin(); aRefsIter != aRefAttrs.end(); aRefsIter++) {
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefsIter);
- if (!aRef) continue;
- if (aRef->isObject()) {
- boost::shared_ptr<ModelAPI_Object> aSub = aRef->object();
- if (updateObject(aSub)) {
- aMustbeUpdated = true;
- }
- } else if (aRef->attr()) { // reference to the attribute
- boost::shared_ptr<ModelAPI_Object> aSub = aRef->attr()->owner();
- if (updateObject(aSub)) {
+
+ // composite feature must be executed after sub-features execution
+ CompositeFeaturePtr aComposite =
+ boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
+ if (aComposite) {
+ int aSubsNum = aComposite->numberOfSubs();
+ for(int a = 0; a < aSubsNum; a++) {
+ if (updateFeature(aComposite->subFeature(a)))
aMustbeUpdated = true;
- }
}
}
- // lists of references
- aRefs = theFeature->data()->attributes(ModelAPI_AttributeRefList::type());
- for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
- list<ObjectPtr> aListRef = boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*aRefsIter)
- ->list();
- list<ObjectPtr>::iterator aListIter = aListRef.begin();
- for (; aListIter != aListRef.end(); aListIter++) {
- boost::shared_ptr<ModelAPI_Object> aSub = *aListIter;
- if (updateObject(aSub)) {
+ // check all references: if referenced objects are updated, this object also must be updated
+ std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ aData->referencesToObjects(aRefs);
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRef = aRefs.begin();
+ for(; aRef != aRefs.end(); aRef++) {
+ std::list<ObjectPtr>::iterator aRefObj = aRef->second.begin();
+ for(; aRefObj != aRef->second.end(); aRefObj++) {
+ if (updateObject(*aRefObj)) {
aMustbeUpdated = true;
}
}
}
+
// execute feature if it must be updated
if (aMustbeUpdated) {
ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
if (aFactory->validate(theFeature)) {
if (isAutomatic || (myJustCreatedOrUpdated.find(theFeature) != myJustCreatedOrUpdated.end()) ||
- !theFeature->isPersistentResult() /* execute quick, not persistent results */) {
+ !theFeature->isPersistentResult() /* execute quick, not persistent results */)
+ {
+ // before execution update the selection attributes if any
+ list<AttributePtr> aRefs =
+ theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+ list<AttributePtr>::iterator aRefsIter = aRefs.begin();
+ for (; aRefsIter != aRefs.end(); aRefsIter++) {
+ boost::shared_ptr<ModelAPI_AttributeSelection> aSel =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
+ aSel->update(); // this must be done on execution since it may be long operation
+ }
+ aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelectionList::type());
+ for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
+ boost::shared_ptr<ModelAPI_AttributeSelectionList> aSel =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aRefsIter);
+ for(int a = aSel->size() - 1; a >= 0; a--) {
+ aSel->value(a)->update();
+ }
+ }
+ // execute in try-catch to avoid internal problems of the feature
try {
theFeature->execute();
} catch(...) {
bool Model_Update::updateObject(boost::shared_ptr<ModelAPI_Object> theObject)
{
+ if (myUpdated.find(theObject) != myUpdated.end())
+ return myUpdated[theObject]; // already processed
+ return myInitial.find(theObject) != myInitial.end();
+
+ /* remove algorithm for update of all features by dependencies tree
if (!theObject)
return false;
FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
if (myInitial.find(theObject) != myInitial.end())
return true;
return false; // nothing is known
+ */
}
return true;
}
-void Model_ValidatorsFactory::registerNotObligatory(
- std::string theFeature, std::string theAttribute)
+void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, std::string theAttribute)
{
std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
if (it != myIDs.end()) {
}
}
}
+
+void Model_ValidatorsFactory::registerConcealment(std::string theFeature, std::string theAttribute)
+{
+
+}
+
+
/// so, it is not needed for the standard validation mechanism
virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
+ /// register that this attribute conceals in the object browser
+ /// all referenced features after execution
+ virtual void registerConcealment(std::string theFeature, std::string theAttribute);
+
protected:
void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const;
/// Get instance from Session
ModelAPI_Session.h
ModelAPI_Plugin.h
ModelAPI_Feature.h
+ ModelAPI_CompositeFeature.h
ModelAPI_Data.h
ModelAPI_Object.h
ModelAPI_Document.h
ModelAPI_AttributeBoolean.h
ModelAPI_AttributeString.h
ModelAPI_AttributeSelection.h
+ ModelAPI_AttributeSelectionList.h
ModelAPI_Events.h
ModelAPI_Validator.h
ModelAPI_FeatureValidator.h
#include "ModelAPI_AttributeReference.h"
#include "ModelAPI_AttributeRefAttr.h"
#include "ModelAPI_AttributeSelection.h"
+ #include "ModelAPI_AttributeSelectionList.h"
#include "ModelAPI_Validator.h"
#include "ModelAPI_AttributeRefList.h"
#include "ModelAPI_AttributeBoolean.h"
%shared_ptr(ModelAPI_AttributeRefList)
%shared_ptr(ModelAPI_AttributeBoolean)
%shared_ptr(ModelAPI_AttributeSelection)
+%shared_ptr(ModelAPI_AttributeSelectionList)
%shared_ptr(ModelAPI_Result)
%shared_ptr(ModelAPI_ResultConstruction)
%shared_ptr(ModelAPI_ResultBody)
%include "ModelAPI_AttributeRefAttr.h"
%include "ModelAPI_AttributeBoolean.h"
%include "ModelAPI_AttributeSelection.h"
+%include "ModelAPI_AttributeSelectionList.h"
%include "ModelAPI_AttributeRefList.h"
%include "ModelAPI_Validator.h"
%include "ModelAPI_Result.h"
MODELAPI_EXPORT virtual void remove(ObjectPtr theObject) = 0;
/// Returns number of features in the list
- MODELAPI_EXPORT virtual int size() = 0;
+ MODELAPI_EXPORT virtual int size() const = 0;
/// Returns the list of features
MODELAPI_EXPORT virtual std::list<ObjectPtr> list() = 0;
+ /// Returns the referenced object by the zero-based index
+ MODELAPI_EXPORT virtual ObjectPtr object(const int theIndex) const = 0;
+
protected:
/// Objects are created for features automatically
MODELAPI_EXPORT ModelAPI_AttributeRefList()
/// Returns the context of the selection (the whole shape owner)
virtual ResultPtr context() = 0;
+ /// Updates the underlied selection due to the changes in the referenced objects
+ /// \returns false if update is failed
+ virtual bool update() = 0;
+
/// Returns the type of this class of attributes
static std::string type()
{
}
};
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeSelection> AttributeSelectionPtr;
+
#endif
--- /dev/null
+// File: ModelAPI_AttributeSelectionList.h
+// Created: 22 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeSelectionList_H_
+#define ModelAPI_AttributeSelectionList_H_
+
+#include "ModelAPI_AttributeSelection.h"
+#include <ModelAPI_Result.h>
+
+/**\class ModelAPI_AttributeSelectionList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to the sub-shapes with
+ * possibility to manage them.
+ */
+
+class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
+{
+ public:
+ /// Adds the new reference to the end of the list
+ virtual void append(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+
+ /// Returns the number ofselection attributes in the list
+ virtual int size() = 0;
+
+ /// Returns the attribute selection by the index (zero based)
+ virtual boost::shared_ptr<ModelAPI_AttributeSelection> value(const int theIndex) = 0;
+
+ /// Returns all attributes
+ virtual void clear() = 0;
+
+ /// Returns the type of this class of attributes
+ static std::string type()
+ {
+ return "SelectionList";
+ }
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType()
+ {
+ return type();
+ }
+
+ /// To virtually destroy the fields of successors
+ virtual ~ModelAPI_AttributeSelectionList()
+ {
+ }
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeSelectionList()
+ {
+ }
+};
+
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeSelectionList> AttributeSelectionListPtr;
+
+#endif
--- /dev/null
+// File: ModelAPI_CompositeFeature.hxx
+// Created: 20 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_CompositeFeature_H_
+#define ModelAPI_CompositeFeature_H_
+
+#include "ModelAPI_Feature.h"
+
+/**\class ModelAPI_CompositeFeature
+ * \ingroup DataModel
+ * \brief Feature that consists of other features: like sketcher
+ * with edges inside. It just allows t oadd a feature to this feature only
+ * instead of adding in both document and this feature.
+ */
+class ModelAPI_CompositeFeature : public ModelAPI_Feature
+{
+public:
+ /// Adds feature to the sketch and to its document
+ virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
+
+ /// Returns the number of sub-elements
+ virtual int numberOfSubs() const = 0;
+
+ /// Returns the sub-feature by zero-base index
+ virtual boost::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex) const = 0;
+
+ /// Returns the sub-feature unique identifier in this composite feature by zero-base index
+ virtual int subFeatureId(const int theIndex) const = 0;
+};
+
+//! Pointer on the composite feature object
+typedef boost::shared_ptr<ModelAPI_CompositeFeature> CompositeFeaturePtr;
+
+#endif
class ModelAPI_Attribute;
class ModelAPI_Feature;
class ModelAPI_AttributeSelection;
+class ModelAPI_AttributeSelectionList;
class GeomAPI_Shape;
/**\class ModelAPI_Data
virtual boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
/// Returns the attribute that contains selection to a shape
virtual boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
+ /// Returns the attribute that contains selection to a shape
+ virtual boost::shared_ptr<ModelAPI_AttributeSelectionList>
+ selectionList(const std::string& theID) = 0;
/// Returns the attribute that contains reference to an attribute of a feature
virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
/// Returns the attribute that contains list of references to features
/// Returns true if feature must be updated (re-executed) on rebuild
virtual bool mustBeUpdated() = 0;
- /// Returns true if this data attributes are referenced to the given feature or its results
- virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature) = 0;
+ /// Returns the identifier of feature-owner, unique in this document
+ virtual int featureId() const = 0;
protected:
/// Objects are created for features automatically
virtual boost::shared_ptr<ModelAPI_Feature> feature(
const boost::shared_ptr<ModelAPI_Result>& theResult) = 0;
- ///! Reutrns true is result was conecaled because of usage it by other object
- virtual bool isConcealed(const boost::shared_ptr<ModelAPI_Object>& theResult) = 0;
-
protected:
/// Only for SWIG wrapping it is here
MODELAPI_EXPORT ModelAPI_Document()
}
/// Returns the data manager of this object: attributes
- virtual boost::shared_ptr<ModelAPI_Data> data()
+ virtual boost::shared_ptr<ModelAPI_Data> data() const
{
return myData;
}
/// To use virtuality for destructors
virtual ~ModelAPI_Object() {}
+
protected:
/// Sets the data manager of an object (document does)
virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
*/
class ModelAPI_Result : public ModelAPI_Object
{
+ bool myIsConcealed; ///< the result is concealed from the data tree (referenced by other objects)
public:
- /// Returns the source feature of this result
- //virtual boost::shared_ptr<ModelAPI_Feature> owner() = 0;
+ /// Returns true if the result is concealed from the data tree (referenced by other objects)
+ inline bool isConcealed() {return myIsConcealed;}
+
+ /// Returns true if the result is concealed from the data tree (referenced by other objects)
+ inline void setIsConcealed(const bool theValue) {myIsConcealed = theValue;}
+
+ /// To virtually destroy the fields of successors
+ virtual ~ModelAPI_Result()
+ {
+ }
- /// Returns the group identifier of this result
- //virtual std::string groupName() = 0;
};
//! Pointer on feature object
/// Returns the shape-result produced by this feature
virtual boost::shared_ptr<GeomAPI_Shape> shape() = 0;
- /// To virtually destroy the fields of successors
- virtual ~ModelAPI_ResultBody()
- {
- }
-
/// Records the subshape newShape which was generated during a topological construction.
/// As an example, consider the case of a face generated in construction of a box.
virtual void generated(
const boost::shared_ptr<GeomAPI_Shape>& theOldShape, const int theTag = 1) = 0;
protected:
- /// Use plugin manager for features creation: this method is
- /// defined here only for SWIG-wrapping
- ModelAPI_ResultBody()
- {
- }
};
//! Pointer on feature object
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Validator.h>
/// so, it is not needed for the standard validation mechanism
virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
+ /// register that this attribute conceals in the object browser
+ /// all referenced features after execution
+ virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0;
+
protected:
/// Get instance from Session
ModelAPI_ValidatorsFactory()
ModuleBase_IViewer.h
ModuleBase_WidgetLineEdit.h
ModuleBase_WidgetMultiSelector.h
+ ModuleBase_ViewerFilters.h
+ ModuleBase_ResultPrs.h
)
SET(PROJECT_SOURCES
ModuleBase_DoubleSpinBox.cpp
ModuleBase_WidgetLineEdit.cpp
ModuleBase_WidgetMultiSelector.cpp
+ ModuleBase_ViewerFilters.cpp
+ ModuleBase_ResultPrs.cpp
)
SET(PROJECT_LIBRARIES
Config
ModelAPI
GeomAPI
+ GeomAlgoAPI
${QT_LIBRARIES}
${CAS_VIEWER}
${CAS_KERNEL}
${CMAKE_SOURCE_DIR}/src/ModelAPI
${CMAKE_SOURCE_DIR}/src/GeomDataAPI
${CMAKE_SOURCE_DIR}/src/GeomAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
)
ADD_DEFINITIONS(-DMODULEBASE_EXPORTS ${CAS_DEFINITIONS})
virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const = 0;
//! Returns list of currently selected shapes
- virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const = 0;
+ virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList,
+ std::list<ObjectPtr>& theOwners) const = 0;
};
#include "ModuleBase_Definitions.h"
#include <ModelAPI_Object.h>
+#include <GeomAPI_AISObject.h>
#include <QObject>
//! Returns currently active operation
virtual ModuleBase_Operation* currentOperation() const = 0;
+ //! Returns AIS opbject by data object
+ virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const = 0;
+
+ //! Returns data object by AIS
+ virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
+
signals:
void selectionChanged();
myParentId(theParentId)
{
myIsComputedDefault = false;
- myIsObligatory = theData ? theData->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
myAttributeID = theData ? theData->widgetId() : "";
}
{
QList<QWidget*> aMyControls = getControls();
foreach(QWidget* eachControl, aMyControls) {
- if(!myFocusInWidgets.contains(eachControl)) {
- enableFocusProcessing(eachControl);
- }
+ eachControl->setFocusPolicy(Qt::StrongFocus);
+ eachControl->installEventFilter(this);
}
}
ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
}
-void ModuleBase_ModelWidget::enableFocusProcessing(QWidget* theWidget)
-{
- theWidget->setFocusPolicy(Qt::StrongFocus);
- theWidget->installEventFilter(this);
- myFocusInWidgets.append(theWidget);
-}
-
bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
{
QWidget* aWidget = qobject_cast<QWidget*>(theObject);
- if (theEvent->type() == QEvent::MouseButtonRelease &&
- myFocusInWidgets.contains(aWidget)) {
- emit focusInWidget(this);
+ if (theEvent->type() == QEvent::FocusIn) {
+ if (getControls().contains(aWidget)) {
+ emit focusInWidget(this);
+ }
}
// pass the event on to the parent class
+
return QObject::eventFilter(theObject, theEvent);
}
/// on operation's execute, like radius for circle's constraint (can not be zero)
bool isComputedDefault() { return myIsComputedDefault; }
- /// Returns false for non-obligatory widgets which are
- /// valid even if they are not initialized
- bool isObligatory() { return myIsObligatory; }
-
/// Defines if it is supposed that the widget should interact with the viewer.
virtual bool isViewerSelector() { return false; }
void updateObject(ObjectPtr theObj) const;
- private:
- /// Let the widget process FocusIn events
- void enableFocusProcessing(QWidget* theWidget);
-
protected:
std::string myAttributeID; /// the attribute name of the model feature
std::string myParentId; /// name of parent
FeaturePtr myFeature;
bool myIsComputedDefault; /// Value should be computed on execute,
- /// like radius for circle's constraint (can not be zero)
- bool myIsObligatory; /// Non-obligatory widget is valid even if it is not initialized
-
- private:
- /// Contains a list of widgets that may accept focus
- QList<QWidget*> myFocusInWidgets;
+ /// like radius for circle's constraint (can not be zero)
};
#endif
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
}
-FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
+FeaturePtr ModuleBase_Operation::createFeature(
+ const bool theFlushMessage, CompositeFeaturePtr theCompositeFeature)
{
- boost::shared_ptr<ModelAPI_Document> aDoc = document();
- myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
+ if (theCompositeFeature) {
+ myFeature = theCompositeFeature->addFeature(getDescription()->operationId().toStdString());
+ } else {
+ boost::shared_ptr<ModelAPI_Document> aDoc = document();
+ myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
+ }
if (myFeature) { // TODO: generate an error if feature was not created
myIsModified = true;
// Model update should call "execute" of a feature.
void ModuleBase_Operation::resume()
{
if (myPropertyPanel)
- connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this,
- SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
+ connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
+ this, SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
emit resumed();
}
#include <ModuleBase.h>
#include <ModuleBase_ViewerPrs.h>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Document.h>
#include <QObject>
/// Creates an operation new feature
/// \param theFlushMessage the flag whether the create message should be flushed
- /// \returns the created feature
- virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+ /// \param theCompositeFeature the feature that must be used for adding the created object or null
+ /// \returns the created
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true,
+ CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
/// Verifies whether this operator can be commited.
/// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
--- /dev/null
+// File: ModuleBase_ResultPrs.cpp
+// Created: 21 October 2014
+// Author: Vitaly SMETANNIKOV
+
+#include "ModuleBase_ResultPrs.h"
+
+#include <ModelAPI_Tools.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAlgoAPI_SketchBuilder.h>
+
+#include <BRep_Builder.hxx>
+#include <AIS_Drawer.hxx>
+#include <Prs3d_IsoAspect.hxx>
+#include <TopoDS_Builder.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape);
+
+ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
+ : AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
+{
+ boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
+ boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
+ boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
+ if (aWirePtr) {
+ if (aWirePtr->hasPlane() ) {
+ // If this is a wire with plane defined thin it is a sketch-like object
+ // It must have invisible faces
+ GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
+ aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, myFacesList);
+
+ myOriginalShape = aWirePtr->impl<TopoDS_Shape>();
+ Set(myOriginalShape);
+ myIsSketchMode = true;
+ } else {
+ Set(aWirePtr->impl<TopoDS_Shape>());
+ }
+ } else {
+ Set(aShapePtr->impl<TopoDS_Shape>());
+ }
+}
+
+
+void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
+ myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
+ Set(aShapePtr->impl<TopoDS_Shape>());
+ AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
+}
+
+
+void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode)
+{
+ if (myIsSketchMode) {
+ if (aMode == TopAbs_FACE) {
+ BRep_Builder aBuilder;
+ TopoDS_Compound aComp;
+ aBuilder.MakeCompound(aComp);
+ aBuilder.Add(aComp, myOriginalShape);
+ std::list<boost::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
+ for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
+ TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
+ aBuilder.Add(aComp, aFace);
+ }
+ Set(aComp);
+ } else {
+ Set(myOriginalShape);
+ }
+ }
+ AIS_Shape::ComputeSelection(aSelection, aMode);
+}
\ No newline at end of file
--- /dev/null
+// File: ModuleBase_ResultPrs.h
+// Created: 21 October 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef ModuleBase_ResultPrs_H
+#define ModuleBase_ResultPrs_H
+
+#include "ModuleBase.h"
+
+#include <ModelAPI_Result.h>
+
+#include <AIS_Shape.hxx>
+#include <Standard_DefineHandle.hxx>
+
+DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape)
+
+class ModuleBase_ResultPrs: public AIS_Shape
+{
+public:
+ Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult);
+
+ Standard_EXPORT ResultPtr getResult() const { return myResult; }
+
+ DEFINE_STANDARD_RTTI(ModuleBase_ResultPrs)
+protected:
+ Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+ Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode) ;
+
+private:
+ ResultPtr myResult;
+
+ bool myIsSketchMode;
+
+ TopoDS_Shape myOriginalShape;
+ std::list<boost::shared_ptr<GeomAPI_Shape> > myFacesList;
+};
+
+
+#endif
\ No newline at end of file
--- /dev/null
+// File: ModuleBase_ViewerFilters.cpp
+// Created: 07 Okt 2014
+// Author: Vitaly SMETANNIKOV
+
+
+#include "ModuleBase_ViewerFilters.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+#include <StdSelect_BRepOwner.hxx>
+
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Curve.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
+
+
+//TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
+Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+ if (theOwner->HasSelectable()) {
+ Handle(AIS_InteractiveObject) aAisObj =
+ Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+ if (!aAisObj.IsNull()) {
+ boost::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+ ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+ if (aObj) {
+ DocumentPtr aDoc = aObj->document();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ return (aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument());
+ }
+ }
+ }
+ return Standard_False;
+}
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+
+Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+ if (theOwner->HasSelectable()) {
+ Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+ if (!aShapeOwner.IsNull()) {
+ TopoDS_Shape aShape = aShapeOwner->Shape();
+ TopAbs_ShapeEnum aType = aShape.ShapeType();
+ switch (aType) {
+ case TopAbs_VERTEX:
+ {
+ gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
+ return myPlane.Distance(aPnt) < Precision::Confusion();
+ }
+ case TopAbs_EDGE:
+ {
+ TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
+ gp_Pnt aFirstPnt = aCurve->Value(aFirst);
+ gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
+ gp_Pnt aLastPnt = aCurve->Value(aLast);
+ bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
+ bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
+ bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
+ return aD1 && aD2 && aD3;
+ }
+ }
+ }
+ }
+ return Standard_False;
+}
--- /dev/null
+// File: ModuleBase_ViewerFilters.h
+// Created: 07 Okt 2014
+// Author: Vitaly SMETANNIKOV
+
+
+#ifndef ModuleBase_ViewerFilters_H
+#define ModuleBase_ViewerFilters_H
+
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <gp_Pln.hxx>
+
+
+class ModuleBase_IWorkshop;
+
+
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select objects which belong to
+* currently active document or to global document
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
+class ModuleBase_ShapeDocumentFilter: public SelectMgr_Filter
+{
+public:
+ Standard_EXPORT ModuleBase_ShapeDocumentFilter(ModuleBase_IWorkshop* theWorkshop): SelectMgr_Filter(),
+ myWorkshop(theWorkshop) {}
+
+ Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+ DEFINE_STANDARD_RTTI(ModuleBase_ShapeDocumentFilter)
+
+private:
+ ModuleBase_IWorkshop* myWorkshop;
+};
+
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select of Vertexes and Edges which belongs to the given plane
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+class ModuleBase_ShapeInPlaneFilter: public SelectMgr_Filter
+{
+public:
+ Standard_EXPORT ModuleBase_ShapeInPlaneFilter(const gp_Pln& thePane):
+ SelectMgr_Filter(), myPlane(thePane) {}
+
+ Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+ DEFINE_STANDARD_RTTI(ModuleBase_ShapeInPlaneFilter)
+private:
+ gp_Pln myPlane;
+};
+
+#endif
\ No newline at end of file
//Create a widget (doublevalue, groupbox, toolbox, etc.
QWidget* aWidget = createWidgetByType(aWdgType, theParent);
if (aWidget) {
- if (!myWidgetApi->getBooleanAttribute(FEATURE_INTERNAL, false)) {
+ if (!myWidgetApi->getBooleanAttribute(ATTRIBUTE_INTERNAL, false)) {
aWidgetLay->addWidget(aWidget);
} else {
aWidget->setVisible(false);
return result;
}
+void ModuleBase_WidgetFactory::processAttributes()
+{
+ // register that this attribute in feature is not obligatory for the feature execution
+ // so, it is not needed for the standard validation mechanism
+ bool isObligatory = true;
+ bool isConcealment = false;
+ if( myWidgetApi ){
+ isObligatory = myWidgetApi->getBooleanAttribute(ATTRIBUTE_OBLIGATORY, true);
+ isConcealment = myWidgetApi->getBooleanAttribute(ATTRIBUTE_CONCEALMENT, false);
+ }
+ boost::shared_ptr<ModelAPI_Session> aSession = ModelAPI_Session::get();
+ if (!isObligatory) {
+ aSession->validators()->registerNotObligatory(myParentId, myWidgetApi->widgetId());
+ }
+ if(isConcealment) {
+ aSession->validators()->registerConcealment(myParentId, myWidgetApi->widgetId());
+ }
+}
+
QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
QWidget* theParent)
{
#endif
}
if (result) {
- // register that this attribute in feature is not obligatory for the feature execution
- // so, it is not needed for the standard validation mechanism
- bool isObligatory =
- myWidgetApi ? myWidgetApi->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
- if (!isObligatory) {
- ModelAPI_Session::get()->validators()->registerNotObligatory(
- myParentId, myWidgetApi->widgetId());
- }
+ processAttributes();
}
return result;
QString qs(const std::string& theStdString) const;
+ void processAttributes();
private:
Config_WidgetAPI* myWidgetApi;
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_Tools.h>
-#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
-#include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <Config_WidgetAPI.h>
#include <QGridLayout>
#include <QLabel>
-#include <QTextEdit>
+#include <QListWidget>
#include <QObject>
#include <QString>
#include <QComboBox>
myMainWidget = new QWidget(theParent);
QGridLayout* aMainLay = new QGridLayout(myMainWidget);
ModuleBase_Tools::adjustMargins(aMainLay);
+
QLabel* aTypeLabel = new QLabel(tr("Type"), myMainWidget);
aMainLay->addWidget(aTypeLabel, 0, 0);
+
myTypeCombo = new QComboBox(myMainWidget);
- std::string aTypes = theData->getProperty("type_choice");
- myShapeTypes = QString::fromStdString(aTypes).split(' ');
+ // There is no sence to paramerize list of types while we can not parametrize selection mode
+ QString aTypesStr("Vertices Edges Faces Solids");
+ myShapeTypes = aTypesStr.split(' ');
myTypeCombo->addItems(myShapeTypes);
aMainLay->addWidget(myTypeCombo, 0, 1);
+
QLabel* aListLabel = new QLabel(tr("Selected objects:"), myMainWidget);
aMainLay->addWidget(aListLabel, 1, 0, 1, -1);
- myListControl = new QTextEdit(myMainWidget);
- myListControl->setReadOnly(true);
+
+ myListControl = new QListWidget(myMainWidget);
aMainLay->addWidget(myListControl, 2, 0, 2, -1);
aMainLay->setColumnStretch(1, 1);
myMainWidget->setLayout(aMainLay);
activateSelection(false);
}
+//********************************************************************
bool ModuleBase_WidgetMultiSelector::storeValue() const
{
// A rare case when plugin was not loaded.
if(!myFeature)
return false;
DataPtr aData = myFeature->data();
- AttributeStringPtr aStringAttr = aData->string(attributeID());
- QString aWidgetValue = myListControl->toPlainText();
- aStringAttr->setValue(aWidgetValue.toStdString());
- updateObject(myFeature);
- return true;
+ AttributeSelectionListPtr aSelectionListAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+ if (aSelectionListAttr && (mySelection.size() > 0)) {
+ aSelectionListAttr->clear();
+ foreach (GeomSelection aSelec, mySelection) {
+ aSelectionListAttr->append(aSelec.first, aSelec.second);
+ }
+ updateObject(myFeature);
+ return true;
+ }
+ return false;
}
+//********************************************************************
bool ModuleBase_WidgetMultiSelector::restoreValue()
{
- return false;
// A rare case when plugin was not loaded.
if(!myFeature)
return false;
DataPtr aData = myFeature->data();
- AttributeStringPtr aStringAttr = aData->string(attributeID());
-
- bool isBlocked = myListControl->blockSignals(true);
- myListControl->setText(QString::fromStdString(aStringAttr->value()));
- myListControl->blockSignals(isBlocked);
-
- return true;
+ AttributeSelectionListPtr aSelectionListAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+ if (aSelectionListAttr) {
+ mySelection.clear();
+ for (int i = 0; i < aSelectionListAttr->size(); i++) {
+ AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+ mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
+ }
+ updateSelectionList();
+ return true;
+ }
+ return false;
}
+//********************************************************************
QWidget* ModuleBase_WidgetMultiSelector::getControl() const
{
return myMainWidget;
}
+//********************************************************************
QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
{
QList<QWidget*> result;
return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
}
+//********************************************************************
void ModuleBase_WidgetMultiSelector::onSelectionChanged()
{
ModuleBase_ISelection* aSelection = myWorkshop->selection();
- NCollection_List<TopoDS_Shape> aSelectedShapes, aFilteredShapes;
- aSelection->selectedShapes(aSelectedShapes);
- QString aText;
- if (!aSelectedShapes.IsEmpty()) {
- filterShapes(aSelectedShapes, aFilteredShapes);
- aText = QString("Items selected: %1").arg(aFilteredShapes.Size());
+ NCollection_List<TopoDS_Shape> aSelectedShapes; //, aFilteredShapes;
+ std::list<ObjectPtr> aOwnersList;
+ aSelection->selectedShapes(aSelectedShapes, aOwnersList);
+
+ mySelection.clear();
+ std::list<ObjectPtr>::const_iterator aIt;
+ NCollection_List<TopoDS_Shape>::Iterator aShpIt(aSelectedShapes);
+ GeomShapePtr aShape;
+ for (aIt = aOwnersList.cbegin(); aIt != aOwnersList.cend(); aShpIt.Next(), aIt++) {
+ ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
+ aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aShpIt.Value()));
+ mySelection.append(GeomSelection(aResult, aShape));
}
- myListControl->setText(aText);
+ updateSelectionList();
+ storeValue();
+ emit valuesChanged();
}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::updateSelectionList()
+{
+ QString aType;
+ if (myTypeCombo->currentText().toLower() == "vertices")
+ aType = "vertex";
+ else if (myTypeCombo->currentText().toLower() == "edges")
+ aType = "edge";
+ else if (myTypeCombo->currentText().toLower() == "faces")
+ aType = "face";
+ else if (myTypeCombo->currentText().toLower() == "solids")
+ aType = "solid";
+
+ myListControl->clear();
+ int i = 1;
+ foreach (GeomSelection aSel, mySelection) {
+ QString aName(aSel.first->data()->name().c_str());
+ aName += ":" + aType + QString("_%1").arg(i);
+ myListControl->addItem(aName);
+ i++;
+ }
+}
+
+
+//********************************************************************
void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
NCollection_List<TopoDS_Shape>& theResult)
{
}
}
+//********************************************************************
void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate)
{
myIsActive = toActivate;
}
}
+//********************************************************************
void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
{
QString aNewType = myTypeCombo->currentText();
#include <ModuleBase.h>
#include <ModuleBase_ModelWidget.h>
+#include <GeomAPI_Shape.h>
+#include <ModelAPI_Result.h>
+
#include <NCollection_List.hxx>
#include <TopoDS_Shape.hxx>
#include <QList>
#include <QString>
#include <QStringList>
+#include <QPair>
class QWidget;
-class QTextEdit;
+class QListWidget;
class QComboBox;
class ModuleBase_IWorkshop;
NCollection_List<TopoDS_Shape>& theResult);
private:
- QTextEdit* myListControl;
+ void updateSelectionList();
+
+ QListWidget* myListControl;
QComboBox* myTypeCombo;
QWidget* myMainWidget;
QStringList myShapeTypes;
bool myUseSubShapes;
bool myIsActive;
+
+ typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
+ QList<GeomSelection> mySelection;
};
#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
#include <boost/smart_ptr/shared_ptr.hpp>
#include <list>
-#include <stdexcept>
-#include <xstring>
+#include <string>
typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
static ShapeTypes MyShapeTypes;
boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aData->attribute(attributeID()));
ResultPtr aBody = boost::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
- if (aBody)
+ if (aBody) {
aSelect->setValue(aBody, myShape);
+ updateObject(myFeature);
+ return true;
+ }
} else {
boost::shared_ptr<ModelAPI_AttributeReference> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
if (!(aObject && aObject->isSame(mySelectedObject))) {
aRef->setValue(mySelectedObject);
updateObject(myFeature);
+ return true;
}
}
- return true;
+ return false;
}
//********************************************************************
boost::shared_ptr<GeomAPI_Shape> aShape;
if (myUseSubShapes) {
NCollection_List<TopoDS_Shape> aShapeList;
- myWorkshop->selection()->selectedShapes(aShapeList);
+ std::list<ObjectPtr> aOwners;
+ myWorkshop->selection()->selectedShapes(aShapeList, aOwners);
if (aShapeList.Extent() > 0) {
aShape = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
aShape->setImpl(new TopoDS_Shape(aShapeList.First()));
if (!myUseSubShapes) {
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE);
ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent);
- Events_Loop::loop()->flush(anEvent);
}
}
updateSelectionName();
LightApp_Module::initialize(theApp);
myWorkshop->startApplication();
+ LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
+ if (anApp)
+ connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
}
//******************************************************
}
}
+//******************************************************
+void NewGeom_Module::onDefaultPreferences()
+{
+ XGUI_Preferences::resetConfig();
+ XGUI_Preferences::updateResourcesByConfig();
+
+ LightApp_Preferences* pref = preferences();
+ if (pref)
+ pref->retrieve();
+}
+
//******************************************************
NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
{
LightApp_Preferences* pref = preferences();
if (!pref)
return;
- XGUI_Preferences::updateCustomProps();
+ XGUI_Preferences::updateConfigByResources();
QString aModName = moduleName();
QtxPreferenceItem* item = pref->findItem(aModName, true );
{
SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
QString aVal = aResMgr->stringValue(theSection, theParam);
- if (!aVal.isNull()) {
- Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
- aProp->setValue(aVal.toStdString());
+ Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
+ std::string aValue = aVal.toStdString();
+ if (aValue.empty()) {
+ aValue = aProp->defaultValue();
+ aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
+
+ LightApp_Preferences* pref = preferences();
+ if (pref)
+ pref->retrieve();
}
+ aProp->setValue(aValue);
+
}
protected slots:
virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
+ void onDefaultPreferences();
protected:
CAM_DataModel* createDataModel();
-->
<document>
+ <section name="launch">
+ <!-- SALOME launching parameters -->
+ <parameter name="modules" value="GEOM,SMESH,HEXABLOCK,MED,YACS,PARAVIS,NewGeom"/>
+ </section>
<section name="NewGeom">
<!-- Major module parameters -->
<parameter name="name" value="NewGeom"/>
#include <PartSet_Module.h>
#include <PartSet_OperationSketchBase.h>
#include <PartSet_OperationSketch.h>
+#include <PartSet_OperationFeatureCreate.h>
#include <XGUI_Displayer.h>
#include <XGUI_Workshop.h>
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Feature.h>
#ifdef _DEBUG
#include <QDebug>
std::set<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
for (; anIt != aLast; anIt++) {
ObjectPtr aObj = (*anIt);
- aDisplayer->deactivate(aObj);
- boost::shared_ptr<ModelAPI_Feature> aFeature =
- boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
- if (aFeature && (aFeature->getKind() == "Sketch")) // Activate sketcher for planes selection
- myModule->activateFeature(aFeature, false);
// If current operation is Sketch then there is no active sketching operation
- // and possible the object was created by Redo operatgion
- else if (aSketchOp) {
+ // and possible the object was created by Redo operation
+ if (aSketchOp) {
XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
// Very possible it is not displayed
aDisplayer->display(aObj, false);
- std::list<int> aModes = aSketchOp->getSelectionModes(aObj);
- myModule->activateInLocalContext(aObj, aModes, false);
}
}
+ } else if (aType == EVENT_OBJECT_TO_REDISPLAY) {
+ PartSet_OperationFeatureCreate* aCreationOp =
+ dynamic_cast<PartSet_OperationFeatureCreate*>
+ (myModule->xWorkshop()->operationMgr()->currentOperation());
+ if (aCreationOp) {
+ // Deactivate currently creating objects for selection
+ XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
+ FeaturePtr aFeature = aCreationOp->feature();
+ const std::list<ResultPtr>& aResults = aFeature->results();
+ boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
+ boost::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+ std::set<ObjectPtr> aFeatures = aUpdMsg->objects();
+ std::set<ObjectPtr>::const_iterator aObjIt, aNoObj = aFeatures.cend();
+ std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
+ for (; anIt != aLast; anIt++) {
+ aObjIt = aFeatures.find(*anIt);
+ if (aObjIt != aNoObj) {
+ aDisplayer->deactivate(*aObjIt);
+ }
+ }
+ }
} else if (aType == EVENT_OBJECT_DELETED) {
boost::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
boost::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
#include <ModelAPI_Data.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <XGUI_MainWindow.h>
#include <XGUI_Displayer.h>
#include <XGUI_Tools.h>
#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_AISObject.h>
#include <AIS_Shape.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
-#include <StdSelect_FaceFilter.hxx>
#include <StdSelect_TypeOfFace.hxx>
#include <QObject>
SLOT(onKeyRelease(QKeyEvent*)));
connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
SLOT(onMouseDoubleClick(QMouseEvent*)));
-
- myDocumentShapeFilter = new XGUI_ShapeDocumentFilter(aXWshop->displayer());
}
PartSet_Module::~PartSet_Module()
void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
{
+ XGUI_Workshop* aXWshp = xWorkshop();
+ XGUI_Displayer* aDisplayer = aXWshp->displayer();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
if (aPreviewOp) {
- XGUI_Workshop* aXWshp = xWorkshop();
XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
- XGUI_Displayer* aDisplayer = aXWshp->displayer();
- aDisplayer->openLocalContext();
- aDisplayer->deactivateObjectsOutOfContext();
- } else {
- Handle(AIS_InteractiveContext) aAIS = xWorkshop()->viewer()->AISContext();
- //TODO (VSV): We have to open Local context because at neutral point filters don't work (bug 25340)
- aAIS->AddFilter(myDocumentShapeFilter);
+ //aDisplayer->deactivateObjectsOutOfContext();
+ PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+ if (aSketchOp) {
+ if (aSketchOp->isEditOperation()) {
+ setSketchingMode(getSketchPlane(aSketchOp->feature()));
+ } else {
+ aDisplayer->openLocalContext();
+ aDisplayer->activateObjectsOutOfContext(QIntList());
+ myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
+ aDisplayer->addSelectionFilter(myPlaneFilter);
+ QIntList aModes = sketchSelectionModes(aPreviewOp->feature());
+ aDisplayer->setSelectionModes(aModes);
+ }
+ }
}
}
if (!theOperation)
return;
XGUI_Workshop* aXWshp = xWorkshop();
+ XGUI_Displayer* aDisplayer = aXWshp->displayer();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
if (aPreviewOp) {
XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
- } else {
- // Activate results of current feature for selection
- FeaturePtr aFeature = theOperation->feature();
- XGUI_Displayer* aDisplayer = aXWshp->displayer();
- std::list<ResultPtr> aResults = aFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
- aDisplayer->activate(*aIt);
- }
- Handle(AIS_InteractiveContext) aAIS = xWorkshop()->viewer()->AISContext();
- aAIS->RemoveFilter(myDocumentShapeFilter);
- }
+ PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+ if (aSketchOp) {
+ aDisplayer->closeLocalContexts();
+ } else {
+ PartSet_OperationFeatureCreate* aCreationOp =
+ dynamic_cast<PartSet_OperationFeatureCreate*>(aPreviewOp);
+ if (aCreationOp) {
+ // Activate just created object for selection
+ FeaturePtr aFeature = aCreationOp->feature();
+ QIntList aModes = sketchSelectionModes(aFeature);
+ const std::list<ResultPtr>& aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator anIt, aLast = aResults.end();
+ for (anIt = aResults.begin(); anIt != aLast; anIt++) {
+ aDisplayer->activate(*anIt, aModes);
+ }
+ aDisplayer->activate(aFeature, aModes);
+ }
+ }
+ }// else {
+ // Activate results of current feature for selection
+ //FeaturePtr aFeature = theOperation->feature();
+ //XGUI_Displayer* aDisplayer = aXWshp->displayer();
+ //std::list<ResultPtr> aResults = aFeature->results();
+ //std::list<ResultPtr>::const_iterator aIt;
+ //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ // aDisplayer->activate(*aIt);
+ //}
+ //}
}
void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
{
- //erasePlanes();
myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
- xWorkshop()->actionsMgr()->update();
-
- //PartSet_TestOCC::testSelection(myWorkshop);
+ xWorkshop()->actionsMgr()->update();
+ // Set working plane
+ ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+ FeaturePtr aSketch = anOperation->feature();
+ setSketchingMode(getSketchPlane(aSketch));
}
void PartSet_Module::onFitAllView()
std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
aSketchOp->initSelection(aSelected, aHighlighted);
- } else if (aFeature) {
- anOperation->setFeature(aFeature);
- //Deactivate result of current feature in order to avoid its selection
- XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- std::list<ResultPtr> aResults = aFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
- aDisplayer->deactivate(*aIt);
- }
- }
+ } //else if (aFeature) {
+ //anOperation->setFeature(aFeature);
+ ////Deactivate result of current feature in order to avoid its selection
+ //XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
+ //std::list<ResultPtr> aResults = aFeature->results();
+ //std::list<ResultPtr>::const_iterator aIt;
+ //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ // aDisplayer->deactivate(*aIt);
+ //}
+ //}
sendOperation(anOperation);
xWorkshop()->actionsMgr()->updateCheckState();
}
void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
{
XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- if (!isStop) {
- foreach(ObjectPtr aObject, theFeatures)
- {
- activateFeature(aObject, false);
- }
- }
+ //if (!isStop) {
+ // foreach(ObjectPtr aObject, theFeatures) {
+ // activateFeature(aObject);
+ // }
+ //}
aDisplayer->stopSelection(theFeatures, isStop, false);
ModuleBase_IViewer* aViewer = myWorkshop->viewer();
aDisplayer->updateViewer();
}
-void PartSet_Module::onCloseLocalContext()
+void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
{
XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- aDisplayer->deactivateObjectsOutOfContext();
- aDisplayer->closeLocalContexts();
+ if (!myPlaneFilter.IsNull()) {
+ aDisplayer->removeSelectionFilter(myPlaneFilter);
+ myPlaneFilter.Nullify();
+ }
+ QIntList aModes;
+ // Clear standard selection modes
+ aDisplayer->setSelectionModes(aModes);
+ aDisplayer->openLocalContext();
+ // Get default selection modes
+ aModes = sketchSelectionModes(ObjectPtr());
+ aDisplayer->activateObjectsOutOfContext(aModes);
+
+ // Set filter
+ mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
+ aDisplayer->addSelectionFilter(mySketchFilter);
}
void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
if (aPrevOp) {
std::list<FeaturePtr> aList = aPrevOp->subFeatures();
XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
+ QIntList aModes = sketchSelectionModes(aPrevOp->feature());
std::list<FeaturePtr>::iterator aSFIt;
for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
std::list<ResultPtr> aResults = (*aSFIt)->results();
std::list<ResultPtr>::iterator aIt;
for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
- if (isDisplay)
- activateInLocalContext((*aIt), aModes, false);
- else
+ if (!isDisplay)
aDisplayer->erase((*aIt), false);
}
if (!isDisplay)
aDisplayer->erase((*aSFIt), false);
}
- aDisplayer->deactivateObjectsOutOfContext();
+ //aDisplayer->deactivateObjectsOutOfContext();
}
if (isDisplay)
ModelAPI_EventCreator::get()->sendUpdated(
anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
} else {
ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
- FeaturePtr aSketch;
+ CompositeFeaturePtr aSketch;
PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
if (aPrevOp) {
aSketch = aPrevOp->sketch();
connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
SLOT(onSetSelection(const QList<ObjectPtr>&)));
- connect(aPreviewOp, SIGNAL(closeLocalContext()), this, SLOT(onCloseLocalContext()));
-
PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
if (aSketchOp) {
connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
return anOperation;
}
-//void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
-//{
-// static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
-// boost::shared_ptr<Config_PointerMessage> aMessage =
-// boost::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
-// aMessage->setPointer(theOperation);
-// Events_Loop::loop()->send(aMessage);
-//}
-
-void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer)
-{
- ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
- if (aPreviewOp) {
- XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- std::list<int> aModes = aPreviewOp->getSelectionModes(theFeature);
- activateInLocalContext(theFeature, aModes, isUpdateViewer);
-
- // If this is a Sketcher then activate objects (planar faces) outside of context
- PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
- if (aSketchOp) {
- Handle(StdSelect_FaceFilter) aFilter = new StdSelect_FaceFilter(StdSelect_Plane);
- aDisplayer->activateObjectsOutOfContext(aModes, aFilter);
- } else {
- aDisplayer->deactivateObjectsOutOfContext();
- }
- }
-}
void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
{
aDisplayer->erase(*aIt, false);
std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
- std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
for (; anIt != aLast; anIt++) {
std::list<ResultPtr>::const_iterator aRIt;
for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
aDisplayer->display((*aRIt), false);
- activateInLocalContext((*aRIt), aModes, false);
+ aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt)));
}
aDisplayer->display(aSPFeature, false);
- activateInLocalContext(aSPFeature, aModes, false);
+ aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature));
}
aDisplayer->updateViewer();
}
}
-void PartSet_Module::activateInLocalContext(ObjectPtr theResult, const std::list<int>& theModes,
- const bool isUpdateViewer)
+QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
{
- XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
- Handle(AIS_InteractiveContext) aContext = xWorkshop()->viewer()->AISContext();
- if (aContext.IsNull())
- return;
- // Open local context if there is no one
- if (!aContext->HasOpenedContext()) {
- aContext->ClearCurrents(false);
- //aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
- aContext->OpenLocalContext();
- aContext->NotUseDisplayedObjects();
- }
- // display or redisplay presentation
- boost::shared_ptr<GeomAPI_AISObject> anAIS = aDisplayer->getAISObject(theResult);
- // Activate selection of objects from prs
- if (anAIS) {
- Handle(AIS_InteractiveObject) aAISObj = anAIS->impl<Handle(AIS_InteractiveObject)>();
- aContext->ClearSelected(false); // ToCheck
- //aContext->upClearSelected(false); // ToCheck
- aContext->Load(aAISObj, -1, true/*allow decomposition*/);
- aContext->Deactivate(aAISObj);
-
- std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
- for (; anIt != aLast; anIt++) {
- aContext->Activate(aAISObj, (*anIt));
+ QIntList aModes;
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
+ if (aFeature) {
+ if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
+ aModes.append(TopAbs_FACE);
+ return aModes;
+ } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
+ aModes.append(AIS_DSM_Text);
+ aModes.append(AIS_DSM_Line);
+ return aModes;
}
- }
+ }
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
+ return aModes;
+}
- if (isUpdateViewer)
- aDisplayer->updateViewer();
+
+gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
+{
+ DataPtr aData = theSketch->data();
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ boost::shared_ptr<GeomDataAPI_Dir> aNorm = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
+ gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
+ return gp_Pln(aOrig, aDir);
}
+
#include <ModuleBase_IModule.h>
#include <ModuleBase_Definitions.h>
+#include <ModuleBase_ViewerFilters.h>
#include <XGUI_Command.h>
-#include <XGUI_ViewerFilters.h>
#include <ModelAPI_Feature.h>
+#include <StdSelect_FaceFilter.hxx>
#include <QMap>
#include <QObject>
/// \param theCmdId the operation name
//virtual void launchOperation(const QString& theCmdId);
- /// 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(ObjectPtr theFeature, const bool isUpdateViewer);
-
/// Updates current operation preview, if it has it.
/// \param theCmdId the operation name
void updateCurrentPreview(const std::string& theCmdId);
XGUI_Workshop* xWorkshop() const;
- /// 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(ObjectPtr theFeature, const std::list<int>& theModes,
- const bool isUpdateViewer = true);
+
+ /// Returns list of selection modes for the given object for sketch operation
+ static QIntList sketchSelectionModes(ObjectPtr theFeature);
public slots:
void onFeatureTriggered();
/// \param theFeatures a list of features to be selected
void onSetSelection(const QList<ObjectPtr>& theFeatures);
- /// SLOT, to close the viewer local context
- void onCloseLocalContext();
+ /// SLOT, Defines Sketch editing mode
+ /// \param thePln - plane of current sketch
+ void setSketchingMode(const gp_Pln& thePln);
/// SLOT, to visualize the feature in another local context mode
/// \param theFeature the feature to be put in another local context mode
//! Edits the feature
void editFeature(FeaturePtr theFeature);
+ gp_Pln getSketchPlane(FeaturePtr theSketch) const;
+
private:
//XGUI_Workshop* myWorkshop;
PartSet_Listener* myListener;
std::map<std::string, std::string> myFeaturesInFiles;
- /// A filter which provides selection within a current document or whole PartSet
- Handle(XGUI_ShapeDocumentFilter) myDocumentShapeFilter;
+ Handle(StdSelect_FaceFilter) myPlaneFilter;
+ Handle(ModuleBase_ShapeInPlaneFilter) mySketchFilter;
};
#endif
PartSet_OperationFeatureBase::PartSet_OperationFeatureBase(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ CompositeFeaturePtr theFeature)
: PartSet_OperationSketchBase(theId, theParent),
mySketch(theFeature)
{
{
}
-FeaturePtr PartSet_OperationFeatureBase::sketch() const
+CompositeFeaturePtr PartSet_OperationFeatureBase::sketch() const
{
return mySketch;
}
/// \param theId the feature identifier
/// \param theParent the operation parent
/// \param theSketch the parent feature
- PartSet_OperationFeatureBase(const QString& theId, QObject* theParent, FeaturePtr theSketch);
+ PartSet_OperationFeatureBase(const QString& theId, QObject* theParent, CompositeFeaturePtr theSketch);
/// Destructor
virtual ~PartSet_OperationFeatureBase();
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual FeaturePtr sketch() const;
+ virtual CompositeFeaturePtr sketch() const;
/// Gives the current selected objects to be processed by the operation
/// \param theEvent the mouse event
//bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
protected:
- FeaturePtr mySketch; ///< the sketch of the feature
+ CompositeFeaturePtr mySketch; ///< the sketch of the feature
};
#endif
PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ CompositeFeaturePtr theFeature)
: PartSet_OperationFeatureBase(theId, theParent, theFeature)
{
}
return false;
}
-std::list<int> PartSet_OperationFeatureCreate::getSelectionModes(ObjectPtr theFeature) const
-{
- std::list<int> aModes;
- if (theFeature != feature())
- aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
- return aModes;
-}
-
void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
{
double aX, anY;
emit featureConstructed(feature(), FM_Deactivation);
}
-FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage)
+FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMessage,
+ CompositeFeaturePtr theCompositeFeature)
{
- FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false);
- if (sketch()) {
- boost::shared_ptr<SketchPlugin_Feature> aFeature = boost::dynamic_pointer_cast<
- SketchPlugin_Feature>(sketch());
-
- aFeature->addSub(aNewFeature);
- }
+ FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false, sketch());
if (theFlushMessage)
flushCreated();
/// \param theId the feature identifier
/// \param theParent the operation parent
/// \param theSketch the parent feature
- PartSet_OperationFeatureCreate(const QString& theId, QObject* theParent, FeaturePtr theSketch);
+ PartSet_OperationFeatureCreate(
+ const QString& theId, QObject* theParent, CompositeFeaturePtr theSketch);
/// Destructor
virtual ~PartSet_OperationFeatureCreate();
- /// 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(ObjectPtr theFeature) const;
-
/// Gives the current mouse point in the viewer
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
/// 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);
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true,
+ CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
/// Verifies whether this operator can be commited.
/// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ CompositeFeaturePtr theFeature)
: PartSet_OperationFeatureBase(theId, theParent, theFeature),
myIsBlockedSelection(false)
{
if (commit()) {
emit featureConstructed(feature(), FM_Deactivation);
- bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
- if (aHasShift && !theHighlighted.empty()) {
- QList<ObjectPtr> aSelected;
- std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
- for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
- aSelected.append((*aIt).object());
+ //bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
+ //if (aHasShift && !theHighlighted.empty()) {
+ // QList<ObjectPtr> aSelected;
+ // std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
+ // for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
+ // aSelected.append((*aIt).object());
/*for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
if (!aSelected.contains((*aIt).object()))
aSelected.append((*aIt).object());
}*/
//aSelected.push_back(feature());
//aSelected.push_back(theHighlighted.front().object());
- emit setSelection(aSelected);
- } else if (aFeature) {
+ //emit setSelection(aSelected);
+ //} else
+ if (aFeature) {
restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
}
}
boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
SketchPlugin_Feature>(feature());
- aSketchFeature->move(aDeltaX, aDeltaY);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
- ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
+ // MPV: added condition because it could be external edge of some object, not sketch
+ if (aSketchFeature && aSketchFeature->sketch() == sketch().get()) {
+ aSketchFeature->move(aDeltaX, aDeltaY);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
+ }
}
sendFeatures();
}
}
-FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMessage*/)
+FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool theFlushMessage,
+ CompositeFeaturePtr theCompositeFeature)
{
// do nothing in order to do not create a new feature
return FeaturePtr();
/// \param theId the feature identifier
/// \param theParent the operation parent
/// \param theFeature the parent feature
- PartSet_OperationFeatureEdit(const QString& theId, QObject* theParent, FeaturePtr theFeature);
+ PartSet_OperationFeatureEdit(const QString& theId, QObject* theParent, CompositeFeaturePtr theFeature);
/// Destructor
virtual ~PartSet_OperationFeatureEdit();
/// 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 FeaturePtr createFeature(const bool theFlushMessage = true);
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true,
+ CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
protected:
/// Emits a signal about the selection blocking. Emits a signal to change the selection.
#include <V3d_View.hxx>
+#include <QMouseEvent>
#ifdef _DEBUG
#include <QDebug>
#endif
-#include <QMouseEvent>
-
-using namespace std;
+//using namespace std;
PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ CompositeFeaturePtr theFeature)
: PartSet_OperationSketchBase(theId, theParent),
mySketch(theFeature),
myIsBlockedSelection(false)
//} else
myFeatures = theSelected;
// add highlighted elements if they are not selected
- std::list<ModuleBase_ViewerPrs>::const_iterator anIt;
- for (anIt = theHighlighted.cbegin(); anIt != theHighlighted.cend(); ++anIt) {
+ std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theHighlighted.cbegin();
+ for ( ; anIt != theHighlighted.cend(); ++anIt) {
if (!isContains(myFeatures, (*anIt)))
myFeatures.push_back(*anIt);
}
// Remove current feature if it is in the list (it will be moved as main feature)
- FeaturePtr aFea = feature();
- for (anIt = myFeatures.cbegin(); anIt != myFeatures.cend(); ++anIt) {
- FeaturePtr aF = ModelAPI_Feature::feature((*anIt).object());
- if (ModelAPI_Feature::feature((*anIt).object()) == feature()) {
- myFeatures.erase(anIt);
+ std::list<ModuleBase_ViewerPrs>::iterator anEraseIt = myFeatures.begin();
+ for ( ; anEraseIt != myFeatures.end(); ++anEraseIt) {
+ if (ModelAPI_Feature::feature((*anEraseIt).object()) == feature()) {
+ myFeatures.erase(anEraseIt);
break;
}
}
}
-FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
+CompositeFeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
{
return mySketch;
}
#include <PartSet_OperationSketchBase.h>
#include <QObject>
+#include <list>
+
class QMouseEvent;
/*!
/// \param theParent the operation parent
/// \param theFeature the parent feature
PartSet_OperationFeatureEditMulti(const QString& theId, QObject* theParent,
- FeaturePtr theFeature);
+ CompositeFeaturePtr theFeature);
/// Destructor
virtual ~PartSet_OperationFeatureEditMulti();
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual FeaturePtr sketch() const;
+ virtual CompositeFeaturePtr sketch() const;
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
void sendFeatures();
private:
- FeaturePtr mySketch; ///< the sketch feature
+ CompositeFeaturePtr mySketch; ///< the sketch feature
std::list<ModuleBase_ViewerPrs> myFeatures; ///< the features to apply the edit operation
Point myCurPoint; ///< the current 3D point clicked or moved
bool myIsBlockedSelection; ///< the state of the last state of selection blocked signal
{
}
-std::list<int> PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) const
+CompositeFeaturePtr PartSet_OperationSketch::sketch() const
{
- std::list<int> aModes;
- if (!hasSketchPlane())
- aModes.push_back(TopAbs_FACE);
- else
- aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
-
- return aModes;
-}
-
-FeaturePtr PartSet_OperationSketch::sketch() const
-{
- return feature();
+ return boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
}
void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
{
PartSet_OperationSketchBase::stopOperation();
emit featureConstructed(feature(), FM_Hide);
- emit closeLocalContext();
}
void PartSet_OperationSketch::afterCommitOperation()
flushUpdated();
emit featureConstructed(feature(), FM_Hide);
- emit closeLocalContext();
emit planeSelected(aDir->x(), aDir->y(), aDir->z());
}
virtual bool isGranted(ModuleBase_Operation* 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(ObjectPtr theFeature) const;
-
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual FeaturePtr sketch() const;
+ virtual CompositeFeaturePtr sketch() const;
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
return std::list<FeaturePtr>();
}
-std::list<int> PartSet_OperationSketchBase::getSelectionModes(ObjectPtr theFeature) const
-{
- //TODO: Define position of selection modes definition
- std::list<int> aModes;
- FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
- if (aFeature && PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
- aModes.push_back(AIS_DSM_Text);
- aModes.push_back(AIS_DSM_Line);
- } else {
- aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
- aModes.push_back(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
- }
- return aModes;
-}
FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage)
{
ModuleBase_Operation::createFeature(theFlushMessage);
/// \return the list of subfeatures
virtual std::list<FeaturePtr> subFeatures() 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(ObjectPtr theFeature) const;
-
/// Returns the operation sketch feature
/// \returns the sketch instance
- virtual FeaturePtr sketch() const = 0;
+ virtual CompositeFeaturePtr sketch() const = 0;
/// Processes the mouse pressed in the point
/// \param theEvent the mouse event
/// \param theFeatures a list of features to be disabled
void setSelection(const QList<ObjectPtr>& theFeatures);
- /// signal to close the operation local context if it is opened
- void closeLocalContext();
-
protected:
/// Creates an operation new feature
/// In addition to the default realization it appends the created line feature to
return aFeature;
}
-void PartSet_Tools::createConstraint(FeaturePtr theSketch,
+void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
{
- boost::shared_ptr<ModelAPI_Document> aDoc = document();
- FeaturePtr aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
-
+ FeaturePtr aFeature;
if (theSketch) {
- boost::shared_ptr<SketchPlugin_Feature> aSketch = boost::dynamic_pointer_cast<
- SketchPlugin_Feature>(theSketch);
- aSketch->addSub(aFeature);
+ aFeature = theSketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ } else {
+ boost::shared_ptr<ModelAPI_Document> aDoc = document();
+ aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
}
boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
aFeature->execute();
}
-void PartSet_Tools::setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
+void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
const std::string& theAttribute, double theClickedX,
double theClickedY)
{
}
}
-boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(FeaturePtr theSketch)
+boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
{
boost::shared_ptr<GeomAPI_Pln> aPlane;
double aA, aB, aC, aD;
}
boost::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
- FeaturePtr theSketch)
+ CompositeFeaturePtr theSketch)
{
boost::shared_ptr<GeomAPI_Pnt> aPoint;
if (!theSketch || !thePoint2D)
#include <QPoint>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
#include <boost/shared_ptr.hpp>
/// Creates a constraint on two points
/// \param thePoint1 the first point
/// \param thePoint1 the second point
- static void createConstraint(FeaturePtr theSketch,
+ static void createConstraint(CompositeFeaturePtr theSketch,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
/// \param theAttribute a name of the requried attribute attribute
/// \param theClickedX the horizontal coordnate of the point
/// \param theClickedY the vertical coordnate of the point
- static void setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
+ static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
const std::string& theAttribute, double theClickedX,
double theClickedY);
/// Create a sketch plane instance
/// \param theSketch a sketch feature
/// \return API object of geom plane
- static boost::shared_ptr<GeomAPI_Pln> sketchPlane(FeaturePtr theSketch);
+ static boost::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
/// Create a point 3D on a basis of point 2D and sketch feature
/// \param thePoint2D a point on a sketch
/// \param theSketch a sketch feature
/// \return API object of point 3D
static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
- FeaturePtr theSketch);
+ CompositeFeaturePtr theSketch);
/// Check whether there is a constraint with the feature kind given
/// \param theKind a feature kind
/// \return the boolean value
<file>icons/distance.png</file>
<file>icons/radius_constr.png</file>
<file>icons/shape_group.png</file>
+ <file>icons/fixed.png</file>
</qresource>
</RCC>
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
#include <GeomAPI_Circ2d.h>
#include <GeomAPI_Pnt2d.h>
void SketchPlugin_Arc::initAttributes()
{
- data()->addAttribute(SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D::type());
- data()->addAttribute(SketchPlugin_Arc::START_ID(), GeomDataAPI_Point2D::type());
- data()->addAttribute(SketchPlugin_Arc::END_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
void SketchPlugin_Arc::execute()
return aDelta;
}
+
+bool SketchPlugin_Arc::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context();
+}
return MY_KIND;
}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
/// Creates an arc-shape
SKETCHPLUGIN_EXPORT virtual void execute();
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomDataAPI_Point2D.h>
{
data()->addAttribute(SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble::type());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
void SketchPlugin_Circle::execute()
return aPoint->pnt()->distance(thePoint);
}
+
+bool SketchPlugin_Circle::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context();
+}
return MY_KIND;
}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#include "SketchPlugin_ConstraintRigid.h"
+#include <ModelAPI_ResultConstruction.h>
+
SketchPlugin_ConstraintRigid::SketchPlugin_ConstraintRigid()
{
}
void SketchPlugin_ConstraintRigid::execute()
{
}
+
+AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious)
+{
+ if (!sketch())
+ return thePrevious;
+
+ boost::shared_ptr<ModelAPI_Data> aData = data();
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ if (!anAttr || !anAttr->isObject())
+ return thePrevious;
+
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConst =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
+ if (!aConst)
+ return thePrevious;
+
+ boost::shared_ptr<GeomAPI_Shape> aShape;
+ aShape = aConst->shape();
+
+ AISObjectPtr anAIS = thePrevious;
+ if (!anAIS)
+ anAIS = AISObjectPtr(new GeomAPI_AISObject);
+
+ boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
+ anAIS->createFixed(aShape, aPlane);
+
+ // Set color from preferences
+ //std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
+ // PERPENDICULAR_COLOR);
+ //anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+
+ return anAIS;
+}
\ No newline at end of file
return MY_KIND;
}
+ /// Returns the AIS preview
+ SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
mySketch = 0;
}
+/*
SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
{
if (!mySketch) {
// find sketch that references to this feature
int aSketches = document()->size(ModelAPI_Feature::group());
for (int a = 0; a < aSketches && !mySketch; a++) {
- boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::dynamic_pointer_cast<
- SketchPlugin_Sketch>(document()->object(ModelAPI_Feature::group(), a));
+ ObjectPtr anObj = document()->object(ModelAPI_Feature::group(), a);
+ boost::shared_ptr<SketchPlugin_Sketch> aSketch =
+ boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj);
if (aSketch) {
std::list<ObjectPtr> aList = aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())
->list();
}
}
return mySketch;
-}
+}*/
AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
AISObjectPtr thePrevious)
#define SketchPlugin_Feature_H_
#include "SketchPlugin.h"
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_AISObject.h>
#include <ModelAPI_Document.h>
static AISObjectPtr simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
AISObjectPtr thePrevious);
- /// Adds sub-feature of the higher level feature (sub-element of the sketch)
- /// \param theFeature sub-feature
- SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature)
+ /// Reference to the external edge or vertex as a AttributeSelection
+ inline static const std::string& EXTERNAL_ID()
{
+ static const std::string MY_EXTERNAL_ID("External");
+ return MY_EXTERNAL_ID;
}
- ;
/// Returns true if this feature must be displayed in the history (top level of Part tree)
SKETCHPLUGIN_EXPORT virtual bool isInHistory()
/// Construction result is allways recomuted on the fly
SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
+
+ /// Returns the sketch of this feature
+ inline SketchPlugin_Sketch* sketch() {return mySketch;}
protected:
/// Sets the higher-level feature for the sub-feature (sketch for line)
void setSketch(SketchPlugin_Sketch* theSketch)
{
mySketch = theSketch;
}
- /// Returns the sketch of this feature
- SketchPlugin_Sketch* sketch();
/// initializes mySketch
SketchPlugin_Feature();
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Lin2d.h>
{
data()->addAttribute(SketchPlugin_Line::START_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(SketchPlugin_Line::END_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
void SketchPlugin_Line::execute()
return aDelta;
}
+
+bool SketchPlugin_Line::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context();
+}
return MY_KIND;
}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
aFactory->registerValidator("SketchPlugin_DistanceAttr",
- new SketchPlugin_DistanceAttrValidator);
+ new SketchPlugin_DistanceAttrValidator);
aFactory->registerValidator("SketchPlugin_DifferentObjects",
new SketchPlugin_DifferentObjectsValidator);
aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
SKETCH_PLANE_COLOR);
Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
PLANE_SIZE);
- Config_PropManager::registerProp("Sketch planes", "planes_thikness", "Thickness",
+ Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
Config_Prop::Integer, SKETCH_WIDTH);
Config_PropManager::registerProp("Visualization", "parallel_color", "Parallel constraint color",
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
#include <GeomAPI_Pnt2d.h>
void SketchPlugin_Point::initAttributes()
{
data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
void SketchPlugin_Point::execute()
return aPoint->pnt()->distance(thePoint);
}
+
+bool SketchPlugin_Point::isFixed() {
+ return data()->selection(EXTERNAL_ID())->context();
+}
return MY_KIND;
}
+ /// Returns true is sketch element is under the rigid constraint
+ SKETCHPLUGIN_EXPORT virtual bool isFixed();
+
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#include <GeomAPI_AISObject.h>
#include <GeomAPI_Dir.h>
-#include <GeomAPI_Wire.h>
+#include <GeomAPI_PlanarEdges.h>
#include <GeomAPI_XYZ.h>
#include <GeomDataAPI_Dir.h>
return;
// Collect all edges as one big wire
- boost::shared_ptr<GeomAPI_Wire> aBigWire(new GeomAPI_Wire);
+ boost::shared_ptr<GeomAPI_PlanarEdges> aBigWire(new GeomAPI_PlanarEdges);
std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator aShapeIt = aFeaturesPreview.begin();
for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
aBigWire->addEdge(*aShapeIt);
}
+ aBigWire->setOrigin(anOrigin->pnt());
+ aBigWire->setDirX(aDirX->dir());
+ aBigWire->setDirY(aDirY->dir());
+ aBigWire->setNorm(aNorm->dir());
+
// GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
// aFeaturesPreview, aLoops, aWires);
boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
setResult(aConstr);
}
-const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature)
+boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string theID)
+{
+ boost::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID);
+ if (aNew) {
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(aNew)->setSketch(this);
+ data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(aNew);
+ }
+ return aNew;
+}
+
+int SketchPlugin_Sketch::numberOfSubs() const
+{
+ return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size();
+}
+
+boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::subFeature(const int theIndex) const
+{
+ ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex);
+ return boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+}
+
+int SketchPlugin_Sketch::subFeatureId(const int theIndex) const
{
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature)->setSketch(this);
- data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(theFeature);
+ return subFeature(theIndex)->data()->featureId();
}
boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
SKETCH_PLANE_COLOR);
aAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
- aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thikness",
+ aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness",
SKETCH_WIDTH));
}
return aAIS;
document()->removeFeature(aFeature, false);
}
}
- SketchPlugin_Feature::erase();
+ ModelAPI_CompositeFeature::erase();
}
* \ingroup DataModel
* \brief Feature for creation of the new part in PartSet.
*/
-class SketchPlugin_Sketch : public SketchPlugin_Feature, public GeomAPI_IPresentable
+class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_IPresentable
{
public:
/// Sketch feature kind
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Adds sub-feature of the higher level feature (sub-element of the sketch)
- /// \param theFeature sub-feature
- SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature);
-
/// Moves the feature
/// \param theDeltaX the delta for X coordinate is moved
/// \param theDeltaY the delta for Y coordinate is moved
/// removes also all sub-sketch elements
SKETCHPLUGIN_EXPORT virtual void erase();
- protected:
+ SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
+
+ /// Returns the number of sub-elements
+ SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;
+
+ /// Returns the sub-feature by zero-base index
+ SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
+ subFeature(const int theIndex) const;
+
+ /// Returns the sub-feature unique identifier in this composite feature by zero-base index
+ SKETCHPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
+
+ /// Construction result is allways recomuted on the fly
+ SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+
+protected:
/// Creates a plane and append it to the list
/// \param theX the X normal value
/// \param theY the Y normal value
<validator id="PartSet_PerpendicularValidator"/>
</feature>
- <feature id="SketchConstraintRigid" title="Rigid" tooltip="Create constraint defining fixed object" icon="">
+ <feature id="SketchConstraintRigid" title="Fixed" tooltip="Create constraint defining fixed object" icon=":icons/fixed.png">
<feature_selector id="ConstraintEntityA" label="Object" tooltip="Select any object in the viewer">
<validator id="SketchPlugin_ResultPoint"/>
<validator id="SketchPlugin_ResultLine"/>
// ========================================================
SketchSolver_ConstraintGroup::SketchSolver_ConstraintGroup(
- boost::shared_ptr<SketchPlugin_Feature> theWorkplane)
+ boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane)
: myID(++myGroupIndexer),
myParamMaxID(0),
myEntityMaxID(0),
// Purpose: verify the group is based on the given workplane
// ============================================================================
bool SketchSolver_ConstraintGroup::isBaseWorkplane(
- boost::shared_ptr<SketchPlugin_Feature> theWorkplane) const
+ boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane) const
{
return theWorkplane == mySketch;
}
// Avoid to create additional "Rigid" constraints for coincident points
bool isCoincAlreadyFixed = false;
if (!anAlreadyFixed.empty()) {
+ if (anAlreadyFixed.find(*aPointsPtr) != anAlreadyFixed.end())
+ isCoincAlreadyFixed = true;
+
std::vector<std::set<Slvs_hEntity> >::const_iterator aCoincIter =
myCoincidentPoints.begin();
for (; !isCoincAlreadyFixed && aCoincIter != myCoincidentPoints.end(); aCoincIter++) {
SketchPlugin_Feature>(theEntity);
if (aFeature) { // Verify the feature by its kind
const std::string& aFeatureKind = aFeature->getKind();
-
- std::list<AttributePtr> anAttributes = aFeature->data()->attributes(std::string());
- std::list<AttributePtr>::iterator anAttrIter = anAttributes.begin();
- for ( ; anAttrIter != anAttributes.end(); anAttrIter++)
- if (!(*anAttrIter)->isInitialized()) // the entity is not fully initialized, don't add it into solver
- return SLVS_E_UNKNOWN;
+ AttributePtr anAttribute;
// Line
if (aFeatureKind.compare(SketchPlugin_Line::ID()) == 0) {
- Slvs_hEntity aStart = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Line::START_ID()));
- Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(SketchPlugin_Line::END_ID()));
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Line::START_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aStart = changeEntity(anAttribute);
+
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Line::END_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aEnd = changeEntity(anAttribute);
if (!isEntExists) // New entity
aNewEntity = Slvs_MakeLineSegment(++myEntityMaxID, myID, myWorkplane.h, aStart, aEnd);
}
// Circle
else if (aFeatureKind.compare(SketchPlugin_Circle::ID()) == 0) {
- Slvs_hEntity aCenter = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
- Slvs_hEntity aRadius = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()));
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aCenter = changeEntity(anAttribute);
+
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aRadius = changeEntity(anAttribute);
if (!isEntExists) // New entity
aNewEntity = Slvs_MakeCircle(++myEntityMaxID, myID, myWorkplane.h, aCenter,
}
// Arc
else if (aFeatureKind.compare(SketchPlugin_Arc::ID()) == 0) {
- Slvs_hEntity aCenter = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
- Slvs_hEntity aStart = changeEntity(aFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
- Slvs_hEntity aEnd = changeEntity(aFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aCenter = changeEntity(anAttribute);
+
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::START_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aStart = changeEntity(anAttribute);
+
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::END_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aEnd = changeEntity(anAttribute);
if (!isEntExists)
aNewEntity = Slvs_MakeArcOfCircle(++myEntityMaxID, myID, myWorkplane.h,
}
// Point (it has low probability to be an attribute of constraint, so it is checked at the end)
else if (aFeatureKind.compare(SketchPlugin_Point::ID()) == 0) {
- Slvs_hEntity aPoint = changeEntity(
- aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+ anAttribute = aFeature->data()->attribute(SketchPlugin_Point::COORD_ID());
+ if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN;
+ Slvs_hEntity aPoint = changeEntity(anAttribute);
if (isEntExists)
return aEntIter->second;
return aNewEntity.h;
}
-
// Unsupported or wrong entity type
return SLVS_E_UNKNOWN;
}
// Class: SketchSolver_ConstraintGroup
// Purpose: create workplane for the group
// ============================================================================
-bool SketchSolver_ConstraintGroup::addWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch)
+bool SketchSolver_ConstraintGroup::addWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch)
{
if (myWorkplane.h || theSketch->getKind().compare(SketchPlugin_Sketch::ID()) != 0)
return false; // the workplane already exists or the function parameter is not Sketch
* Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type
* \remark Type of theSketch is not verified inside
*/
- SketchSolver_ConstraintGroup(boost::shared_ptr<SketchPlugin_Feature> theWorkplane);
+ SketchSolver_ConstraintGroup(boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane);
~SketchSolver_ConstraintGroup();
* \param[in] theWorkplane the feature to be compared with base workplane
* \return \c true if workplanes are the same
*/
- bool isBaseWorkplane(boost::shared_ptr<SketchPlugin_Feature> theWorkplane) const;
+ bool isBaseWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theWorkplane) const;
- boost::shared_ptr<SketchPlugin_Feature> getWorkplane() const
+ boost::shared_ptr<ModelAPI_CompositeFeature> getWorkplane() const
{
return mySketch;
}
* \param[in] theSketch parameters of workplane are the attributes of this sketch
* \return \c true if success, \c false if workplane parameters are not consistent
*/
- bool addWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch);
+ bool addWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch);
/** \brief Add the entities of constraint for points coincidence into the appropriate list
* \param[in] thePoint1 identifier of the first point
std::list<Slvs_hConstraint> myTempConstraints; ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user
// SketchPlugin entities
- boost::shared_ptr<SketchPlugin_Feature> mySketch; ///< Equivalent to workplane
+ boost::shared_ptr<ModelAPI_CompositeFeature> mySketch; ///< Equivalent to workplane
ConstraintMap 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<FeaturePtr, Slvs_hEntity> myEntityFeatMap; ///< The map between "feature" parameters of constraints and their equivalent SolveSpace entities
// Only sketches and constraints can be added by Create event
const std::string& aFeatureKind = aFeature->getKind();
if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) {
- boost::shared_ptr<SketchPlugin_Feature> aSketch = boost::dynamic_pointer_cast<
- SketchPlugin_Feature>(aFeature);
+ boost::shared_ptr<ModelAPI_CompositeFeature> aSketch = boost::dynamic_pointer_cast<
+ ModelAPI_CompositeFeature>(aFeature);
if (aSketch)
changeWorkplane(aSketch);
continue;
// Purpose: update workplane by given parameters of the sketch
// ============================================================================
bool SketchSolver_ConstraintManager::changeWorkplane(
- boost::shared_ptr<SketchPlugin_Feature> theSketch)
+ boost::shared_ptr<ModelAPI_CompositeFeature> theSketch)
{
bool aResult = true; // changed when a workplane wrongly updated
bool isUpdated = false;
// There are no groups applicable for this constraint => create new one
// The group will be created only for constraints, not for features
if (!aConstraint) return false;
- boost::shared_ptr<SketchPlugin_Feature> aWP = findWorkplane(aConstraint);
+ boost::shared_ptr<ModelAPI_CompositeFeature> aWP = findWorkplane(aConstraint);
if (!aWP)
return false;
SketchSolver_ConstraintGroup* aGroup = new SketchSolver_ConstraintGroup(aWP);
boost::shared_ptr<SketchPlugin_Feature> theFeature,
std::set<Slvs_hGroup>& theGroupIDs) const
{
- boost::shared_ptr<SketchPlugin_Feature> aWP = findWorkplane(theFeature);
+ boost::shared_ptr<ModelAPI_CompositeFeature> aWP = findWorkplane(theFeature);
SketchSolver_ConstraintGroup* anEmptyGroup = 0; // appropriate empty group for specified constraint
std::vector<SketchSolver_ConstraintGroup*>::const_iterator aGroupIter;
// Class: SketchSolver_Session
// Purpose: search workplane containing given feature
// ============================================================================
-boost::shared_ptr<SketchPlugin_Feature> SketchSolver_ConstraintManager::findWorkplane(
+boost::shared_ptr<ModelAPI_CompositeFeature> SketchSolver_ConstraintManager::findWorkplane(
boost::shared_ptr<SketchPlugin_Feature> theFeature) const
{
// Already verified workplanes
- std::set<boost::shared_ptr<SketchPlugin_Feature> > aVerified;
+ std::set<boost::shared_ptr<ModelAPI_CompositeFeature> > aVerified;
std::vector<SketchSolver_ConstraintGroup*>::const_iterator aGroupIter;
for (aGroupIter = myGroups.begin(); aGroupIter != myGroups.end(); aGroupIter++) {
- boost::shared_ptr<SketchPlugin_Feature> aWP = (*aGroupIter)->getWorkplane();
+ boost::shared_ptr<ModelAPI_CompositeFeature> aWP = (*aGroupIter)->getWorkplane();
if (aVerified.find(aWP) != aVerified.end())
continue;
aVerified.insert(aWP);
}
- return boost::shared_ptr<SketchPlugin_Feature>();
+ return boost::shared_ptr<ModelAPI_CompositeFeature>();
}
// ============================================================================
* \return \c true if the workplane changed successfully
* \remark Type of theSketch is not verified inside
*/
- bool changeWorkplane(boost::shared_ptr<SketchPlugin_Feature> theSketch);
+ bool changeWorkplane(boost::shared_ptr<ModelAPI_CompositeFeature> theSketch);
/** \brief Removes a workplane from the manager.
* All groups based on such workplane will be removed too.
* \param[in] theFeature object to be found
* \return workplane containing the feature
*/
- boost::shared_ptr<SketchPlugin_Feature> findWorkplane(
+ boost::shared_ptr<ModelAPI_CompositeFeature> findWorkplane(
boost::shared_ptr<SketchPlugin_Feature> theFeature) const;
private:
XGUI_Preferences.h
XGUI_IPrefMgr.h
XGUI_QtEvents.h
- XGUI_ViewerFilters.h
)
SET(PROJECT_AUTOMOC
XGUI_Selection.cpp
XGUI_Preferences.cpp
XGUI_QtEvents.cpp
- XGUI_ViewerFilters.cpp
)
SET(PROJECT_RESOURCES
#include <ModelAPI_Object.h>
#include <ModelAPI_Tools.h>
+#include <ModuleBase_ResultPrs.h>
+
#include <GeomAPI_Shape.h>
#include <GeomAPI_IPresentable.h>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <AIS_DimensionSelectionMode.hxx>
#include <AIS_Shape.hxx>
+#include <AIS_Dimension.hxx>
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <set>
if (isVisible(theObject)) {
redisplay(theObject, isUpdateViewer);
} else {
- boost::shared_ptr<GeomAPI_AISObject> anAIS;
+ AISObjectPtr anAIS;
GeomPresentablePtr aPrs = boost::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
bool isShading = false;
if (aPrs) {
- anAIS = aPrs->getAISObject(boost::shared_ptr<GeomAPI_AISObject>());
+ anAIS = aPrs->getAISObject(AISObjectPtr());
} else {
ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aResult) {
boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
if (aShapePtr) {
- anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
- anAIS->createShape(aShapePtr);
+ anAIS = AISObjectPtr(new GeomAPI_AISObject());
+ anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
+ //anAIS->createShape(aShapePtr);
isShading = true;
}
}
}
}
-void XGUI_Displayer::display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS,
+void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
bool isShading, bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
- boost::shared_ptr<GeomAPI_AISObject> anObject = myResult2AISObjectMap[theObject];
+ AISObjectPtr anObject = myResult2AISObjectMap[theObject];
if (anObject) {
Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
if (!isVisible(theObject))
return;
- Handle(AIS_InteractiveObject) aAISIO;
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+ AISObjectPtr aAISObj = getAISObject(theObject);
+ Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+
GeomPresentablePtr aPrs = boost::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
if (aPrs) {
- boost::shared_ptr<GeomAPI_AISObject> aAIS_Obj = aPrs->getAISObject(aAISObj);
- if (aAISObj && !aAIS_Obj) {
+ AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
+ if (!aAIS_Obj) {
erase(theObject, isUpdateViewer);
return;
}
- aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
- } else {
- ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (aResult) {
- boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
- if (aShapePtr) {
- Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(
- aAISObj->impl<Handle(AIS_InteractiveObject)>());
- if (!aAISShape.IsNull()) {
- aAISShape->Set(aShapePtr->impl<TopoDS_Shape>());
- aAISIO = aAISShape;
- }
- }
+ if (aAIS_Obj != aAISObj) {
+ myResult2AISObjectMap[theObject] = aAIS_Obj;
}
+ aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
}
+
if (!aAISIO.IsNull()) {
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
aContext->Redisplay(aAISIO, isUpdateViewer);
- //if (aContext->HasOpenedContext()) {
- // aContext->Load(aAISIO, -1, true/*allow decomposition*/);
- //}
}
}
if (aContext.IsNull())
return;
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theObject];
+ AISObjectPtr anObj = myResult2AISObjectMap[theObject];
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
aContext->Deactivate(anAIS);
}
}
-void XGUI_Displayer::activate(ObjectPtr theObject)
+void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes)
{
if (isVisible(theObject)) {
Handle(AIS_InteractiveContext) aContext = AISContext();
if (aContext.IsNull())
return;
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theObject];
+ AISObjectPtr anObj = myResult2AISObjectMap[theObject];
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
- aContext->Activate(anAIS);
+ if (aContext->HasOpenedContext()) {
+ aContext->Load(anAIS, -1, true);
+ }
+ if (theModes.size() > 0) {
+ foreach(int aMode, theModes) {
+ aContext->Activate(anAIS, aMode);
+ }
+ } else
+ aContext->Activate(anAIS);
}
}
if (!isVisible(theObject))
return false;
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap.at(theObject);
+ AISObjectPtr anObj = myResult2AISObjectMap.at(theObject);
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
TColStd_ListOfInteger aModes;
if (myResult2AISObjectMap.find(aResult) == myResult2AISObjectMap.end())
continue;
- boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[aResult];
+ AISObjectPtr anObj = myResult2AISObjectMap[aResult];
if (anObj) {
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull())
updateViewer();
}
+
+void XGUI_Displayer::clearSelected()
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (aContext) {
+ aContext->UnhilightCurrents(false);
+ aContext->ClearSelected();
+ }
+}
+
void XGUI_Displayer::eraseAll(const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) ic = AISContext();
ResultToAISMap::iterator aIt;
for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) {
// erase an object
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = (*aIt).second;
+ AISObjectPtr aAISObj = (*aIt).second;
Handle(AIS_InteractiveObject) anIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
if (!anIO.IsNull())
ic->Remove(anIO, false);
for (; aFIt != aFLast; aFIt++) {
ObjectPtr aFeature = (*aFIt).first;
if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
- boost::shared_ptr<GeomAPI_AISObject> anObj = (*aFIt).second;
+ AISObjectPtr anObj = (*aFIt).second;
if (!anObj)
continue;
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
closeAllContexts(true);
}
-boost::shared_ptr<GeomAPI_AISObject> XGUI_Displayer::getAISObject(ObjectPtr theObject) const
+AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const
{
- boost::shared_ptr<GeomAPI_AISObject> anIO;
+ AISObjectPtr anIO;
if (myResult2AISObjectMap.find(theObject) != myResult2AISObjectMap.end())
anIO = (myResult2AISObjectMap.find(theObject))->second;
return anIO;
}
-ObjectPtr XGUI_Displayer::getObject(Handle(AIS_InteractiveObject) theIO) const
+ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const
+{
+ Handle(AIS_InteractiveObject) aRefAIS = theIO->impl<Handle(AIS_InteractiveObject)>();
+ return getObject(aRefAIS);
+}
+
+ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const
{
ObjectPtr aFeature;
ResultToAISMap::const_iterator aFIt = myResult2AISObjectMap.begin(), aFLast =
myResult2AISObjectMap.end();
for (; aFIt != aFLast && !aFeature; aFIt++) {
- boost::shared_ptr<GeomAPI_AISObject> anObj = (*aFIt).second;
+ AISObjectPtr anObj = (*aFIt).second;
if (!anObj)
continue;
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
return myWorkshop->viewer()->AISContext();
}
-void XGUI_Displayer::display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate)
+void XGUI_Displayer::display(AISObjectPtr theAIS, bool isUpdate)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
aContext->Display(anAISIO, isUpdate);
}
-void XGUI_Displayer::erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate)
+void XGUI_Displayer::erase(AISObjectPtr theAIS, const bool isUpdate)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
}
}
-void XGUI_Displayer::activateObjectsOutOfContext(const std::list<int>& theModes,
- Handle(SelectMgr_Filter) theFilter)
+void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
// Open local context if there is no one
return;
aContext->UseDisplayedObjects();
- std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
- for (; anIt != aLast; anIt++) {
- aContext->ActivateStandardMode((TopAbs_ShapeEnum)(*anIt));
+ ResultToAISMap::iterator aIt;
+ Handle(AIS_InteractiveObject) anAISIO;
+ for (aIt = myResult2AISObjectMap.begin(); aIt != myResult2AISObjectMap.end(); aIt++) {
+ anAISIO = (*aIt).second->impl<Handle(AIS_InteractiveObject)>();
+ aContext->Load(anAISIO, -1, true);
+ if (theModes.size() == 0)
+ aContext->Activate(anAISIO);
+ else {
+ foreach(int aMode, theModes) {
+ aContext->Activate(anAISIO, aMode);
+ }
+ }
}
-
- if (!theFilter.IsNull())
- aContext->AddFilter(theFilter);
}
if (!aContext->HasOpenedContext())
return;
- aContext->RemoveFilters();
aContext->NotUseDisplayedObjects();
}
if (aContext.IsNull())
return;
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+ AISObjectPtr aAISObj = getAISObject(theObject);
if (!aAISObj)
return;
aContext->SetDisplayMode(aAISIO, theMode, toUpdate);
}
+void XGUI_Displayer::setSelectionModes(const QIntList& theModes)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (aContext.IsNull())
+ return;
+ if (!aContext->HasOpenedContext())
+ return;
+ // Clear previous mode
+ const TColStd_ListOfInteger& aModes = aContext->ActivatedStandardModes();
+ if (!aModes.IsEmpty()) {
+ TColStd_ListOfInteger aMModes;
+ aMModes.Assign(aModes);
+ TColStd_ListIteratorOfListOfInteger it(aMModes);
+ for(; it.More(); it.Next()) {
+ aContext->DeactivateStandardMode((TopAbs_ShapeEnum)it.Value());
+ }
+ }
+ foreach(int aMode, theModes) {
+ aContext->ActivateStandardMode((TopAbs_ShapeEnum)aMode);
+ }
+}
XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
{
if (aContext.IsNull())
return NoMode;
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theObject);
+ AISObjectPtr aAISObj = getAISObject(theObject);
if (!aAISObj)
return NoMode;
return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode();
}
+void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (aContext.IsNull())
+ return;
+ aContext->AddFilter(theFilter);
+}
+
+void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ if (aContext.IsNull())
+ return;
+ aContext->RemoveFilter(theFilter);
+}
void display(ObjectPtr theObject, bool isUpdateViewer = true);
/// Display the given AIS object. To hide this object use corresponde erase method
- void display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate = true);
+ void display(AISObjectPtr theAIS, bool isUpdate = true);
/// Stop the current selection and color the given features to the selection color
/// \param theFeatures a list of features to be disabled
*/
void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
+
+ /// Un select all objects
+ void clearSelected();
+
/// Erase the feature and a shape.
/// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
/// Erase the given AIS object displayed by corresponded display method
- void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
+ void erase(AISObjectPtr theAIS, const bool isUpdate = true);
/// Erase all presentations
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
void eraseDeletedResults(const bool isUpdateViewer = true);
+ /// Opens local context. Does nothing if it is already opened.
void openLocalContext();
/// Deactivates selection of sub-shapes
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
void closeLocalContexts(const bool isUpdateViewer = true);
+ /*
+ * Set modes of selections. Selection mode has to be defined by TopAbs_ShapeEnum.
+ * It doesn't manages a local context
+ * \param theModes - list of selection modes. If the list is empty then all selectoin modes will be cleared.
+ */
+ void setSelectionModes(const QIntList& theModes);
+
+ void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+ void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
/// Updates the viewer
void updateViewer();
/// Searches the interactive object by feature
/// \param theFeature the feature or NULL if it not visualized
/// \return theIO an interactive object
- boost::shared_ptr<GeomAPI_AISObject> getAISObject(ObjectPtr theFeature) const;
+ AISObjectPtr getAISObject(ObjectPtr theFeature) const;
/// Searches the feature by interactive object
/// \param theIO an interactive object
/// \return feature the feature or NULL if it not visualized
- ObjectPtr getObject(Handle(AIS_InteractiveObject) theIO) const;
+ ObjectPtr getObject(const AISObjectPtr& theIO) const;
+ ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
/// Deactivates the given object (not allow selection)
void deactivate(ObjectPtr theFeature);
/// Activates the given object (it can be selected)
- void activate(ObjectPtr theFeature);
+ /// \param theModes - modes on which it has to be activated (can be empty)
+ void activate(ObjectPtr theFeature, const QIntList& theModes);
/// Returns true if the given object can be selected
bool isActive(ObjectPtr theObject) const;
/// Activates in local context displayed outside of the context.
- /// \param theModes - selection modes to activate
- /// \param theFilter - filter for selection
- void activateObjectsOutOfContext(const std::list<int>& theModes,
- Handle(SelectMgr_Filter) theFilter);
+ /// \param theModes - modes on which it has to be activated (can be empty)
+ void activateObjectsOutOfContext(const QIntList& theModes);
+ /// Activates in local context displayed outside of the context.
void deactivateObjectsOutOfContext();
/// Sets display mode for the given object if this object is displayed
/// \param theAIS AIS presentation
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// Returns true if the Feature succesfully displayed
- void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isShading,
+ void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
bool isUpdateViewer = true);
/// Display the shape and activate selection of sub-shapes
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// \returns true if the presentation is created
//bool redisplay(ObjectPtr theObject,
- // boost::shared_ptr<GeomAPI_AISObject> theAIS,
+ // AISObjectPtr theAIS,
// const bool isUpdateViewer = true);
/** Redisplay the shape if it was displayed
protected:
XGUI_Workshop* myWorkshop;
- typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
+ typedef std::map<ObjectPtr, AISObjectPtr> ResultToAISMap;
ResultToAISMap myResult2AISObjectMap;
};
#include "XGUI_SelectionMgr.h"
#include "XGUI_Selection.h"
#include "XGUI_OperationMgr.h"
+#include "XGUI_Displayer.h"
+
+#include <AIS_Shape.hxx>
+
XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
: ModuleBase_IWorkshop(theWorkshop),
this, SIGNAL(operationStarted(ModuleBase_Operation*)));
connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
this, SIGNAL(operationStopped(ModuleBase_Operation*)));
+
+ myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this);
}
XGUI_ModuleConnector::~XGUI_ModuleConnector()
{
+ myDocumentShapeFilter.Nullify();
}
ModuleBase_ISelection* XGUI_ModuleConnector::selection() const
void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
{
- Handle(AIS_InteractiveContext) aAIS = myWorkshop->viewer()->AISContext();
- if (!aAIS->HasOpenedContext())
- aAIS->OpenLocalContext();
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ aDisp->openLocalContext();
+ // Convert shape types to selection types
+ QIntList aModes;
foreach(int aType, theTypes) {
- aAIS->ActivateStandardMode((TopAbs_ShapeEnum)aType);
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
}
+ aDisp->activateObjectsOutOfContext(aModes);
+ //TODO: We have to open Local context because at neutral point filters don't work (bug 25340)
+ aDisp->addSelectionFilter(myDocumentShapeFilter);
}
void XGUI_ModuleConnector::deactivateSubShapesSelection()
{
- Handle(AIS_InteractiveContext) aAIS = myWorkshop->viewer()->AISContext();
- aAIS->CloseAllContexts();
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ // The document limitation selection has to be only during operation
+ aDisp->removeSelectionFilter(myDocumentShapeFilter);
+ aDisp->closeLocalContexts(false);
+}
+
+AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const
+{
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ return aDisp->getAISObject(theObject);
}
+
+ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const
+{
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ return aDisp->getObject(theAIS);
+}
\ No newline at end of file
#include "XGUI.h"
#include <ModuleBase_Definitions.h>
#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_ViewerFilters.h>
class Handle_AIS_InteractiveContext;
class XGUI_Workshop;
//! Returns currently active operation
virtual ModuleBase_Operation* currentOperation() const;
+ //! Returns AIS opbject by data object
+ virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const;
+
+ //! Returns data object by AIS
+ virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
+
XGUI_Workshop* workshop() const { return myWorkshop; }
- private:
+private:
XGUI_Workshop* myWorkshop;
+
+ /// A filter which provides selection within a current document or whole PartSet
+ Handle(ModuleBase_ShapeDocumentFilter) myDocumentShapeFilter;
};
#endif
#include <QLayout>
#include <QApplication>
#include <QDialogButtonBox>
+#include <QPushButton>
const QString XGUI_Preferences::VIEWER_SECTION = "Viewer";
const QString XGUI_Preferences::MENU_SECTION = "Menu";
return false;
}
-void XGUI_Preferences::updateCustomProps()
+void XGUI_Preferences::updateConfigByResources()
{
Config_Properties aProps = Config_PropManager::getProperties();
Config_Properties::iterator aIt;
Config_Prop* aProp = (*aIt);
QString aVal = myResourceMgr->stringValue(QString(aProp->section().c_str()),
QString(aProp->name().c_str()));
- if (!aVal.isNull())
+ if (!aVal.isEmpty()) {
aProp->setValue(aVal.toStdString());
+ }
+ }
+}
+
+void XGUI_Preferences::updateResourcesByConfig()
+{
+ Config_Properties aProps = Config_PropManager::getProperties();
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ myResourceMgr->setValue(QString(aProp->section().c_str()), QString(aProp->name().c_str()),
+ QString(aProp->value().c_str()));
+ }
+}
+
+void XGUI_Preferences::resetConfig()
+{
+ Config_Properties aProps = Config_PropManager::getProperties();
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ aProp->setValue(aProp->defaultValue());
}
}
QStringList aParams = myResourceMgr->parameters(aSection);
foreach (QString aParam, aParams)
{
- Config_PropManager::registerProp(aSection.toStdString(), aParam.toStdString(), "",
- Config_Prop::Disabled,
- myResourceMgr->stringValue(aSection, aParam).toStdString());
+ Config_Prop* aProp = Config_PropManager::registerProp(aSection.toStdString(),
+ aParam.toStdString(), "", Config_Prop::Disabled);
+ aProp->setValue(myResourceMgr->stringValue(aSection, aParam).toStdString());
}
}
}
setFocusProxy(myPreferences);
myPreferences->setFrameStyle(QFrame::Box | QFrame::Sunken);
- QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
+ QDialogButtonBox::Reset,
Qt::Horizontal, this);
+ QPushButton* aDefaultButton = aBtnBox->button(QDialogButtonBox::Reset);
+ aDefaultButton->setText(tr("Default"));
+ connect(aDefaultButton, SIGNAL(clicked()), this, SLOT(onDefault()));
+
main->addWidget(aBtnBox);
connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
myIsChanged = true;
// Save custom properties
- XGUI_Preferences::updateCustomProps();
+ XGUI_Preferences::updateConfigByResources();
QDialog::accept();
}
theModified = myPreferences->modified();
}
+void XGUI_PreferencesDlg::onDefault()
+{
+ // reset main resources
+#ifdef WIN32
+ QtxResourceMgr::WorkingMode aPrev =
+ myPreferences->resourceMgr()->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
+ myPreferences->retrieve();
+ myPreferences->resourceMgr()->setWorkingMode(aPrev);
+#endif
+ // reset plugin's resources
+ XGUI_Preferences::resetConfig();
+ XGUI_Preferences::updateResourcesByConfig();
+
+ myPreferences->retrieve();
+}
+
//**********************************************************
//**********************************************************
//**********************************************************
/// It is used in case of necessity to define external resource manager (not NewGeom)
static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
- /// Updates properties defined by module from SUIT_ResourceMgr to Config_PropManager
- static void updateCustomProps();
+ /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
+ static void updateConfigByResources();
+
+ /// Updates SUIT_ResourceMgr values by Config_PropManager properties
+ /// \param theUpdateOnlyInvalid flag to update only invalid values, if it is false, all are updated
+ static void updateResourcesByConfig();
+
+ /// Set default values to the Config_PropManager properties
+ static void resetConfig();
/// Loads properties defined by module to Config_PropManager
static void loadCustomProps();
public slots:
virtual void accept();
+protected slots:
+ void onDefault();
+
private:
/// Create editors for aplication properties
void createEditors();
#endif
XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
- : ModuleBase_IPropertyPanel(theParent), myActiveWidget(0)
+ : ModuleBase_IPropertyPanel(theParent),
+ myActiveWidget(NULL)
{
this->setWindowTitle(tr("Property Panel"));
QAction* aViewAct = this->toggleViewAction();
{
myWidgets.clear();
qDeleteAll(myCustomWidget->children());
+ myActiveWidget = NULL;
}
void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this,
SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
- this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)));
+ this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
if (aPointWidget)
void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
{
- int aS = myWidgets.size();
foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
{
eachWidget->setFeature(theFeature);
eachWidget->restoreValue();
}
- // the repaint is used here to immediatelly react in GUI to the values change.
+ // the repaint is used here to immediately react in GUI to the values change.
repaint();
}
-
void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
{
- QObject* aSender = sender();
ModuleBase_ModelWidget* aNextWidget = 0;
QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
bool isFoundWidget = false;
}
isFoundWidget = (*anIt) == theWidget;
}
- myActiveWidget = aNextWidget;
- emit widgetActivated(myActiveWidget);
+ // Normaly focusTo is enough to activate widget
+ // here is a special case on mouse click in the viewer
+ if(aNextWidget == NULL) {
+ activateWidget(NULL);
+ }
}
void XGUI_PropertyPanel::activateNextWidget()
QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
anOkBtn->setEnabled(isEnabled);
}
+
+void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
+{
+ if(myActiveWidget) {
+ myActiveWidget->setHighlighted(false);
+ }
+ if(theWidget) {
+ theWidget->setHighlighted(true);
+ }
+ myActiveWidget = theWidget;
+ emit widgetActivated(theWidget);
+}
// Enables / disables "ok" ("accept") button
void setAcceptEnabled(bool);
-signals:
+ protected slots:
+ // Makes the given widget active, highlights it and removes
+ // highlighting from the previous active widget
+ // emits widgetActivated(theWidget) signal
+ void activateWidget(ModuleBase_ModelWidget* theWidget);
+
+ signals:
/// Signal about the point 2d set to the feature
/// \param the feature
/// \param the attribute of the feature
void storedPoint2D(ObjectPtr theFeature, const std::string& theAttribute);
+
private:
QWidget* myCustomWidget;
QList<ModuleBase_ModelWidget*> myWidgets;
}
//**************************************************************
-void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
+void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList,
+ std::list<ObjectPtr>& theOwners) const
{
theList.Clear();
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
TopoDS_Shape aShape = aContext->SelectedShape();
- if (!aShape.IsNull())
+ if (!aShape.IsNull()) {
theList.Append(aShape);
+ Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
+ Handle(AIS_InteractiveObject) anObj =
+ Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
+ ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
+ theOwners.push_back(anObject);
+ }
}
}
virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const;
//! Returns list of currently selected shapes
- virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const;
+ virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theShapes,
+ std::list<ObjectPtr>& theOwners) const;
private:
XGUI_Workshop* myWorkshop;
if (myStartPnt == myEndPnt) {
// the MoveTo is necessary for the second click in the same point. Otherwise the selection is lost.
- Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
- if (!aView3d.IsNull()) {
- myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
- }
+ //Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
+ //if (!aView3d.IsNull()) {
+ // myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
+ //}
if (aHasShift && myMultiSelectionEnabled)
myAISContext->ShiftSelect();
else
+++ /dev/null
-// File: XGUI_ViewerFilters.cpp
-// Created: 07 Okt 2014
-// Author: Vitaly SMETANNIKOV
-
-
-#include "XGUI_ViewerFilters.h"
-#include "XGUI_Displayer.h"
-
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Document.h>
-
-#include <AIS_InteractiveObject.hxx>
-
-IMPLEMENT_STANDARD_HANDLE(XGUI_ShapeDocumentFilter, SelectMgr_Filter);
-IMPLEMENT_STANDARD_RTTIEXT(XGUI_ShapeDocumentFilter, SelectMgr_Filter);
-
-
-//TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
-Standard_Boolean XGUI_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
-{
- if (theOwner->HasSelectable()) {
- Handle(AIS_InteractiveObject) aAisObj =
- Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
- if (!aAisObj.IsNull()) {
- ObjectPtr aObj = myDisplayer->getObject(aAisObj);
- if (aObj) {
- DocumentPtr aDoc = aObj->document();
- SessionPtr aMgr = ModelAPI_Session::get();
- return (aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument());
- }
- }
- }
- return Standard_False;
-}
\ No newline at end of file
+++ /dev/null
-// File: XGUI_ViewerFilters.h
-// Created: 07 Okt 2014
-// Author: Vitaly SMETANNIKOV
-
-
-#ifndef XGUI_ViewerFilters_H
-#define XGUI_ViewerFilters_H
-
-#include <SelectMgr_Filter.hxx>
-#include <SelectMgr_EntityOwner.hxx>
-
-
-class XGUI_Displayer;
-
-DEFINE_STANDARD_HANDLE(XGUI_ShapeDocumentFilter, SelectMgr_Filter);
-
-class XGUI_ShapeDocumentFilter: public SelectMgr_Filter
-{
-public:
- Standard_EXPORT XGUI_ShapeDocumentFilter(XGUI_Displayer* myDisp): SelectMgr_Filter(),
- myDisplayer(myDisp) {}
-
- Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
-
- DEFINE_STANDARD_RTTI(XGUI_ShapeDocumentFilter)
-
-private:
- XGUI_Displayer* myDisplayer;
-};
-
-#endif
\ No newline at end of file
{
std::set<ObjectPtr> aObjects = theMsg->objects();
std::set<ObjectPtr>::const_iterator aIt;
+ QIntList aModes;
for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
ObjectPtr aObj = (*aIt);
- if (!aObj->data() || !aObj->data()->isValid() || aObj->document()->isConcealed(aObj))
+ bool aHide = !aObj->data() || !aObj->data()->isValid();
+ if (!aHide) { // check that this is not hidden result
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ aHide = aRes && aRes->isConcealed();
+ }
+ if (aHide)
myDisplayer->erase(aObj, false);
else {
if (myDisplayer->isVisible(aObj)) {
ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
if (!aOperation->hasObject(aObj))
if (!myDisplayer->isActive(aObj))
- myDisplayer->activate(aObj);
+ myDisplayer->activate(aObj, aModes);
}
} else {
if (myOperationMgr->hasOperation()) {
// it doesn't stored in the operation mgr and doesn't displayed
} else if (myOperationMgr->hasOperation()) {
ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
- if (!(*aIt)->document()->isConcealed(*aIt) &&
- aOperation->hasObject(*aIt)) { // Display only current operation results
+ if (aOperation->hasObject(*aIt)) { // Display only current operation results
myDisplayer->display(*aIt, false);
isDisplayed = true;
}
connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
SLOT(onKeyReleased(QKeyEvent*)));
- //connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr,
- // SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
- //connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel,
- // SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
SLOT(setAcceptEnabled(bool)));