+
+//*********************************************************************************
+void SketcherPrs_SymbolPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const SelectMgr_SequenceOfOwner& theOwners)
+{
+ Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
+ aSelectionPrs->Clear();
+ drawLines(aSelectionPrs, GetContext()->SelectionStyle()->Color());
+
+ aSelectionPrs->SetDisplayPriority(9);
+ aSelectionPrs->Display();
+ thePM->Color(this, GetContext()->SelectionStyle());
+}
+
+//*********************************************************************************
+void SketcherPrs_SymbolPrs::HilightOwnerWithColor(
+ const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const Handle(Prs3d_Drawer)& theStyle,
+ const Handle(SelectMgr_EntityOwner)& theOwner)
+{
+ thePM->Color(this, theStyle);
+
+ Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
+ aHilightPrs->Clear();
+ drawLines(aHilightPrs, theStyle->Color());
+ aHilightPrs->SetZLayer(Graphic3d_ZLayerId_Topmost);
+
+ if (thePM->IsImmediateModeOn())
+ thePM->AddToImmediateList(aHilightPrs);
+}
+
+//*********************************************************************************
+void SketcherPrs_SymbolPrs::Compute(
+ const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ // Create an icon
+ prepareAspect();
+
+ Handle(AIS_InteractiveContext) aCtx = GetContext();
+ Handle(OpenGl_GraphicDriver) aDriver =
+ Handle(OpenGl_GraphicDriver)::DownCast(aCtx->CurrentViewer()->Driver());
+ if (aDriver.IsNull())
+ return;
+
+ // Update points with default shift value
+ // it updates array of points if the presentation is ready to display, or the array of points
+ // contains the previous values
+
+ bool aReadyToDisplay = updateIfReadyToDisplay(20, myIsCustomColor);
+
+ int aNbVertex = myPntArray->VertexNumber();
+ if (myOwner.IsNull()) {
+ myOwner = new SelectMgr_EntityOwner(this);
+ }
+
+ // Create sensitive point for each symbol
+ mySPoints.Clear();
+ for (int i = 1; i <= aNbVertex; i++) {
+ Handle(SketcherPrs_SensitivePoint) aSP = new SketcherPrs_SensitivePoint(myOwner, i);
+ mySPoints.Append(aSP);
+ if (myIsCustomColor)
+ myPntArray->SetVertexColor(i, myCustomColor);
+ }
+
+ Handle(OpenGl_Group) aGroup =
+ Handle(OpenGl_Group)::DownCast(Prs3d_Root::CurrentGroup (thePresentation));
+ aGroup->SetPrimitivesAspect(myAspect);
+
+ // Recompute boundary box of the group
+ Graphic3d_BndBox4f& aBnd = aGroup->ChangeBoundingBox();
+ gp_Pnt aVert;
+ aBnd.Clear();
+ for (int i = 1; i <= myPntArray->ItemNumber(); i++) {
+ aVert = myPntArray->Vertice(i);
+ aBnd.Add(Graphic3d_Vec4((float)aVert.X(), (float)aVert.Y(), (float)aVert.Z(), 1.0f));
+ }
+
+ // Pint the group with custom procedure (see Render)
+ SketcherPrs_SymbolArray* aElem =
+ new SketcherPrs_SymbolArray((OpenGl_GraphicDriver*)aDriver->This(), this, GetContext());
+ aGroup->AddElement(aElem);
+
+ // Disable frustum culling for this object by marking it as mutable
+ aGroup->Structure()->SetMutable(true);
+
+ if (!aReadyToDisplay)
+ SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
+ "An empty AIS presentation: SketcherPrs_LengthDimension");
+}
+
+
+//*********************************************************************************
+void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode)
+{
+ ClearSelected();
+ if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) {
+ for (int i = 1; i <= mySPoints.Length(); i++)
+ aSelection->Add(mySPoints.Value(i));
+ }
+}
+
+//*********************************************************************************
+void SketcherPrs_SymbolPrs::SetCustomColor(const std::vector<int>& theColor)
+{
+ myIsCustomColor = !theColor.empty();
+ if (myIsCustomColor)
+ myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255.,
+ theColor[2] / 255., Quantity_TOC_RGB);
+ else
+ myCustomColor = Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB);
+
+ if (!myAspect.IsNull())
+ myAspect->SetColor (myCustomColor);
+
+ Handle(Prs3d_Presentation) aPrs = Presentation();
+ if (!aPrs.IsNull()) {
+ if (myIsCustomColor) {
+ Handle(Graphic3d_PresentationAttributes) aAttr = new Graphic3d_PresentationAttributes();
+ aAttr->SetColor(myCustomColor);
+ aPrs->Highlight(aAttr);
+ }
+ else {
+ aPrs->UnHighlight();
+ }
+ }
+}
+
+//*********************************************************************************
+void SketcherPrs_SymbolPrs::drawShape(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const Handle(Prs3d_Presentation)& thePrs,
+ Quantity_Color theColor) const
+{
+ Handle(Graphic3d_AspectLine3d) aLineAspect =
+ new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
+
+ Handle(Prs3d_LineAspect) aLinesStyle = myDrawer->LineAspect();
+ Handle(Graphic3d_AspectLine3d) aOldStyle = aLinesStyle->Aspect();
+ aLinesStyle->SetAspect(aLineAspect);
+ myDrawer->SetLineAspect(aLinesStyle);
+
+ if (theShape->isEdge()) {
+ // The shape is edge
+ std::shared_ptr<GeomAPI_Curve> aCurve =
+ std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(theShape));
+ if (aCurve->isLine()) {
+ // The shape is line
+ GeomAdaptor_Curve
+ aCurv(aCurve->impl<Handle(Geom_Curve)>(), aCurve->startParam(), aCurve->endParam());
+ StdPrs_Curve::Add(thePrs, aCurv, myDrawer);
+ } else {
+ // The shape is circle or arc
+ GeomAdaptor_Curve
+ aAdaptor(aCurve->impl<Handle(Geom_Curve)>(), aCurve->startParam(), aCurve->endParam());
+ StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer);
+ }
+ } else if (theShape->isVertex()) {
+ // draw vertex
+ std::shared_ptr<GeomAPI_Vertex> aVertex =
+ std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(theShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+ Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
+ StdPrs_Point::Add(thePrs, aPoint, myDrawer);
+ }
+
+ aLinesStyle->SetAspect(aOldStyle);
+ myDrawer->SetLineAspect(aLinesStyle);
+}
+
+//*********************************************************************************
+void SketcherPrs_SymbolPrs::drawListOfShapes(
+ const std::shared_ptr<ModelAPI_AttributeRefList>& theListAttr,
+ const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
+{
+ int aNb = theListAttr->size();
+ if (aNb == 0)
+ return;
+ int i;
+ ObjectPtr aObj;
+ for (i = 0; i < aNb; i++) {
+ aObj = theListAttr->object(i);
+ std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
+ if (aShape.get() != NULL)
+ drawShape(aShape, thePrs, theColor);
+ }
+}
+
+//*********************************************************************************
+void SketcherPrs_SymbolPrs::BoundingBox(Bnd_Box& theBndBox)
+{
+ Select3D_BndBox3d aTmpBox;
+ for (Select3D_EntitySequenceIter aPntIter (mySPoints); aPntIter.More(); aPntIter.Next()) {
+ const Handle(Select3D_SensitiveEntity)& anEnt = aPntIter.Value();
+ aTmpBox.Combine (anEnt->BoundingBox());
+ }
+
+ theBndBox.Update (aTmpBox.CornerMin().x(), aTmpBox.CornerMin().y(), aTmpBox.CornerMin().z(),
+ aTmpBox.CornerMax().x(), aTmpBox.CornerMax().y(), aTmpBox.CornerMax().z());
+}