X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_AISObject.cpp;h=275f62444d19c3adb20801f24dde09fcf408f2f6;hb=06e7f5859095193fc7f498bd89a7d28009794f53;hp=7f2fd801116d550a4a2752e46ab45659a217ef85;hpb=423c10234142d14d0d5de89383f2f96a4ec5930f;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 7f2fd8011..275f62444 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomAPI_AISObject.cpp -// Created: 25 Jun 2014 -// Author: Artem ZHIDKOV +// Copyright (C) 2014-2023 CEA, EDF +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include @@ -21,13 +34,14 @@ #include #include -#include -#include -#include -#include #include -#include #include +#include +#include +#include +#include +#include +#include #include @@ -79,6 +93,7 @@ void GeomAPI_AISObject::createShape(std::shared_ptr theShape) aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS); else aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.)); + aDrawer->SetIsoOnPlane(false); setImpl(new Handle(AIS_InteractiveObject)(aShape)); } } @@ -91,12 +106,11 @@ std::shared_ptr GeomAPI_AISObject::getShape() const if (!anAIS.IsNull()) { Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); if (aShapeAIS) { - std::shared_ptr aResult(new GeomAPI_Shape); + aResult.reset(new GeomAPI_Shape); aResult->setImpl(new TopoDS_Shape(aShapeAIS->Shape())); - return aResult; } } - return std::shared_ptr(); + return aResult; } void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoint, @@ -126,9 +140,10 @@ void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoin Handle(AIS_InteractiveObject) anAIS = impl(); if (anAIS.IsNull()) { - Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension(theStartPoint->impl(), - theEndPoint->impl(), - thePlane->impl()); + Handle(PrsDim_LengthDimension) aDimAIS = + new PrsDim_LengthDimension(theStartPoint->impl(), + theEndPoint->impl(), + thePlane->impl()); aDimAIS->SetCustomValue(theDistance); Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); @@ -145,7 +160,7 @@ void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoin setImpl(new Handle(AIS_InteractiveObject)(aDimAIS)); } else { // update presentation - Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + Handle(PrsDim_LengthDimension) aDimAIS = Handle(PrsDim_LengthDimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->SetMeasuredGeometry(theStartPoint->impl(), theEndPoint->impl(), thePlane->impl()); @@ -163,7 +178,7 @@ bool GeomAPI_AISObject::isEmptyDistanceGeometry() Handle(AIS_InteractiveObject) anAIS = impl(); if (!anAIS.IsNull()) { - Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + Handle(PrsDim_LengthDimension) aDimAIS = Handle(PrsDim_LengthDimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { anEmpty = !aDimAIS->IsValid(); } @@ -195,8 +210,8 @@ void GeomAPI_AISObject::createRadius(std::shared_ptr theCircle, Handle(AIS_InteractiveObject) anAIS = impl(); if (anAIS.IsNull()) { - Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(theCircle->impl(), - anAnchor->impl()); + Handle(PrsDim_RadiusDimension) aDimAIS = new PrsDim_RadiusDimension(theCircle->impl(), + anAnchor->impl()); aDimAIS->SetCustomValue(theRadius); Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); @@ -212,7 +227,7 @@ void GeomAPI_AISObject::createRadius(std::shared_ptr theCircle, setImpl(new Handle(AIS_InteractiveObject)(aDimAIS)); } else { // update presentation - Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS); + Handle(PrsDim_RadiusDimension) aDimAIS = Handle(PrsDim_RadiusDimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->SetMeasuredGeometry(theCircle->impl(), anAnchor->impl()); aDimAIS->SetCustomValue(theRadius); @@ -229,14 +244,14 @@ void GeomAPI_AISObject::createParallel(std::shared_ptr theLine1, Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl()); Handle(AIS_InteractiveObject) anAIS = impl(); if (anAIS.IsNull()) { - Handle(AIS_ParallelRelation) aParallel = new AIS_ParallelRelation( + Handle(PrsDim_ParallelRelation) aParallel = new PrsDim_ParallelRelation( theLine1->impl(), theLine2->impl(), aPlane); if (theFlyoutPoint) aParallel->SetPosition(theFlyoutPoint->impl()); setImpl(new Handle(AIS_InteractiveObject)(aParallel)); } else { - Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS); + Handle(PrsDim_ParallelRelation) aParallel = Handle(PrsDim_ParallelRelation)::DownCast(anAIS); if (!aParallel.IsNull()) { aParallel->SetFirstShape(theLine1->impl()); aParallel->SetSecondShape(theLine2->impl()); @@ -255,13 +270,13 @@ void GeomAPI_AISObject::createPerpendicular(std::shared_ptr theLi Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl()); Handle(AIS_InteractiveObject) anAIS = impl(); if (anAIS.IsNull()) { - Handle(AIS_PerpendicularRelation) aPerpendicular = new AIS_PerpendicularRelation( + Handle(PrsDim_PerpendicularRelation) aPerpendicular = new PrsDim_PerpendicularRelation( theLine1->impl(), theLine2->impl(), aPlane); setImpl(new Handle(AIS_InteractiveObject)(aPerpendicular)); } else { - Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast( - anAIS); + Handle(PrsDim_PerpendicularRelation) aPerpendicular = + Handle(PrsDim_PerpendicularRelation)::DownCast(anAIS); if (!aPerpendicular.IsNull()) { aPerpendicular->SetFirstShape(theLine1->impl()); aPerpendicular->SetSecondShape(theLine2->impl()); @@ -278,13 +293,13 @@ void GeomAPI_AISObject::createFixed(std::shared_ptr theShape, Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl()); Handle(AIS_InteractiveObject) anAIS = impl(); TopoDS_Shape aShape = theShape->impl(); - Handle(AIS_FixRelation) aFixPrs; + Handle(PrsDim_FixRelation) aFixPrs; if (anAIS.IsNull()) { - aFixPrs = new AIS_FixRelation(aShape, aPlane); + aFixPrs = new PrsDim_FixRelation(aShape, aPlane); setImpl(new Handle(AIS_InteractiveObject)(aFixPrs)); } else { - aFixPrs = Handle(AIS_FixRelation)::DownCast(anAIS); + aFixPrs = Handle(PrsDim_FixRelation)::DownCast(anAIS); if (!aFixPrs.IsNull()) { aFixPrs->SetFirstShape(aShape); aFixPrs->SetPlane(aPlane); @@ -311,12 +326,15 @@ void GeomAPI_AISObject::setColor(const int& theColor) if (anAIS.IsNull()) return; Quantity_Color aColor((Quantity_NameOfColor) theColor); - Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS); + Handle(PrsDim_Dimension) aDimAIS = Handle(PrsDim_Dimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->DimensionAspect()->SetCommonColor(aColor); } Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); - aContext->SetColor(anAIS, aColor, false); + if (!aContext.IsNull()) + aContext->SetColor(anAIS, aColor, false); + else + anAIS->SetColor(aColor); } double GeomAPI_AISObject::width() @@ -353,12 +371,19 @@ bool GeomAPI_AISObject::setColor(int theR, int theG, int theB) if (aColor.IsEqual(aCurrentColor)) return false; - Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS); + Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); + Handle(PrsDim_Dimension) aDimAIS = Handle(PrsDim_Dimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->DimensionAspect()->SetCommonColor(aColor); + if (!aContext.IsNull()) + aContext->Redisplay(aDimAIS, false); + } + else { + if (!aContext.IsNull()) + aContext->SetColor(anAIS, aColor, false); + else + anAIS->SetColor(aColor); } - Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); - aContext->SetColor(anAIS, aColor, false); return true; } @@ -368,7 +393,8 @@ void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB) if (anAIS.IsNull()) return; - Quantity_Color aColor = anAIS->Color(); + Quantity_Color aColor; + anAIS->Color(aColor); theR = (int)(aColor.Red()*255.); theG = (int)(aColor.Green()*255.); theB = (int)(aColor.Blue()*255.); @@ -386,6 +412,10 @@ bool GeomAPI_AISObject::setDeflection(const double theDeflection) if (fabs(aCoefficient-theDeflection) > Precision::Confusion()) { isModified = true; anAISShape->SetOwnDeviationCoefficient(theDeflection); + Handle(Prs3d_Drawer) aDrawer = anAISShape->DynamicHilightAttributes(); + if (!aDrawer.IsNull()) { + aDrawer->SetDeviationCoefficient(theDeflection); + } // redisplay is necessary here to update presentation in all modes // Standard True flag. Displayer uses Standard False flag. If it will be changed in // displayer, redisplay here will not be necessary. But performance should be checked. @@ -408,6 +438,39 @@ double GeomAPI_AISObject::getDeflection() const return aDeflection; } +bool GeomAPI_AISObject::setTransparency(const double theTransparency) +{ + bool isModified = false; + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); + if (!anAISShape.IsNull()) { + Standard_Real aPreviousValue = anAISShape->Transparency(); + if (fabs(aPreviousValue - theTransparency) > Precision::Confusion()) { + anAISShape->SetTransparency(theTransparency); + //>SetOwnDeviationCoefficient(theTransparency); + isModified = true; + // redisplay is necessary here to update presentation in all modes + // Standard True flag. Displayer uses Standard False flag. If it will be changed in + // displayer, redisplay here will not be necessary. But performance should be checked. + anAISShape->Redisplay(Standard_True); + } + } + } + return isModified; +} + +double GeomAPI_AISObject::getTransparency() const +{ + double aTransparency = 0; + + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + aTransparency = anAIS->Transparency(); + } + return aTransparency; +} + bool GeomAPI_AISObject::empty() const { @@ -464,13 +527,13 @@ bool GeomAPI_AISObject::setLineStyle(int theStyle) if (aDrawer->HasOwnWireAspect()) { aLineAspect = aDrawer->WireAspect(); } - Quantity_Color aCurrentColor; - Aspect_TypeOfLine aCurrentType; - Standard_Real aCurrentWidth; - aLineAspect->Aspect()->Values(aCurrentColor, aCurrentType, aCurrentWidth); - isChanged = aType != aCurrentType; - if (isChanged) { - aLineAspect->SetTypeOfLine(aType); + if (!aLineAspect.IsNull()) { + Handle(Graphic3d_AspectLine3d) aGraphicAspect = aLineAspect->Aspect(); + Aspect_TypeOfLine aCurrentType = aGraphicAspect->Type(); + isChanged = aType != aCurrentType; + if (isChanged) { + aLineAspect->SetTypeOfLine(aType); + } } } return isChanged;