}
}
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
+ GeomShapePtr theShape)
+{
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aResult);
+ aSelectionListAttr->append(aResult, theShape);
+}
+
//********************************************************************
void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
{
// Store selection in the attribute
int aSize = mySelection.size();
foreach (GeomSelection aSelec, mySelection) {
- aSelectionListAttr->append(aSelec.first, aSelec.second);
+ setObject(aSelec.first, aSelec.second);
}
}
//********************************************************************
bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
- //TopoDS_Shape aShape = thePrs.shape();
- //if (!acceptSubShape(aShape))
- // return false;
-
- ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
- /*
- if (myFeature) {
- // We can not select a result of our feature
- const std::list<ResultPtr>& aResList = myFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- bool isSkipSelf = false;
- for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
- if ((*aIt) == aResult) {
- isSkipSelf = true;
- break;
- }
- }
- if(isSkipSelf)
- return false;
- }*/
+ // DEBUG_THE_SAME_AS_SHAPE
+ ObjectPtr anObject;
+ GeomShapePtr aShape;
+ getGeomSelection(thePrs, anObject, aShape);
- // if the result has the similar shap as the parameter shape, just the context is set to the
- // selection list attribute.
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
-
- /*const TopoDS_Shape& aTDSShape = thePrs.shape();
- // if only result is selected, an empty shape is set to the model
- if (aTDSShape.IsNull()) {
- aSelectionListAttr->append(aResult, GeomShapePtr());
- }
- else {
- GeomShapePtr aShape(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(aTDSShape));
- // We can not select a result of our feature
- if (aShape->isEqual(aResult->shape()))
- aSelectionListAttr->append(aResult, GeomShapePtr());
- else
- aSelectionListAttr->append(aResult, aShape);
- }*/
- GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
- aSelectionListAttr->append(aResult, aShape);
-
+ setObject(anObject, aShape);
return true;
}
return aSelected;
}
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape)
+{
+ // DEBUG_THE_SAME_AS_SHAPE
+ theObject = myWorkshop->selection()->getResult(thePrs);
+ theShape = myWorkshop->selection()->getShape(thePrs);
+}
+
//********************************************************************
void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList)
{
/// Slot is called on selection of list of selected items
void onListSelection();
- protected:
+protected:
/// The methiod called when widget is activated
virtual void activateCustom();
/// parameters of the current attribute
virtual void storeAttributeValue();
+ /// Append the values to the model attribute of the widget. It casts this attribute to
+ /// the specific type and set the given values
+ /// \param theSelectedObject an object
+ /// \param theShape a selected shape, which is used in the selection attribute
+ /// \return true if it is succeed
+ void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
/// a shape. If the attribute do not uses the shape, it is empty
QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
- protected:
/// Update selection list
void updateSelectionList(AttributeSelectionListPtr);
+ /// Return an object and geom shape by the viewer presentation
+ /// \param thePrs a selection
+ /// \param theObject an output object
+ /// \param theShape a shape of the selection
+ virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape);
+
/// Converts the XML defined type choice to the validator type
/// For example, the "Edges" is converted to "edge"
std::string validatorType(const QString& theType) const;
#include <list>
#include <string>
-//#define DEBUG_SHAPE_VALIDATION_PREVIOUS
-
ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
}
//********************************************************************
-bool ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
+void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
GeomShapePtr theShape)
{
- bool isChanged = false;
- FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject);
- if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
- return isChanged;
-
DataPtr aData = myFeature->data();
AttributeReferencePtr aRef = aData->reference(attributeID());
if (aRef) {
ObjectPtr aObject = aRef->value();
if (!(aObject && aObject->isSame(theSelectedObject))) {
aRef->setValue(theSelectedObject);
- isChanged = true;
}
} else {
AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
ObjectPtr aObject = aRefAttr->object();
if (!(aObject && aObject->isSame(theSelectedObject))) {
aRefAttr->setObject(theSelectedObject);
- isChanged = true;
}
} else {
AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
if (aSelectAttr.get() != NULL) {
aSelectAttr->setValue(aResult, theShape);
- isChanged = true;
}
}
}
- return isChanged;
}
//********************************************************************
return aSelected;
}
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape)
+{
+ theObject = myWorkshop->selection()->getResult(thePrs);
+ theShape = myWorkshop->selection()->getShape(thePrs);
+}
+
//********************************************************************
void ModuleBase_WidgetShapeSelector::clearAttribute()
{
//********************************************************************
bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
-#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS
- return true;
-#endif
-
GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
bool aValid;
// if there is no selected shape, the method returns true
TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
aValid = acceptSubShape(aTopoShape);
}
+ if (aValid) {
+ // In order to avoid selection of the same object
+ ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult);
+ aValid = aSelectedFeature != myFeature;
+ }
return aValid;
}
//********************************************************************
bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
- bool isDone = false;
-
- ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
-
- // It should be checked by corresponded validator
- //ObjectPtr aObject = thePrs.object();
- //ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
- /*
- if ((!aCurrentObject) && (!aObject))
- return false;*/
-
- // It should be checked by corresponded validator
- // Check that the selected object is result (others can not be accepted)
- //ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
- //if (!aRes)
- // return false;
- /*if (myFeature) {
- // We can not select a result of our feature
- const std::list<std::shared_ptr<ModelAPI_Result>>& aResList = myFeature->results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
- for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
- if ((*aIt) == aRes)
- return false;
- }
- }
- */
- // It should be checked by corresponded validator
- /*
- // Check that object belongs to active document or PartSet
- DocumentPtr aDoc = aRes->document();
- SessionPtr aMgr = ModelAPI_Session::get();
- if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument()))
- return false;*/
-
-#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS
- // It should be checked by corresponded validator
- // Check that the result has a shape
- GeomShapePtr aShape = ModelAPI_Tools::shape(aRes);
- if (!aShape)
- return false;
-
- // Get sub-shapes from local selection
- if (!thePrs.shape().IsNull()) {
- aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(thePrs.shape()));
- }
-
- // Check that the selection corresponds to selection type
- TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
- if (!acceptSubShape(aTopoShape))
- return false;
-#else
- // the difference is that the next method returns an empty shape if the result has the same shape
- // to be checked for all cases and uncommented
- GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
-#endif
+ ObjectPtr anObject;
+ GeomShapePtr aShape;
+ getGeomSelection(thePrs, anObject, aShape);
- setObject(aResult, aShape);
+ setObject(anObject, aShape);
return true;
}
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
/// \return true if it is succeed
- virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+ virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
/// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
/// \return a shape
/// a shape. If the attribute do not uses the shape, it is empty
QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
+ /// Return an object and geom shape by the viewer presentation
+ /// \param thePrs a selection
+ /// \param theObject an output object
+ /// \param theShape a shape of the selection
+ virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape);
+
//----------- Class members -------------
protected:
/// Label of the widget
#include <XGUI_Workshop.h>
+#include <SketchPlugin_Feature.h>
+
#include <QString>
PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue)
}
}
+bool PartSet_ExternalObjectsMgr::isValidObject(const ObjectPtr& theObject)
+{
+ bool aValid = true;
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ // Do check using of external feature
+ std::shared_ptr<SketchPlugin_Feature> aSPFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+
+ // Do check that we can use external feature
+ if (aSPFeature.get() != NULL && aSPFeature->isExternal() && !useExternal()) {
+ aValid = false;
+ }
+
+ return aValid;
+}
+
ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
const GeomShapePtr& theShape,
const CompositeFeaturePtr& theSketch)
/// Returns the state whether the external object is used
bool useExternal() const { return myUseExternal; }
+ bool isValidObject(const ObjectPtr& theObject);
+
/// Finds or create and external object
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
ObjectPtr externalObjectValidated(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape,
const CompositeFeaturePtr& theSketch);
-
// Removes the external presentation from the model
/// \param theSketch a current sketch
/// \param theFeature a current feature
myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature);
}
+//********************************************************************
+bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+ bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
+ if (aValid) {
+ ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
+ aValid = myExternalObjectMgr->isValidObject(anObject);
+ }
+ return aValid;
+}
+
//********************************************************************
void PartSet_WidgetMultiSelector::storeAttributeValue()
{
myExternalObjectMgr->removeExternalValidated(sketch(), myFeature);
}
-//********************************************************************
-bool PartSet_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
- //TopoDS_Shape aShape = thePrs.shape();
- //if (!acceptSubShape(aShape))
- // return false;
-
- ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
- /*if (myFeature) {
- // We can not select a result of our feature
- const std::list<ResultPtr>& aResList = myFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- bool isSkipSelf = false;
- for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
- if ((*aIt) == aResult) {
- isSkipSelf = true;
- break;
- }
- }
- if(isSkipSelf)
- return false;
- }*/
-
- /*GeomShapePtr aGShape = GeomShapePtr();
- const TopoDS_Shape& aTDSShape = thePrs.shape();
- // if only result is selected, an empty shape is set to the model
- if (aTDSShape.IsNull()) {
- //aSelectionListAttr->append(aResult, GeomShapePtr());
- }
- else {
- aGShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- //GeomShapePtr aShape(new GeomAPI_Shape());
- aGShape->setImpl(new TopoDS_Shape(aTDSShape));
- // We can not select a result of our feature
- if (aGShape->isEqual(aResult->shape())) {
- //aSelectionListAttr->append(aResult, GeomShapePtr());
- aGShape = GeomShapePtr();
- }
- else {
- //aSelectionListAttr->append(aResult, aShape);
- }
- }*/
-
- GeomShapePtr aGShape = myWorkshop->selection()->getShape(thePrs);
- setObject(aResult, aGShape);
- return true;
-}
-
-//********************************************************************
-bool PartSet_WidgetMultiSelector::setObject(const ObjectPtr& theSelectedObject,
- const GeomShapePtr& theShape)
+void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape)
{
- ObjectPtr aSelectedObject = theSelectedObject;
- GeomShapePtr aShape = theShape;
+ ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape);
- FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject);
- //if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
- // return false;
-
- // Do check using of external feature
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
-
- // Do check that we can use external feature
- if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal()))
- return false;
-
- if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myExternalObjectMgr->useExternal()) {
+ // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
+ if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() &&
+ myExternalObjectMgr->useExternal()) {
if (myIsInVaildate)
- aSelectedObject = myExternalObjectMgr->externalObjectValidated(theSelectedObject, theShape, sketch());
+ theObject = myExternalObjectMgr->externalObjectValidated(theObject, theShape, sketch());
else
- aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch());
+ theObject = myExternalObjectMgr->externalObject(theObject, theShape, sketch());
}
-
-
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aSelectedObject);
-
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
-
- aSelectionListAttr->append(aResult, aShape);
-
- return true;
}
/// Retrurns installed sketcher
CompositeFeaturePtr sketch() const { return mySketch; }
- /// Fills the attribute with the value of the selected owner
- /// \param theOwner a selected owner
- virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
-
public slots:
/// Slot is called on selection changed
virtual void onSelectionChanged();
protected:
+ /// Checks the widget validity. By default, it returns true.
+ /// \param theValue a selected presentation in the view
+ /// \return a boolean value
+ virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
/// \param theValid a boolean flag, if restore happens for valid parameters
void restoreAttributeValue(const bool theValid);
- /// Store the values to the model attribute of the widget. It casts this attribute to
- /// the specific type and set the given values
- /// \param theSelectedObject an object
- /// \param theShape a selected shape, which is used in the selection attribute
- /// \return true if it is succeed
- bool setObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape);
+ /// Return an object and geom shape by the viewer presentation
+ /// \param thePrs a selection
+ /// \param theObject an output object
+ /// \param theShape a shape of the selection
+ virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape);
protected:
PartSet_ExternalObjectsMgr* myExternalObjectMgr;
delete myExternalObjectMgr;
}
-bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
+//********************************************************************
+bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
- ObjectPtr aSelectedObject = theSelectedObject;
- //GeomShapePtr aShape = theShape;
+ bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
+ if (aValid) {
+ ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
+ aValid = myExternalObjectMgr->isValidObject(anObject);
+ }
+ return aValid;
+}
- FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject);
- if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
- return false;
+//********************************************************************
+void PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
+{
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject);
// Do check using of external feature
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+ // Processing of sketch object
+ if (aSPFeature.get() != NULL && theShape.get())
+ setPointAttribute(theSelectedObject, theShape);
+ else
+ ModuleBase_WidgetShapeSelector::setObject(theSelectedObject, theShape);
+}
- // Do check that we can use external feature
- if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal()))
- return false;
-
- if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() && myExternalObjectMgr->useExternal()) {
- aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch());
- } else {
- // Processing of sketch object
- if (theShape.get()) {
- setPointAttribute(theSelectedObject, theShape);
- return true;
- }
- }
- return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);
+void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape)
+{
+ ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
+
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
+ std::shared_ptr<SketchPlugin_Feature> aSPFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+ // there is no a sketch feature is selected, but the shape exists, try to create an exernal object
+ if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() &&
+ myExternalObjectMgr->useExternal())
+ theObject = myExternalObjectMgr->externalObject(theObject, theShape, sketch());
}
//********************************************************************
CompositeFeaturePtr sketch() const { return mySketch; }
protected:
+ /// Checks the widget validity. By default, it returns true.
+ /// \param theValue a selected presentation in the view
+ /// \return a boolean value
+ virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
/// Store the values to the model attribute of the widget. It casts this attribute to
/// the specific type and set the given values
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
- virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+ /// \return true if it is succeed
+ virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+
+ /// Return an object and geom shape by the viewer presentation
+ /// \param thePrs a selection
+ /// \param theObject an output object
+ /// \param theShape a shape of the selection
+ virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape);
/// Get the shape from the attribute if the attribute contain a shape
/// It processes the ref attr type of attributes. It obtains the referenced attribute,