#include <BRep_Builder.hxx>
#include <Prs3d_Drawer.hxx>
+#include <Prs3d.hxx>
#include <Prs3d_PointAspect.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <TopoDS_Builder.hxx>
+#include <SelectMgr_SequenceOfOwner.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <SelectMgr_SelectionManager.hxx>
+#include <StdPrs_WFDeflectionShape.hxx>
+#include <StdSelect_BRepSelectionTool.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
+
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
+
+//*******************************************************************************************
IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape);
IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
+
+
+
+
ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
: ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
{
aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
else
aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
+
+ // Activate individual repaintng if this is a part of compsolid
+ ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
+ SetAutoHilight(aCompSolid.get() == NULL);
}
std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
if (!aShapePtr)
return;
+
if (myIsSketchMode) {
myFacesList.clear();
ResultConstructionPtr aConstruction =
void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
const Standard_Integer aMode)
{
- if (aMode > TopAbs_SHAPE)
+ if (aMode > 8)
// In order to avoid using custom selection modes
return;
+
if (myIsSketchMode) {
- if (aMode == TopAbs_FACE) {
+ if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) {
BRep_Builder aBuilder;
TopoDS_Compound aComp;
aBuilder.MakeCompound(aComp);
aBuilder.Add(aComp, aFace);
}
Set(aComp);
- } else {
+ } else
Set(myOriginalShape);
+ }
+ if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
+ // Limit selection area only by actual object (Shape)
+ ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
+ if (aCompSolid.get()) {
+ std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
+ if (aShapePtr.get()) {
+ TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+ int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE);
+ double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
+
+ Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
+ StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
+ aDeflection, myDrawer->HLRAngle(), 9, 500);
+
+ for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
+ Handle(SelectMgr_EntityOwner) anOwner
+ = Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Sensitive()->BaseSensitive()->OwnerId());
+ anOwner->Set(this);
+ }
+ return;
+ }
}
- }
+ //AIS_Shape::ComputeSelection(aSelection, 0);
+ }
AIS_Shape::ComputeSelection(aSelection, aMode);
-}
\ No newline at end of file
+}
+
+
+bool ModuleBase_ResultPrs::hasCompSolidSelectionMode() const
+{
+ if (!HasInteractiveContext())
+ return false;
+
+ Handle(AIS_InteractiveContext) aContext = GetContext();
+ TColStd_ListOfInteger aModes;
+ aContext->ActivatedModes(this, aModes);
+
+ TColStd_ListIteratorOfListOfInteger aIt(aModes);
+ for (; aIt.More(); aIt.Next()) {
+ if (aIt.Value() == AIS_Shape::SelectionMode(TopAbs_COMPSOLID))
+ return true;
+ }
+ return false;
+}
+
+
+TopoDS_Shape ModuleBase_ResultPrs::getSelectionShape() const
+{
+ if (hasCompSolidSelectionMode()) {
+ // In case of CompSolid mode use shape from Parent for highlighting
+ ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
+ if (aCompSolid.get()) {
+ std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
+ if (aShapePtr.get())
+ return aShapePtr->impl<TopoDS_Shape>();
+ }
+ }
+ return myOriginalShape;
+}
+
+
+void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const SelectMgr_SequenceOfOwner& theOwners)
+{
+ TopoDS_Shape aShape = getSelectionShape();
+ if (!aShape.IsNull()) {
+ Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
+ aSelectionPrs->Clear();
+
+ StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
+
+ aSelectionPrs->SetDisplayPriority(9);
+ aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
+ aSelectionPrs->Display();
+ thePM->Highlight(this);
+ }
+}
+
+void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const Quantity_NameOfColor theColor,
+ const Handle(SelectMgr_EntityOwner)& theOwner)
+{
+ TopoDS_Shape aShape = getSelectionShape();
+ if (!aShape.IsNull()) {
+ thePM->Color(this, theColor);
+
+ Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
+ aHilightPrs->Clear();
+
+ StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
+ aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
+
+ if (thePM->IsImmediateModeOn())
+ thePM->AddToImmediateList(aHilightPrs);
+ }
+}
#include <ViewerData_AISShape.hxx>
#include <Standard_DefineHandle.hxx>
+#include <StdSelect_BRepOwner.hxx>
+
+DEFINE_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner)
+
+/**
+* \ingroup GUI
+* A redefinition of standard BRep Owner in order to provide specific selection
+* of CompSolid objects. This owner is created only for selection mode TopAbs_COMPSOLID
+*/
+class ModuleBase_BRepOwner: public StdSelect_BRepOwner
+{
+public:
+ ModuleBase_BRepOwner(const TopoDS_Shape& aShape,
+ const Standard_Integer aPriority = 0,
+ const Standard_Boolean ComesFromDecomposition = Standard_False)
+ : StdSelect_BRepOwner(aShape, aPriority, ComesFromDecomposition) {}
+
+ virtual void HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& aPM,
+ const Quantity_NameOfColor aCol, const Standard_Integer aMode = 0)
+ { Selectable()->HilightOwnerWithColor(aPM, aCol, this); }
+
+ DEFINE_STANDARD_RTTI(ModuleBase_BRepOwner)
+};
+
+
DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape)
/// \param theResult a result object
Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult);
+
+ //! Method which draws selected owners ( for fast presentation draw )
+ Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const SelectMgr_SequenceOfOwner& theOwners);
+
+ //! Method which hilight an owner belonging to
+ //! this selectable object ( for fast presentation draw )
+ Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner);
+
/// Returns result object
Standard_EXPORT ResultPtr getResult() const { return myResult; }
/// Returns a list of faces
Standard_EXPORT const std::list<std::shared_ptr<GeomAPI_Shape> >& facesList() { return myFacesList; }
+ /// Returns true if the object is used in CompSolid selection mode
+ Standard_EXPORT bool hasCompSolidSelectionMode() const;
+
DEFINE_STANDARD_RTTI(ModuleBase_ResultPrs)
protected:
/// Redefinition of virtual function
const Standard_Integer aMode) ;
private:
+ /// Returns shape dependent on CompSolid selection mode
+ /// In case CompSolid selection mode it returns parent's compsolid shape
+ TopoDS_Shape getSelectionShape() const;
+
/// Reference to result object
ResultPtr myResult;
#include "XGUI_ViewerProxy.h"
#include "XGUI_ObjectsBrowser.h"
+#include "ModuleBase_ResultPrs.h"
+
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Tools.h>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Axis.hxx>
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
ObjectPtr aFeature = aDisplayer->getObject(anIO);
+
+ Handle(ModuleBase_BRepOwner) aCompSolidBRO = Handle(ModuleBase_BRepOwner)::DownCast(theOwner);
+ if (!aCompSolidBRO.IsNull()) {
+ // If ModuleBase_BRepOwner object is created then it means that TopAbs_COMPSOLID selection mode
+ // is On and we have to use parent result which corresponds to the CompSolid shape
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aFeature);
+ if (aResult.get()) {
+ ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(aResult);
+ if (aCompSolid.get()) {
+ GeomShapePtr aShapePtr = aCompSolid->shape();
+ if (aShapePtr.get()) {
+ TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+ if (aShape.IsEqual(thePrs.shape())) {
+ thePrs.setObject(aCompSolid);
+ return;
+ }
+ }
+ }
+ }
+ }
thePrs.setObject(aFeature);
}