if (anAIS.IsNull())
return;
Quantity_Color aColor((Quantity_NameOfColor) theColor);
- anAIS->SetColor(aColor);
Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS);
if (!aDimAIS.IsNull()) {
aDimAIS->DimensionAspect()->SetCommonColor(aColor);
if (aColor.IsEqual(aCurrentColor))
return false;
- anAIS->SetColor(aColor);
Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS);
if (!aDimAIS.IsNull()) {
aDimAIS->DimensionAspect()->SetCommonColor(aColor);
void ModuleBase_Operation::start()
{
+ myIsModified = false;
QString anId = getDescription()->operationId();
if (myIsEditing) {
anId = anId.append(EditSuffix());
emit triggered(theState);
}
+void ModuleBase_Operation::onValuesChanged()
+{
+ myIsModified = true;
+}
+
//TODO: nds stabilization hotfix
void ModuleBase_Operation::commitOperation()
{
myPropertyPanel = theProp;
myPropertyPanel->setEditingMode(isEditOperation());
+ if (myPropertyPanel) {
+ const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
+ QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+ for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
+ ModuleBase_ModelWidget* aWgt = (*aWIt);
+ connect(aWgt, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
+ }
+ }
+
// Do not activate widgets by default if the current operation is editing operation
// Because we don't know which widget is going to be edited.
if (!isEditOperation())
/// Returns True if data of its feature was modified during operation
virtual bool isModified() const { return myIsModified; }
+ /// Change the modified state of the operation
+ void setIsModified(const bool theIsModified) { myIsModified = theIsModified; }
+
/// Returns True id the current operation is launched in editing mode
bool isEditOperation() const { return myIsEditing; }
/// \param theState th flag to abort, if it is true, do nothing, overwise abort
void setRunning(bool theState);
+ /// Changes the modified flag of the operation
+ void onValuesChanged();
+
protected:
/// Virtual method called when operation started (see start() method for more description)
/// Default impl calls corresponding slot and commits immediately.
// Author: Natalia ERMOLAEVA
#include <PartSet_CustomPrs.h>
+#include <PartSet_Module.h>
+#include "PartSet_OperationPrs.h"
#include <XGUI_ModuleConnector.h>
#include <XGUI_Workshop.h>
#include <Config_PropManager.h>
#include <AIS_InteractiveContext.hxx>
+#include <AIS_InteractiveObject.hxx>
+#include <Prs3d_PointAspect.hxx>
#define OPERATION_PARAMETER_COLOR "255, 255, 0"
PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
: myWorkshop(theWorkshop)
{
- Handle(PartSet_OperationPrs) myOperationPrs = new PartSet_OperationPrs(); /// AIS presentation for the feature of operation
+ myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
+ myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop)));
+
+ std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
+ OPERATION_PARAMETER_COLOR);
+ myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+ myOperationPrs->setPointMarker(5, 2.);
+ myOperationPrs->setWidth(1);
}
-void PartSet_CustomPrs::setCustomized(const FeaturePtr& theFeature)
+bool PartSet_CustomPrs::isActive() const
{
+ Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+
+ return aContext->IsDisplayed(anOperationPrs);
+}
- myOperationPrs->setFeature(theFeature);
- /* QMap<ResultPtr, QList<GeomShapePtr> > aNewCustomized;
+void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
+{
+ Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
- QList<GeomShapePtr> aShapeList;
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (aResult.get()) {
- aNewCustomized[aResult] = aShapeList;
- }
- else {
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- if (aFeature.get()) {
- std::list<AttributePtr> anAttributes = aFeature->data()->attributes("");
- std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
- for (; anIt != aLast; anIt++) {
- AttributePtr anAttribute = *anIt;
- ObjectPtr anObject = GeomValidators_Tools::getObject(anAttribute);
- if (anObject.get()) {
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- if (aResult.get())
- aNewCustomized[aResult] = aShapeList;
- }
- else if (anAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
- std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
- for(int i = 0; i < aCurSelList->size(); i++) {
- std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
- ObjectPtr anObject = GeomValidators_Tools::getObject(aSelAttribute);
- if (anObject.get()) {
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- if (aResult.get())
- aNewCustomized[aResult] = aShapeList;
- }
- }
- }
- }
- }
+ if (anOperationPrs->canActivate(theFeature)) {
+ anOperationPrs->setFeature(theFeature);
+ if (theFeature.get())
+ displayPresentation();
}
+}
+
+void PartSet_CustomPrs::deactivate()
+{
+ Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
+ anOperationPrs->setFeature(FeaturePtr());
+
+ erasePresentation();
+}
+
+
+void PartSet_CustomPrs::displayPresentation()
+{
+ Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
- bool isDone = false;
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
- XGUI_Displayer* aDisplayer = aWorkshop->displayer();
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
- // find objects which are not customized anymore
- QMap<ResultPtr, QList<GeomShapePtr> > aNotCustomized;
- QMap<ResultPtr, QList<GeomShapePtr> >::const_iterator anIt = myCustomized.begin(),
- aLast = myCustomized.end();
- for (; anIt != aLast; anIt++) {
- ResultPtr aResult = anIt.key();
- if (!aNewCustomized.contains(aResult))
- aNotCustomized[aResult] = aShapeList;
+ if (!aContext->IsDisplayed(anOperationPrs)) {
+ PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+ aContext->Display(anOperationPrs);
+ aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
}
+ else
+ anOperationPrs->Redisplay();
+}
- myCustomized.clear();
- // restore the previous state of the object if there is no such object in the new map
- for (anIt = aNotCustomized.begin(), aLast = aNotCustomized.end(); anIt != aLast; anIt++) {
- ResultPtr aResult = anIt.key();
- AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult);
- if (anAISObj.get()) {
- Handle(AIS_InteractiveObject) anAISIO = anAISObj->impl<Handle(AIS_InteractiveObject)>();
- aContext->Redisplay(anAISIO, false);
- }
- isDone = aDisplayer->customizeObject(aResult);
- }
+void PartSet_CustomPrs::erasePresentation()
+{
+ Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ if (aContext->IsDisplayed(anOperationPrs))
+ aContext->Remove(anOperationPrs);
+}
+
+Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const
+{
+ Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
+ return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
+}
+
+bool PartSet_CustomPrs::customize(const ObjectPtr& theObject)
+{
+ // the presentation should be recomputed if the previous AIS depend on the result
+ // [it should be hiddend] or the new AIS depend on it [it should be visualized]
+ Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ if (aContext->IsDisplayed(anOperationPrs)) {
+ bool aChanged = anOperationPrs->dependOn(theObject);
- // set customized for the new objects
- myCustomized = aNewCustomized;
- for (anIt = myCustomized.begin(), aLast = myCustomized.end(); anIt != aLast; anIt++) {
- ResultPtr aResult = anIt.key();
- AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult);
- if (anAISObj.get())
- isDone = customisePresentation(aResult, anAISObj, 0) || isDone;
+ anOperationPrs->updateShapes();
+ aChanged = aChanged || anOperationPrs->dependOn(theObject);
+
+ //if (aChanged)
+ anOperationPrs->Redisplay();
}
- if (isDone)
- aDisplayer->updateViewer();*/
+ return false;
}
-/*#include <AIS_InteractiveObject.hxx>
-#include <AIS_Shape.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <StdPrs_ShadedShape.hxx>
-#include <StdPrs_WFDeflectionShape.hxx>*/
bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
{
- bool isDone = false;
- /*if (myCustomized.contains(theResult)) {
- std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
- OPERATION_PARAMETER_COLOR);
- isDone = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
- /*
- Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
-
- const Handle(Prs3d_Presentation)& aPresentation = anAISIO->Presentation();
- if (!aPresentation.IsNull()) {
- Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAISIO);
- if (!aShapeAIS.IsNull()) {
- TopExp_Explorer anExp(aShapeAIS->Shape(), TopAbs_VERTEX);
- Handle(Prs3d_Drawer) aDrawer = aShapeAIS->Attributes();
- for (; anExp.More(); anExp.Next()) {
- const TopoDS_Vertex& aVertex = (const TopoDS_Vertex&)anExp.Current();
- StdPrs_WFDeflectionShape::Add(aPresentation, aVertex, aDrawer);
- }
- }
- }
- thePrs->setPointMarker(5, 5.); // Set point as a '+' symbol*+/
- }
- /*
- std::vector<int> aColor;
-
- getResultColor(theResult, aColor);
-
- SessionPtr aMgr = ModelAPI_Session::get();
- if (aMgr->activeDocument() != theResult->document()) {
- QColor aQColor(aColor[0], aColor[1], aColor[2]);
- QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF());
- aColor[0] = aNewColor.red();
- aColor[1] = aNewColor.green();
- aColor[2] = aNewColor.blue();
- }
- return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);*/
- return isDone;
+ return false;
}
#define PartSet_CustomPrs_H
#include "PartSet.h"
+
#include "PartSet_OperationPrs.h"
#include <ModelAPI_Object.h>
#include <GeomAPI_AISObject.h>
#include <GeomAPI_Shape.h>
-#include <QMap>
-#include <QList>
-
class ModuleBase_IWorkshop;
/**
PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop);
PARTSET_EXPORT virtual ~PartSet_CustomPrs() {};
- /// Set the feature is customized
- /// \param theObject a feature object
- void setCustomized(const FeaturePtr& theObject);
+ /// Returns true if the presentation is active
+ bool isActive() const;
+
+ /// Initializes the presentation by the parameter object
+ void activate(const FeaturePtr& theObject);
+
+ void deactivate();
+
+ /// Modifies the given presentation in the custom way.
+ bool customize(const ObjectPtr& theObject);
/// Modifies the given presentation in the custom way.
virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
+private:
+ /// Returns the AIS presentation
+ Handle(PartSet_OperationPrs) getPresentation() const;
+
+ /// Displays the internal presentation in the viewer of workshop
+ void displayPresentation();
+ /// Erases the internal presentation from the viewer of workshop
+ void erasePresentation();
+ /// Sets color, point size and width of the presentation
+ void customizePresentation();
+
private:
ModuleBase_IWorkshop* myWorkshop; /// current workshop
- Handle(PartSet_OperationPrs) myOperationPrs; /// AIS presentation for the feature of operation
- //QMap<ResultPtr, QList<GeomShapePtr> > myCustomized; /// objects, which are customized
+ AISObjectPtr myOperationPrs; /// the AIS presentation, which is displayed/erased in the viewer
};
#endif
void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
{
+ // z layer is created for all started operations in order to visualize operation AIS presentation
+ // over the object
+ Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
+ aViewer->AddZLayer(myVisualLayerId);
+
if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
- Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
- aViewer->AddZLayer(myVisualLayerId);
mySketchMgr->startSketch(theOperation);
}
else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
mySketchMgr->startNestedSketch(theOperation);
}
+
+ std::shared_ptr<PartSet_CustomPrs> aCustomPrs =
+ std::dynamic_pointer_cast<PartSet_CustomPrs>(myCustomPrs);
+ aCustomPrs->activate(theOperation->feature());
}
void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
{
if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
mySketchMgr->stopSketch(theOperation);
- Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
- aViewer->RemoveZLayer(myVisualLayerId);
- myVisualLayerId = 0;
}
else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
mySketchMgr->stopNestedSketch(theOperation);
}
+ Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
+ aViewer->RemoveZLayer(myVisualLayerId);
+ myVisualLayerId = 0;
+ std::shared_ptr<PartSet_CustomPrs> aCustomPrs =
+ std::dynamic_pointer_cast<PartSet_CustomPrs>(myCustomPrs);
+ aCustomPrs->deactivate();
}
ModuleBase_Operation* PartSet_Module::currentOperation() const
aDisplayer->updateViewer();
}
-void PartSet_Module::setCustomized(const FeaturePtr& theFeature)
-{
- std::shared_ptr<PartSet_CustomPrs> aCustomPrs =
- std::dynamic_pointer_cast<PartSet_CustomPrs>(myCustomPrs);
- if (aCustomPrs.get())
- aCustomPrs->setCustomized(theFeature);
-}
-
bool PartSet_Module::customizeObject(ObjectPtr theObject)
{
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
- XGUI_Displayer* aDisplayer = aWorkshop->displayer();
-
- AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult);
- return myCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
+ std::shared_ptr<PartSet_CustomPrs> aCustomPrs =
+ std::dynamic_pointer_cast<PartSet_CustomPrs>(myCustomPrs);
+ bool isCustomized = false;
+ if (aCustomPrs->isActive())
+ isCustomized = aCustomPrs->customize(theObject);
+ return isCustomized;
}
void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
class ModuleBase_Operation;
class ModuleBase_IViewWindow;
class PartSet_MenuMgr;
+class PartSet_CustomPrs;
class PartSet_SketcherMgr;
class QAction;
/// \param theObjectBrowser a pinter on Object Browser widget
virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
+ /// Returns the viewer Z layer
+ int getVisualLayerId() const { return myVisualLayerId; }
+
public slots:
/// SLOT, that is called by no more widget signal emitted by property panel
/// Set a specific flag to restart the sketcher operation
// Author: Natalia ERMOLAEVA
#include "PartSet_OperationPrs.h"
+#include "PartSet_Tools.h"
-//#include <ModelAPI_Tools.h>
-//#include <ModelAPI_ResultConstruction.h>
-//#include <GeomAPI_PlanarEdges.h>
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <GeomValidators_Tools.h>
-//#include <BRep_Builder.hxx>
-//#include <Prs3d_IsoAspect.hxx>
-//#include <TopoDS_Builder.hxx>
+#include <StdPrs_WFDeflectionShape.hxx>
+
+#include <QList>
IMPLEMENT_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape);
IMPLEMENT_STANDARD_RTTIEXT(PartSet_OperationPrs, ViewerData_AISShape);
-PartSet_OperationPrs::PartSet_OperationPrs()
- : ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr())
+PartSet_OperationPrs::PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop)
+ : ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr()), myWorkshop(theWorkshop)
{
}
-void PartSet_OperationPrs::setFeature(FeaturePtr theFeature)
+bool PartSet_OperationPrs::canActivate(const FeaturePtr& theFeature)
{
-/* std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
- std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
- std::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
- myIsSketchMode = true;
- }
- }
- Set(aShapePtr->impl<TopoDS_Shape>());
-*/
+ bool aHasSelectionAttribute = false;
+
+ std::list<AttributePtr> anAttributes = theFeature->data()->attributes("");
+ std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
+ for (; anIt != aLast && !aHasSelectionAttribute; anIt++)
+ aHasSelectionAttribute = isSelectionAttribute(*anIt);
+
+ return aHasSelectionAttribute;
}
+void PartSet_OperationPrs::setFeature(const FeaturePtr& theFeature)
+{
+ myFeature = theFeature;
+ updateShapes();
+}
+
+bool PartSet_OperationPrs::dependOn(const ObjectPtr& theResult)
+{
+ return myFeatureShapes.contains(theResult);
+}
+
+void PartSet_OperationPrs::updateShapes()
+{
+ myFeatureShapes.clear();
+ getFeatureShapes(myFeatureShapes);
+}
-/*#include <TopExp_Explorer.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <StdPrs_ShadedShape.hxx>
-#include <StdPrs_WFDeflectionShape.hxx>
-*/
void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode)
{
-/* std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
- if (!aShapePtr)
- return;
- if (myIsSketchMode) {
- myFacesList.clear();
- ResultConstructionPtr aConstruction =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
- if (aConstruction.get()) {
- int aFacesNum = aConstruction->facesNum();
- for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
- myFacesList.push_back(aConstruction->face(aFaceIndex));
- }
+ thePresentation->Clear();
+
+ // create presentations on the base of the shapes
+ Handle(Prs3d_Drawer) aDrawer = Attributes();
+ QMap<ObjectPtr, QList<GeomShapePtr> >::const_iterator anIt = myFeatureShapes.begin(),
+ aLast = myFeatureShapes.end();
+ for (; anIt != aLast; anIt++) {
+ QList<GeomShapePtr> aShapes = anIt.value();
+ QList<GeomShapePtr>::const_iterator aShIt = aShapes.begin(), aShLast = aShapes.end();
+ for (; aShIt != aShLast; aShIt++) {
+ GeomShapePtr aGeomShape = *aShIt;
+ TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>();
+ StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer);
}
}
- myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
- if (!myOriginalShape.IsNull()) {
- Set(myOriginalShape);
-
- AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
- /*
- TopExp_Explorer anExp(myOriginalShape, TopAbs_VERTEX);
- Handle(Prs3d_Drawer) aDrawer = Attributes();
- for (; anExp.More(); anExp.Next()) {
- const TopoDS_Vertex& aVertex = (const TopoDS_Vertex&)anExp.Current();
- StdPrs_WFDeflectionShape::Add(thePresentation, aVertex, aDrawer);
- }*|/
- }*/
}
-
void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
const Standard_Integer aMode)
{
-/* if (aMode > TopAbs_SHAPE)
- // In order to avoid using custom selection modes
+ // the presentation is not used in the selection
+}
+
+void addValue(const ObjectPtr& theObject, const GeomShapePtr& theShape,
+ QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
+{
+ if (theObjectShapes.contains(theObject))
+ theObjectShapes[theObject].append(theShape);
+ else {
+ QList<GeomShapePtr> aShapes;
+ aShapes.append(theShape);
+ theObjectShapes[theObject] = aShapes;
+ }
+}
+
+void PartSet_OperationPrs::getFeatureShapes(QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
+{
+ if (!myFeature.get())
return;
- if (myIsSketchMode) {
- if (aMode == TopAbs_FACE) {
- BRep_Builder aBuilder;
- TopoDS_Compound aComp;
- aBuilder.MakeCompound(aComp);
- aBuilder.Add(aComp, myOriginalShape);
- std::list<std::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);
+ QList<GeomShapePtr> aShapes;
+ std::list<AttributePtr> anAttributes = myFeature->data()->attributes("");
+ std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
+ for (; anIt != aLast; anIt++) {
+ AttributePtr anAttribute = *anIt;
+ if (!isSelectionAttribute(anAttribute))
+ continue;
+
+ std::string anAttrType = anAttribute->attributeType();
+
+ if (anAttrType == ModelAPI_AttributeSelectionList::typeId()) {
+ std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
+ for(int i = 0; i < aCurSelList->size(); i++) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
+ ResultPtr aResult = aSelAttribute->context();
+ GeomShapePtr aShape = aSelAttribute->value();
+ if (!aShape.get())
+ aShape = aResult->shape();
+ addValue(aResult, aShape, theObjectShapes);
+ }
+ }
+ else {
+ ObjectPtr anObject;
+ GeomShapePtr aShape;
+ if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
+ AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
+ if (anAttr->isObject()) {
+ anObject = anAttr->object();
+ }
+ else {
+ aShape = PartSet_Tools::findShapeBy2DPoint(anAttr, myWorkshop);
+ // the distance point is not found if the point is selected in the 2nd time
+ // TODO: after debug, this check can be removed
+ if (!aShape.get())
+ continue;
+ anObject = anAttr->attr()->owner();
+ }
+ }
+ if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
+ anObject = anAttr->context();
+ aShape = anAttr->value();
+ }
+ if (anAttrType == ModelAPI_AttributeReference::typeId()) {
+ AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttribute);
+ anObject = anAttr->value();
+ }
+
+ if (anObject.get()) {
+ if (!aShape.get()) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aResult.get())
+ aShape = aResult->shape();
+ }
+ addValue(anObject, aShape, theObjectShapes);
}
- Set(aComp);
- } else {
- Set(myOriginalShape);
}
- }*/
- AIS_Shape::ComputeSelection(aSelection, aMode);
-}
\ No newline at end of file
+ }
+}
+
+bool PartSet_OperationPrs::isSelectionAttribute(const AttributePtr& theAttribute)
+{
+ std::string anAttrType = theAttribute->attributeType();
+
+ return anAttrType == ModelAPI_AttributeSelectionList::typeId() ||
+ anAttrType == ModelAPI_AttributeRefAttr::typeId() ||
+ anAttrType == ModelAPI_AttributeSelection::typeId() ||
+ anAttrType == ModelAPI_AttributeReference::typeId();
+}
#include "PartSet.h"
-#include <ModelAPI_Result.h>
+#include <ModelAPI_Object.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Attribute.h>
+
+#include <ModuleBase_IWorkshop.h>
+
+#include <GeomAPI_Shape.h>
#include <ViewerData_AISShape.hxx>
#include <Standard_DefineHandle.hxx>
+#include <QMap>
+#include <QList>
+
DEFINE_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape)
/**
* \ingroup GUI
-* A redefinition of standard AIS Interactive Object in order to provide specific behaviour
-* for wire presentations based in a one plane
+* A redefinition of standard AIS Interactive Object in order to provide colored presentation of
+* a list of shapes. It contains a shapes where the parameter feature refers. It processes the following
+* types of attributes: ModelAPI_AttributeSelectionList, ModelAPI_AttributeRefAttr,
+* ModelAPI_AttributeSelection and ModelAPI_AttributeReference.
+* The selection for this presentation is absent.
*/
class PartSet_OperationPrs : public ViewerData_AISShape
{
public:
/// Constructor
- /// \param theResult a result object
- Standard_EXPORT PartSet_OperationPrs();
+ Standard_EXPORT PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop);
+
+ /// Returns true if the feature contains attributes, which has references to other features
+ /// \param theFeature a feature
+ /// \return boolean result
+ bool canActivate(const FeaturePtr& theFeature);
- /// set the operation feature. It is used in Compute method to group the feature parameter shapes
+ /// Sets the operation feature. It is used in Compute method to group the feature parameter shapes
/// theFeature a feature
- void setFeature(FeaturePtr theFeature);
+ void setFeature(const FeaturePtr& theFeature);
+ /// Returns true if the presentation
+ bool dependOn(const ObjectPtr& theObject);
+
+ // Recompute internal list of shaped dependent on the current feature
+ void updateShapes();
DEFINE_STANDARD_RTTI(PartSet_OperationPrs)
Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
const Standard_Integer aMode) ;
private:
- /// Reference to a feature object
- FeaturePtr myFeature;
+ /// Fills the map by the feature object and shapes, which should be visuaziled
+ /// Gets the feature attribute, collect objects to whom the attribute refers
+ /// \param theObjectShape an output map of objects
+ void getFeatureShapes(QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
+
+ /// Returns true if the attribute type belong to reference attribute
+ /// \param theAttribute an attribute
+ /// \return a boolean value
+ static bool isSelectionAttribute(const AttributePtr& theAttribute);
+
+private:
+ ModuleBase_IWorkshop* myWorkshop;
+ FeaturePtr myFeature; /// Reference to a feature object
+ QMap<ObjectPtr, QList<GeomShapePtr> > myFeatureShapes;
};
void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
{
- ModuleBase_Operation* anOperation = getCurrentOperation();
- bool isSketchOp = isSketchOperation(anOperation);
- bool isNestedSketchOp = isNestedSketchOperation(anOperation);
- if (isSketchOp || isNestedSketchOp)
- myModule->setCustomized(anOperation->feature());
-
if (!isNestedCreateOperation(getCurrentOperation()))
return;
onShowConstraintsToggle(true);
}
connectToPropertyPanel(true);
- myModule->setCustomized(getCurrentOperation()->feature());
}
void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
myIsResetCurrentValue = false;
myIsMouseOverViewProcessed = true;
operationMgr()->onValidateOperation();
-
- myModule->setCustomized(FeaturePtr());
}
void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
// Author: Natalia ERMOLAEVA
#include <PartSet_Tools.h>
+#include <PartSet_Module.h>
+#include <PartSet_SketcherMgr.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_ResultConstruction.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_SelectionMgr.h>
+#include <XGUI_Selection.h>
+
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point2D.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Point.h>
+#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_ViewerPrs.h>
#include <V3d_View.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
+#include <AIS_InteractiveObject.hxx>
+#include <StdSelect_BRepOwner.hxx>
+#include <SelectMgr_IndexedMapOfOwner.hxx>
#ifdef _DEBUG
#include <QDebug>
return aHasVertex;
}
+GeomShapePtr PartSet_Tools::findShapeBy2DPoint(const AttributePtr& theAttribute,
+ ModuleBase_IWorkshop* theWorkshop)
+{
+ // 1. find an attribute value in attribute reference attribute value
+ GeomShapePtr aShape;
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (aRefAttr) {
+ if (!aRefAttr->isObject()) {
+ AttributePtr theAttribute = aRefAttr->attr();
+ if (theAttribute.get()) {
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
+ XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
+ // 2. find visualized vertices of the attribute and if the attribute of the vertex is
+ // the same, return it
+ FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ // 2.1 get visualized results of the feature
+ const std::list<ResultPtr>& aResList = anAttributeFeature->results();
+ std::list<ResultPtr>::const_iterator anIt = aResList.begin(), aLast = aResList.end();
+ for (; anIt != aLast; anIt++) {
+ AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt);
+ if (aAISObj.get() != NULL) {
+ Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+ // 2.2 find selected owners of a visualizedd object
+ SelectMgr_IndexedMapOfOwner aSelectedOwners;
+ aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
+ for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
+ Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
+ if (!anOwner.IsNull()) {
+ Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
+ if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
+ const TopoDS_Shape& aBRepShape = aBRepOwner->Shape();
+ if (aBRepShape.ShapeType() == TopAbs_VERTEX) {
+ // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial
+ // attribute, returns the shape
+ PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(theWorkshop->module());
+ PartSet_SketcherMgr* aSketchMgr = aModule->sketchMgr();
+ AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature,
+ aBRepShape, aSketchMgr->activeSketch());
+ if (aPntAttr.get() != NULL && aPntAttr == theAttribute) {
+ aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
+ aShape->setImpl(new TopoDS_Shape(aBRepShape));
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return aShape;
+}
+
AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj,
const TopoDS_Shape theShape,
FeaturePtr theSketch)
class Handle_V3d_View;
class ModuleBase_ViewerPrs;
+class ModuleBase_IWorkshop;
class GeomDataAPI_Point2D;
class GeomAPI_Pln;
class GeomAPI_Pnt2d;
* \param theShape - a Shape
* \param theSketch - a Sketch to get a plane of converting to 2d
*/
- static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch);
+ static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
+ FeaturePtr theSketch);
+
+ /**
+ * Finds an attribute value in attribute reference attribute value
+ * \param theAttribute - an attribure reference filled with an attribute
+ * \return a geometry shape
+ */
+ static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute,
+ ModuleBase_IWorkshop* theWorkshop);
protected:
/// Returns an object that is under the mouse point. Firstly it checks the highlighting,
GeomShapePtr PartSet_WidgetShapeSelector::getShape() const
{
// an empty shape by default
- GeomShapePtr aShape;
-
- // 1. find an attribute value in attribute reference attribute value
DataPtr aData = myFeature->data();
- AttributePtr aAttr = aData->attribute(attributeID());
- AttributeRefAttrPtr aRefAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
- if (aRefAttr) {
- if (!aRefAttr->isObject()) {
- AttributePtr anAttribute = aRefAttr->attr();
- if (anAttribute.get()) {
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
-
- // 2. find visualized vertices of the attribute and if the attribute of the vertex is
- // the same, return it
- FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(anAttribute->owner());
- // 2.1 get visualized results of the feature
- const std::list<ResultPtr>& aResList = anAttributeFeature->results();
- std::list<ResultPtr>::const_iterator anIt = aResList.begin(), aLast = aResList.end();
- for (; anIt != aLast; anIt++) {
- AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt);
- if (aAISObj.get() != NULL) {
- Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
- // 2.2 find selected owners of a visualizedd object
- SelectMgr_IndexedMapOfOwner aSelectedOwners;
- aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
- for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
- Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
- if (!anOwner.IsNull()) {
- Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
- if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
- const TopoDS_Shape& aBRepShape = aBRepOwner->Shape();
- if (aBRepShape.ShapeType() == TopAbs_VERTEX) {
- // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial
- // attribute, returns the shape
- AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature,
- aBRepShape, sketch());
- if (aPntAttr.get() != NULL && aPntAttr == anAttribute) {
- aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
- aShape->setImpl(new TopoDS_Shape(aBRepShape));
- break;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
+ AttributePtr anAttribute = aData->attribute(attributeID());
+ GeomShapePtr aShape = PartSet_Tools::findShapeBy2DPoint(anAttribute, myWorkshop);
+
if (!aShape.get())
aShape = ModuleBase_WidgetShapeSelector::getShape();
return aShape;
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
// Customization of presentation
+ bool isPresentable = false;
GeomCustomPrsPtr aCustomPrs;
FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
if (aFeature.get() != NULL) {
if (aCustomPrs.get() == NULL) {
// we ignore presentable not customized objects
GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
- if (aPrs.get() != NULL)
- return false;
+ isPresentable = aPrs.get() != NULL;
aCustomPrs = myCustomPrs;
}
- bool isCustomized = aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
+ bool isCustomized = false;
+ if (!isPresentable)
+ aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
isCustomized = myWorkshop->module()->customizeObject(theObject) || isCustomized;
return isCustomized;
}