return;
boost::shared_ptr<GeomAPI_Shape> aFace =
boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
+ if (!aFace)
+ return;
double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
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);
#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_CompositeFeature.h>
#include <GeomAPI_Shape.h>
#include <TNaming_Selector.hxx>
#include <TNaming_NamedShape.hxx>
+#include <TNaming_Tool.hxx>
#include <TopoDS_Shape.hxx>
+#include <TDataStd_ReferenceList.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.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);
}
void Model_AttributeSelection::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
{
+ ModelAPI_AttributeSelection::setObject(theObject);
myRef.setObject(theObject);
}
+
+void Model_AttributeSelection::selectBody(
+ const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ // perform the selection
+ TNaming_Selector aSel(myRef.myRef->Label());
+ 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
+ throw std::invalid_argument("a result with shape is expected");
+ }
+ Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aNewShape, myRef.myRef->Label());
+ TDF_Label aLab = aNS->Label();
+
+ aSel.Select(aNewShape, aContext);
+}
+
+#include <BRepTools.hxx>
+
+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>();
+ TopTools_MapOfShape allEdges;
+ for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) {
+ BRepTools::Write(anEdgeExp.Current(), "D:\\selected.brep");
+ allEdges.Add(anEdgeExp.Current());
+ }
+ // iterate and store the result ids of sub-elements
+ Handle(TDataStd_ReferenceList) aRefs = TDataStd_ReferenceList::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()) {
+ const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
+ BRepTools::Write(aResShape, "D:\\sub.brep");
+ if (allEdges.Contains(aResShape)) {
+ boost::shared_ptr<Model_Data> aSubData = boost::dynamic_pointer_cast<Model_Data>(aSub->data());
+ TDF_Label aSubLab = aSubData->label();
+ aRefs->Append(aSubLab);
+ }
+ }
+ }
+ }
+}
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);
friend class Model_Data;
};
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
ModelAPI_Session.h
ModelAPI_Plugin.h
ModelAPI_Feature.h
+ ModelAPI_CompositeFeature.h
ModelAPI_Data.h
ModelAPI_Object.h
ModelAPI_Document.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()
--- /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;
+};
+
+//! Pointer on the composite feature object
+typedef boost::shared_ptr<ModelAPI_CompositeFeature> CompositeFeaturePtr;
+
+#endif
}
/// 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;
}
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.
#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
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();
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)
{
}
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();
/// 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)
{
}
}
-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.
PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId,
QObject* theParent,
- FeaturePtr theFeature)
+ CompositeFeaturePtr theFeature)
: PartSet_OperationSketchBase(theId, theParent),
mySketch(theFeature),
myIsBlockedSelection(false)
}
}
-FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
+CompositeFeaturePtr PartSet_OperationFeatureEditMulti::sketch() const
{
return mySketch;
}
/// \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
{
}
-FeaturePtr PartSet_OperationSketch::sketch() const
+CompositeFeaturePtr PartSet_OperationSketch::sketch() const
{
- return feature();
+ return boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(feature());
}
void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
/// 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
/// 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
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
// 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();
#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)
- {
- }
- ;
-
/// Returns true if this feature must be displayed in the history (top level of Part tree)
SKETCHPLUGIN_EXPORT virtual bool isInHistory()
{
setResult(aConstr);
}
-const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature)
+boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string theID)
{
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature)->setSketch(this);
- data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(theFeature);
+ 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);
}
boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
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();
+ 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;
+
protected:
/// Creates a plane and append it to the list
/// \param theX the X normal value
// ========================================================
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;
}
// 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: