#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()
{
<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" />
#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
*/
};
+//! Pointer on attribute object
+typedef boost::shared_ptr<GeomAPI_Shape> GeomShapePtr;
+
#endif
* \brief Interface to the edge object
*/
-class GEOMAPI_EXPORT GeomAPI_Wire : public GeomAPI_Shape
+class GeomAPI_Wire : public GeomAPI_Shape
{
public:
/// Creation of empty (null) shape
- GeomAPI_Wire();
+ GEOMAPI_EXPORT GeomAPI_Wire();
- virtual bool isVertex() const
+ GEOMAPI_EXPORT virtual bool isVertex() const
{
return false;
}
/// Returns whether the shape is an edge
- virtual bool isEdge() const
+ GEOMAPI_EXPORT virtual bool isEdge() const
{
return false;
}
- void addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge);
- std::list<boost::shared_ptr<GeomAPI_Shape> > getEdges();
+ 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
- bool hasPlane() const { return myOrigin && myNorm && myDirX && myDirY; }
+ GEOMAPI_EXPORT bool hasPlane() const { return myOrigin && myNorm && myDirX && myDirY; }
/// Set/Get origin point
- void setOrigin(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin) { myOrigin = theOrigin; }
- boost::shared_ptr<GeomAPI_Pnt> origin() const { return myOrigin; }
+ 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
- void setDirX(const boost::shared_ptr<GeomAPI_Dir>& theDirX) { myDirX = theDirX; }
- boost::shared_ptr<GeomAPI_Dir> dirX() const { return myDirX; }
+ 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
- void setDirY(const boost::shared_ptr<GeomAPI_Dir>& theDirY) { myDirY = theDirY; }
- boost::shared_ptr<GeomAPI_Dir> dirY() const { return myDirY; }
+ 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
- void setNorm(const boost::shared_ptr<GeomAPI_Dir>& theNorm) { myNorm = theNorm; }
- boost::shared_ptr<GeomAPI_Dir> norm() const { return myNorm; }
+ 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;
Config
GeomData
GeomAPI
+ GeomAlgoAPI
${CAS_OCAF}
${CAS_TKCAF}
${CAS_SHAPE}
../Config
../GeomData
../GeomDataAPI
+ ../GeomAlgoAPI
../GeomAPI
${CAS_INCLUDE_DIRS}
)
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_CompositeFeature.h>
#include <GeomAPI_Shape.h>
+#include <GeomAPI_Wire.h>
+#include <GeomAlgoAPI_SketchBuilder.h>
#include <TNaming_Selector.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_Tool.hxx>
#include <TNaming_Builder.hxx>
#include <TopoDS_Shape.hxx>
-#include <TDataStd_ReferenceList.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;
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(myRef.myRef->Label());
+ 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_Wire> aWirePtr = boost::dynamic_pointer_cast<GeomAPI_Wire>(
+ 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()) {
+ 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)
{
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;
+ TColStd_MapOfTransient allCurves;
for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) {
- allEdges.Add(anEdgeExp.Current());
+ 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_ReferenceList) aRefs = TDataStd_ReferenceList::Set(aLab);
+ 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);
boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
if (aConstr->shape()) {
const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
- 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);
+ 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));
+ }
}
}
}
/// 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);
{
int aNewTag = mySize->Get() + 1;
TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
- mySubs.push_back(boost::shared_ptr<Model_AttributeSelection>(
- new Model_AttributeSelection(aNewLab)));
+
+ 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()
void Model_AttributeSelectionList::clear()
{
- mySubs.clear();
- TDF_ChildIterator aSubIter(mySize->Label());
- for(; aSubIter.More(); aSubIter.Next()) {
- aSubIter.Value().ForgetAllAttributes(Standard_True);
+ if (!mySubs.empty()) {
+ mySubs.clear();
+ TDF_ChildIterator aSubIter(mySize->Label());
+ for(; aSubIter.More(); aSubIter.Next()) {
+ aSubIter.Value().ForgetAllAttributes(Standard_True);
+ }
+ owner()->data()->sendAttributeUpdated(this);
}
}
}
return false;
}
+
+int Model_Data::featureId() const
+{
+ return myLab.Father().Tag(); // tag of the feature label
+}
/// 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;
+
};
#endif
#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>
}
}
}
+ // selection attributes: must be called "update" methods if needed
+ aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+ for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
+ boost::shared_ptr<ModelAPI_AttributeSelection> aSel =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
+ if (updateObject(aSel->context())) {
+ aMustbeUpdated = true;
+ // aSel->update(); // this must be done on execution since it may be long operation
+ }
+ }
+ // lists of selection attributes: must be called "update" methods if needed
+ 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--) {
+ if (updateObject(aSel->value(a)->context())) {
+ 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
+ aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+ for (aRefsIter = aRefs.begin(); 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(...) {
/// 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
}
};
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeSelectionList> AttributeSelectionListPtr;
+
#endif
/// 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
/// 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
ModelAPI_Data()
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_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_ */
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()));
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();
<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) {
}
}
return mySketch;
-}
+}*/
AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
AISObjectPtr thePrevious)
static AISObjectPtr simpleAISObject(boost::shared_ptr<ModelAPI_Result> theRes,
AISObjectPtr thePrevious);
+ /// 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();
#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();
return boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
}
+int SketchPlugin_Sketch::subFeatureId(const int theIndex) const
+{
+ return subFeature(theIndex)->data()->featureId();
+}
+
boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
{
boost::shared_ptr<GeomDataAPI_Point> aC = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
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;}
<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"/>
}
//**************************************************************
-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;