X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationPrs.cpp;h=f243fca538038bb2b7eeb26d872c53011c612d51;hb=bcb39f79a614f96a6508a84b7a5f04843a5bf6e9;hp=4539ebbd2129e573d619ebb1b3a3dd399373b148;hpb=f5ddae43cdb88e20e6fe3e0efc7f1751a39f216c;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index 4539ebbd2..f243fca53 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -5,101 +5,224 @@ // Author: Natalia ERMOLAEVA #include "PartSet_OperationPrs.h" +#include "PartSet_Tools.h" -//#include -//#include -//#include +#include "XGUI_Workshop.h" +#include "XGUI_ModuleConnector.h" +#include "XGUI_Displayer.h" -//#include -//#include -//#include +#include "ModuleBase_Tools.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#include 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 aShapePtr = ModelAPI_Tools::shape(theResult); - std::shared_ptr aWirePtr = - std::dynamic_pointer_cast(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()); -*/ + bool aHasSelectionAttribute = false; + + std::list anAttributes = theFeature->data()->attributes(""); + std::list::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 -#include -#include -#include -*/ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { -/* std::shared_ptr aShapePtr = ModelAPI_Tools::shape(myResult); - if (!aShapePtr) - return; - if (myIsSketchMode) { - myFacesList.clear(); - ResultConstructionPtr aConstruction = - std::dynamic_pointer_cast(myResult); - if (aConstruction.get()) { - int aFacesNum = aConstruction->facesNum(); - for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) { - myFacesList.push_back(aConstruction->face(aFaceIndex)); - } + thePresentation->Clear(); + XGUI_Displayer* aDisplayer = workshop()->displayer(); + + // create presentations on the base of the shapes + Handle(Prs3d_Drawer) aDrawer = Attributes(); + QMap >::const_iterator anIt = myFeatureShapes.begin(), + aLast = myFeatureShapes.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = anIt.key(); + if (!isVisible(aDisplayer, anObject)) + continue; + QList aShapes = anIt.value(); + QList::const_iterator aShIt = aShapes.begin(), aShLast = aShapes.end(); + for (; aShIt != aShLast; aShIt++) { + GeomShapePtr aGeomShape = *aShIt; + if (!aGeomShape.get()) + continue; + TopoDS_Shape aShape = aGeomShape->impl(); + // change deviation coefficient to provide more precise circle + Standard_Real aPrevDeviation = aDrawer->DeviationCoefficient(); + aDrawer->SetDeviationCoefficient(ModuleBase_Tools::defaultDeviationCoefficient()); + StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer); + aDrawer->SetDeviationCoefficient(aPrevDeviation); } } - myOriginalShape = aShapePtr->impl(); - 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 +} + +bool PartSet_OperationPrs::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject) +{ + bool aVisible = false; + GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aPrs.get() || aResult.get()) + aVisible = theDisplayer->isVisible(theObject); + else { + // check if all results of the feature are visible + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + aVisible = !aResults.empty(); + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + aVisible = aVisible && theDisplayer->isVisible(*aIt); + } + } + return aVisible; +} + +bool isSubObject(const ObjectPtr& theObject, const FeaturePtr& theFeature) +{ + bool isSub = false; + CompositeFeaturePtr aComposite = std::dynamic_pointer_cast(theFeature); + if (aComposite.get()) + isSub = aComposite->isSub(theObject); + + return isSub; +} + +void addValue(const ObjectPtr& theObject, const GeomShapePtr& theShape, + const FeaturePtr& theFeature, + QMap >& theObjectShapes) +{ + if (theObject.get()) { + GeomShapePtr aShape = theShape; + if (!aShape.get()) { + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) + aShape = aResult->shape(); + } + if (!isSubObject(theObject, theFeature)) { + if (theObjectShapes.contains(theObject)) + theObjectShapes[theObject].append(aShape); + else { + QList aShapes; + aShapes.append(aShape); + theObjectShapes[theObject] = aShapes; + } + } + } +} + +void PartSet_OperationPrs::getFeatureShapes(QMap >& 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>::const_iterator aIt; - for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) { - TopoDS_Shape aFace = (*aIt)->impl(); - aBuilder.Add(aComp, aFace); + QList aShapes; + std::list anAttributes = myFeature->data()->attributes(""); + std::list::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 aCurSelList = + std::dynamic_pointer_cast(anAttribute); + for(int i = 0; i < aCurSelList->size(); i++) { + std::shared_ptr aSelAttribute = aCurSelList->value(i); + ResultPtr aResult = aSelAttribute->context(); + GeomShapePtr aShape = aSelAttribute->value(); + addValue(aResult, aShape, myFeature, theObjectShapes); } - Set(aComp); - } else { - Set(myOriginalShape); } - }*/ - AIS_Shape::ComputeSelection(aSelection, aMode); -} \ No newline at end of file + else { + ObjectPtr anObject; + GeomShapePtr aShape; + if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) { + AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(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(anAttribute); + anObject = anAttr->context(); + aShape = anAttr->value(); + } + if (anAttrType == ModelAPI_AttributeReference::typeId()) { + AttributeReferencePtr anAttr = std::dynamic_pointer_cast(anAttribute); + anObject = anAttr->value(); + } + addValue(anObject, aShape, myFeature, theObjectShapes); + } + } +} + +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(); +} + +XGUI_Workshop* PartSet_OperationPrs::workshop() const +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + return aConnector->workshop(); +}