1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0024762: Visualization - new interactive object AIS_ColoredShape with customized subshapes presentations

AIS_Shape, ::SetColor(), ::SetMaterial(), ::SetTransparency(), ::SetWidth() - improve consistency.
Setup color for marker aspect as well.

vaspects - new command superseeds vsetcolor, vsetmaterial, vsettransparancy, vsetwidth and their unset analogs. Improve syntax and arguments validation.

OpenGl_AspectMarker::SetAspect() - do not reset myMarkerSize when sprite is unchanged.

Extend NCollection_IndexedDataMap - Iterator::Key() and FindFromKey() with value copying.

Add test case bugs vis bug24762_coloredshape.
This commit is contained in:
kgv 2014-04-02 11:21:24 +04:00 committed by abv
parent a76ea94c2c
commit 6858f70e9a
15 changed files with 1997 additions and 842 deletions

View File

@ -325,6 +325,7 @@ is
class Triangulation; class Triangulation;
imported ColoredShape;
imported TexturedShape; imported TexturedShape;
class Drawer; class Drawer;

View File

@ -0,0 +1,460 @@
// Created on: 2014-04-24
// Created by: Kirill Gavrilov
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <AIS_ColoredShape.hxx>
#include <AIS_InteractiveContext.hxx>
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#include <gp_Pnt2d.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_Group.hxx>
#include <Graphic3d_StructureManager.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
#include <Precision.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <Prs3d_Presentation.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_Root.hxx>
#include <PrsMgr_PresentationManager3d.hxx>
#include <Standard_ErrorHandler.hxx>
#include <StdPrs_ShadedShape.hxx>
#include <StdPrs_ToolShadedShape.hxx>
#include <StdPrs_WFDeflectionShape.hxx>
#include <StdPrs_WFShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>
IMPLEMENT_STANDARD_HANDLE (AIS_ColoredDrawer, AIS_Drawer)
IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredDrawer, AIS_Drawer)
IMPLEMENT_STANDARD_HANDLE (AIS_ColoredShape, AIS_Shape)
IMPLEMENT_STANDARD_RTTIEXT(AIS_ColoredShape, AIS_Shape)
//=======================================================================
//function : AIS_ColoredShape
//purpose :
//=======================================================================
AIS_ColoredShape::AIS_ColoredShape (const TopoDS_Shape& theShape)
: AIS_Shape (theShape)
{
// disable dedicated line aspects
myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
}
//=======================================================================
//function : AIS_ColoredShape
//purpose :
//=======================================================================
AIS_ColoredShape::AIS_ColoredShape (const Handle(AIS_Shape)& theShape)
: AIS_Shape (theShape->Shape())
{
// disable dedicated line aspects
myDrawer->SetFreeBoundaryAspect (myDrawer->LineAspect());
myDrawer->SetUnFreeBoundaryAspect(myDrawer->LineAspect());
myDrawer->SetSeenLineAspect (myDrawer->LineAspect());
if (theShape->HasMaterial())
{
SetMaterial (theShape->Material());
}
if (theShape->HasColor())
{
SetColor (theShape->Color());
}
if (theShape->HasWidth())
{
SetWidth (theShape->Width());
}
if (theShape->IsTransparent())
{
SetTransparency (theShape->Transparency());
}
}
//=======================================================================
//function : CustomAspects
//purpose :
//=======================================================================
Handle(AIS_ColoredDrawer) AIS_ColoredShape::CustomAspects (const TopoDS_Shape& theShape)
{
Handle(AIS_ColoredDrawer) aDrawer;
myShapeColors.Find (theShape, aDrawer);
if (aDrawer.IsNull())
{
aDrawer = new AIS_ColoredDrawer (myDrawer);
myShapeColors.Bind (theShape, aDrawer);
LoadRecomputable (AIS_WireFrame);
LoadRecomputable (AIS_Shaded);
}
return aDrawer;
}
//=======================================================================
//function : ClearCustomAspects
//purpose :
//=======================================================================
void AIS_ColoredShape::ClearCustomAspects()
{
if (myShapeColors.IsEmpty())
{
return;
}
myShapeColors.Clear();
LoadRecomputable (AIS_WireFrame);
LoadRecomputable (AIS_Shaded);
}
//=======================================================================
//function : UnsetCustomAspects
//purpose :
//=======================================================================
void AIS_ColoredShape::UnsetCustomAspects (const TopoDS_Shape& theShape,
const Standard_Boolean theToUnregister)
{
if (!myShapeColors.IsBound (theShape))
{
return;
}
LoadRecomputable (AIS_WireFrame);
LoadRecomputable (AIS_Shaded);
if (theToUnregister)
{
myShapeColors.UnBind (theShape);
return;
}
myShapeColors.ChangeFind (theShape) = new AIS_ColoredDrawer (myDrawer);
}
//=======================================================================
//function : SetCustomColor
//purpose :
//=======================================================================
void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape& theShape,
const Quantity_Color& theColor)
{
if (theShape.IsNull())
{
return;
}
const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
setColor (aDrawer, theColor);
aDrawer->SetOwnColor (theColor);
LoadRecomputable (AIS_WireFrame);
LoadRecomputable (AIS_Shaded);
}
//=======================================================================
//function : SetCustomWidth
//purpose :
//=======================================================================
void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape,
const Standard_Real theLineWidth)
{
if (theShape.IsNull())
{
return;
}
const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
setWidth (CustomAspects (theShape), theLineWidth);
aDrawer->SetOwnWidth (theLineWidth);
LoadRecomputable (AIS_WireFrame);
LoadRecomputable (AIS_Shaded);
}
//=======================================================================
//function : SetColor
//purpose :
//=======================================================================
void AIS_ColoredShape::SetColor (const Quantity_Color& theColor)
{
setColor (myDrawer, theColor);
myOwnColor = theColor;
hasOwnColor = Standard_True;
LoadRecomputable (AIS_WireFrame);
LoadRecomputable (AIS_Shaded);
for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
{
const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
if (aDrawer->HasOwnColor())
{
continue;
}
if (aDrawer->HasShadingAspect())
{
aDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
}
if (aDrawer->HasLineAspect())
{
aDrawer->LineAspect()->SetColor (theColor);
}
if (aDrawer->HasWireAspect())
{
aDrawer->WireAspect()->SetColor (theColor);
}
}
}
//=======================================================================
//function : SetWidth
//purpose :
//=======================================================================
void AIS_ColoredShape::SetWidth (const Standard_Real theLineWidth)
{
setWidth (myDrawer, theLineWidth);
myOwnWidth = theLineWidth;
LoadRecomputable (AIS_WireFrame);
LoadRecomputable (AIS_Shaded);
for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
{
const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
if (aDrawer->HasOwnWidth())
{
continue;
}
if (aDrawer->HasLineAspect())
{
aDrawer->LineAspect()->SetWidth (theLineWidth);
}
if (aDrawer->HasWireAspect())
{
aDrawer->WireAspect()->SetWidth (theLineWidth);
}
}
}
//=======================================================================
//function : SetTransparency
//purpose :
//=======================================================================
void AIS_ColoredShape::SetTransparency (const Standard_Real theValue)
{
setTransparency (myDrawer, theValue);
myTransparency = theValue;
LoadRecomputable (AIS_WireFrame);
LoadRecomputable (AIS_Shaded);
for (DataMapOfShapeColor::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
{
const Handle(AIS_Drawer)& aDrawer = anIter.Value();
if (aDrawer->HasShadingAspect())
{
aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
}
}
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode)
{
thePrs->Clear();
if (IsInfinite())
{
thePrs->SetInfiniteState (Standard_True);
}
const Standard_Boolean isClosed = StdPrs_ToolShadedShape::IsClosed (myshape);
if (theMode == AIS_Shaded)
{
// compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
|| (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
{
BRepTools::Clean (myshape);
}
StdPrs_ShadedShape::Tessellate (myshape, myDrawer);
}
// 1) myShapeColors + myshape --> array[TopAbs_ShapeEnum] of map of color-to-compound
DataMapOfShapeCompd aTypeKeyshapeDrawshapeArray[(size_t )TopAbs_SHAPE];
dispatchColors (myshape, myShapeColors, aTypeKeyshapeDrawshapeArray);
// 2) finally add appropriate presentations (1 color -- 1 compound) according to theMode
Handle(AIS_ColoredDrawer) aCustomDrawer;
for (size_t aShType = 0; aShType < (size_t )TopAbs_SHAPE; ++aShType)
{
DataMapOfShapeCompd& aKeyshapeDrawshapeMap = aTypeKeyshapeDrawshapeArray[aShType];
for (DataMapOfShapeCompd::Iterator aMapIter (aKeyshapeDrawshapeMap);
aMapIter.More(); aMapIter.Next())
{
const TopoDS_Shape& aShapeKey = aMapIter.Key(); // key shape with detailed color or a base shape
const TopoDS_Compound& aShapeDraw = aMapIter.Value(); // compound of subshapes with <aShType> type
Handle(AIS_Drawer) aDrawer = !myShapeColors.Find (aShapeKey, aCustomDrawer) ? myDrawer : aCustomDrawer;
// Draw each kind of subshapes and personal-colored shapes in a separate group
// since it's necessary to set transparency/material for all subshapes
// without affecting their unique colors
Handle(Graphic3d_Group) aCurrGroup = Prs3d_Root::NewGroup (thePrs);
switch (theMode)
{
default:
case AIS_Shaded:
{
if ((Standard_Integer )aShapeDraw.ShapeType() <= TopAbs_FACE
&& !IsInfinite())
{
StdPrs_ShadedShape::Add (thePrs, aShapeDraw, aDrawer);
aDrawer->SetShadingAspectGlobal (Standard_False);
Handle(Graphic3d_AspectFillArea3d) anAsp = aDrawer->ShadingAspect()->Aspect();
isClosed ? anAsp->SuppressBackFace() : anAsp->AllowBackFace();
aCurrGroup->SetGroupPrimitivesAspect (anAsp);
break;
}
// compute wire-frame otherwise
}
case AIS_WireFrame:
{
StdPrs_WFDeflectionShape::Add (thePrs, aShapeDraw, aDrawer);
break;
}
}
}
}
}
//=======================================================================
//function : dispatchColors
//purpose :
//=======================================================================
Standard_Boolean AIS_ColoredShape::dispatchColors (const TopoDS_Shape& theBaseKey,
const TopoDS_Shape& theSubshapeToParse,
const DataMapOfShapeShape& theSubshapeKeyshapeMap,
const TopAbs_ShapeEnum theParentType,
DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray)
{
TopAbs_ShapeEnum aShType = theSubshapeToParse.ShapeType();
if (aShType == TopAbs_SHAPE)
{
return Standard_False;
}
// check own setting of current shape
TopoDS_Shape aKeyShape = theBaseKey;
Standard_Boolean isOverriden = theSubshapeKeyshapeMap.Find (theSubshapeToParse, aKeyShape);
// iterate on sub-shapes
BRep_Builder aBBuilder;
TopoDS_Shape aShapeCopy = theSubshapeToParse.EmptyCopied();
Standard_Boolean isSubOverride = Standard_False;
Standard_Integer nbDef = 0;
for (TopoDS_Iterator it (theSubshapeToParse); it.More(); it.Next())
{
if (dispatchColors (theBaseKey, it.Value(),
theSubshapeKeyshapeMap, aShType,
theTypeKeyshapeDrawshapeArray))
{
isSubOverride = Standard_True;
}
else
{
aBBuilder.Add (aShapeCopy, it.Value());
++nbDef;
}
}
if (aShType == TopAbs_FACE || !isSubOverride)
{
aShapeCopy = theSubshapeToParse;
}
else if (nbDef == 0)
{
return isOverriden || isSubOverride; // empty compound
}
// if any of styles is overridden regarding to default one, add rest to map
if (isOverriden
|| (isSubOverride && theParentType != TopAbs_WIRE // avoid drawing edges when vertex color is overridden
&& theParentType != TopAbs_FACE) // avoid drawing edges of the same color as face
|| (theParentType == TopAbs_SHAPE && !(isOverriden || isSubOverride))) // bind original shape to default color
{
TopoDS_Compound aCompound;
DataMapOfShapeCompd& aKeyshapeDrawshapeMap = theTypeKeyshapeDrawshapeArray[(size_t )aShType];
if (!aKeyshapeDrawshapeMap.FindFromKey (aKeyShape, aCompound))
{
aBBuilder.MakeCompound (aCompound);
aKeyshapeDrawshapeMap.Add (aKeyShape, aCompound);
}
aBBuilder.Add (aCompound, aShapeCopy);
}
return isOverriden || isSubOverride;
}
//=======================================================================
//function : dispatchColors
//purpose :
//=======================================================================
void AIS_ColoredShape::dispatchColors (const TopoDS_Shape& theBaseShape,
const DataMapOfShapeColor& theKeyshapeColorMap,
DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray)
{
// Extract <theShapeColors> map (KeyshapeColored -> Color)
// to subshapes map (Subshape -> KeyshapeColored).
// This needed when colored shape is not part of <theBaseShape>
// (but subshapes are) and actually container for subshapes.
DataMapOfShapeShape aSubshapeKeyshapeMap;
for (DataMapOfShapeColor::Iterator anIt (theKeyshapeColorMap);
anIt.More(); anIt.Next())
{
const TopoDS_Shape& aSh = anIt.Key();
TopAbs_ShapeEnum aType = aSh.ShapeType();
TopAbs_ShapeEnum aSubType = (aType == TopAbs_SOLID || aType == TopAbs_SHELL)
? TopAbs_FACE
: (aType == TopAbs_WIRE ? TopAbs_EDGE : TopAbs_SHAPE);
switch (aSubType)
{
case TopAbs_SHAPE:
{
aSubshapeKeyshapeMap.Bind (aSh, aSh);
break;
}
default:
{
for (TopExp_Explorer anExp (aSh, aSubType); anExp.More(); anExp.Next())
{
if (!aSubshapeKeyshapeMap.IsBound (anExp.Current()))
{
aSubshapeKeyshapeMap.Bind (anExp.Current(), aSh);
}
}
}
}
}
// Fill the array of maps per shape type
dispatchColors (theBaseShape, theBaseShape,
aSubshapeKeyshapeMap, TopAbs_SHAPE,
theTypeKeyshapeDrawshapeArray);
}

View File

@ -0,0 +1,145 @@
// Created on: 2014-04-24
// Created by: Kirill Gavrilov
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _AIS_ColoredShape_HeaderFile
#define _AIS_ColoredShape_HeaderFile
#include <AIS_Drawer.hxx>
#include <AIS_Shape.hxx>
#include <NCollection_DataMap.hxx>
#include <NCollection_IndexedDataMap.hxx>
#include <TopTools_ShapeMapHasher.hxx>
#include <TopoDS_Compound.hxx>
//! Customizable properties.
class AIS_ColoredDrawer : public AIS_Drawer
{
public:
AIS_ColoredDrawer (const Handle(AIS_Drawer)& theLink)
: myHasOwnColor (Standard_False),
myHasOwnWidth (Standard_False)
{
Link (theLink);
}
Standard_Boolean HasOwnColor() const { return myHasOwnColor; }
void UnsetOwnColor() { myHasOwnColor = Standard_False; }
void SetOwnColor (const Quantity_Color& /*theColor*/) { myHasOwnColor = Standard_True; }
Standard_Boolean HasOwnWidth() const { return myHasOwnWidth; }
void UnsetOwnWidth() { myHasOwnWidth = Standard_False; }
void SetOwnWidth (const Standard_Real /*theWidth*/) { myHasOwnWidth = Standard_True; }
public: //! @name list of overridden properties
Standard_Boolean myHasOwnColor;
Standard_Boolean myHasOwnWidth;
public:
DEFINE_STANDARD_RTTI(AIS_ColoredDrawer);
};
DEFINE_STANDARD_HANDLE(AIS_ColoredDrawer, AIS_Drawer)
//! Presentation of the shape with customizable sub-shapes properties.
class AIS_ColoredShape : public AIS_Shape
{
public:
//! Default constructor
Standard_EXPORT AIS_ColoredShape (const TopoDS_Shape& theShape);
//! Copy constructor
Standard_EXPORT AIS_ColoredShape (const Handle(AIS_Shape)& theShape);
public: //! @name sub-shape aspects
//! Customize properties of specified sub-shape.
//! The shape will be stored in the map but ignored, if it is not sub-shape of main Shape!
//! This method can be used to mark sub-shapes with customizable properties.
Standard_EXPORT Handle(AIS_ColoredDrawer) CustomAspects (const TopoDS_Shape& theShape);
//! Reset the map of custom sub-shape aspects.
Standard_EXPORT void ClearCustomAspects();
//! Reset custom properties of specified sub-shape.
//! @param theToUnregister unregister or not sub-shape from the map
Standard_EXPORT void UnsetCustomAspects (const TopoDS_Shape& theShape,
const Standard_Boolean theToUnregister = Standard_False);
//! Customize color of specified sub-shape
Standard_EXPORT void SetCustomColor (const TopoDS_Shape& theShape,
const Quantity_Color& theColor);
//! Customize line width of specified sub-shape
Standard_EXPORT void SetCustomWidth (const TopoDS_Shape& theShape,
const Standard_Real theLineWidth);
public: //! @name global aspects
//! Setup color of entire shape.
Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor);
//! Setup line width of entire shape.
Standard_EXPORT virtual void SetWidth (const Standard_Real theLineWidth);
//! Sets transparency value.
Standard_EXPORT virtual void SetTransparency (const Standard_Real theValue);
protected: //! @name override presentation computation
Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode);
protected:
typedef NCollection_DataMap<TopoDS_Shape, Handle(AIS_ColoredDrawer), TopTools_ShapeMapHasher> DataMapOfShapeColor;
typedef NCollection_DataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> DataMapOfShapeShape;
typedef NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Compound, TopTools_ShapeMapHasher> DataMapOfShapeCompd;
protected:
//! Recursive function to map shapes.
//! @param theBaseKey the key to be used for undetailed shapes (default colors)
//! @param theSubshapeToParse the subshape to be parsed
//! @param theSubshapeKeyshapeMap shapes map Subshape (in the base shape) -> Keyshape (detailed shape)
//! @param theParentType the parent subshape type
//! @param theTypeKeyshapeDrawshapeArray the array of shape types to fill
Standard_EXPORT static Standard_Boolean dispatchColors (const TopoDS_Shape& theBaseKey,
const TopoDS_Shape& theSubshapeToParse,
const DataMapOfShapeShape& theSubshapeKeyshapeMap,
const TopAbs_ShapeEnum theParentType,
DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray);
Standard_EXPORT static void dispatchColors (const TopoDS_Shape& theBaseShape,
const DataMapOfShapeColor& theKeyshapeColorMap,
DataMapOfShapeCompd* theTypeKeyshapeDrawshapeArray);
protected:
DataMapOfShapeColor myShapeColors;
public:
DEFINE_STANDARD_RTTI(AIS_ColoredShape);
};
DEFINE_STANDARD_HANDLE(AIS_ColoredShape, AIS_Shape)
#endif // _AIS_ColoredShape_HeaderFile

View File

@ -15,86 +15,136 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
inline Standard_Boolean AIS_Drawer::WasLastLocal() const inline Standard_Boolean AIS_Drawer::WasLastLocal() const
{return Standard_False;} {
return Standard_False;
}
inline Standard_Boolean AIS_Drawer::HasLocalAttributes() const inline Standard_Boolean AIS_Drawer::HasLocalAttributes() const
{return hasLocalAttributes;} {
return hasLocalAttributes;
}
inline Standard_Real AIS_Drawer::PreviousDeviationCoefficient () const inline Standard_Real AIS_Drawer::PreviousDeviationCoefficient() const
{return (myhasOwnDeviationCoefficient) ? myPreviousDeviationCoefficient : 0.0;} {
return myhasOwnDeviationCoefficient ? myPreviousDeviationCoefficient : 0.0;
}
inline Standard_Real AIS_Drawer::PreviousHLRDeviationCoefficient () const inline Standard_Real AIS_Drawer::PreviousHLRDeviationCoefficient() const
{return (myhasOwnHLRDeviationCoefficient) ? myPreviousHLRDeviationCoefficient : 0.0;} {
return myhasOwnHLRDeviationCoefficient ? myPreviousHLRDeviationCoefficient : 0.0;
}
inline Standard_Real AIS_Drawer::PreviousDeviationAngle () const inline Standard_Real AIS_Drawer::PreviousDeviationAngle() const
{return (myhasOwnDeviationAngle) ? myPreviousDeviationAngle : 0.0;} {
return myhasOwnDeviationAngle ? myPreviousDeviationAngle : 0.0;
}
inline Standard_Real AIS_Drawer::PreviousHLRDeviationAngle () const inline Standard_Real AIS_Drawer::PreviousHLRDeviationAngle() const
{return (myhasOwnHLRDeviationAngle) ? myPreviousHLRDeviationAngle : 0.0;} {
return myhasOwnHLRDeviationAngle ? myPreviousHLRDeviationAngle : 0.0;
}
inline void AIS_Drawer::Link ( const Handle(Prs3d_Drawer)& aDrawer) inline void AIS_Drawer::Link (const Handle(Prs3d_Drawer)& theDrawer)
{ myLink = aDrawer;} {
myLink = theDrawer;
}
inline Standard_Boolean AIS_Drawer::HasLink() const inline Standard_Boolean AIS_Drawer::HasLink() const
{ return ! myLink.IsNull();} {
return !myLink.IsNull();
}
inline void AIS_Drawer::SetDeviationCoefficient () inline void AIS_Drawer::SetDeviationCoefficient()
{ myhasOwnDeviationCoefficient = Standard_False; } {
myhasOwnDeviationCoefficient = Standard_False;
}
inline void AIS_Drawer::SetHLRDeviationCoefficient () inline void AIS_Drawer::SetHLRDeviationCoefficient()
{ myhasOwnHLRDeviationCoefficient = Standard_False; } {
myhasOwnHLRDeviationCoefficient = Standard_False;
}
inline void AIS_Drawer::SetDeviationAngle () inline void AIS_Drawer::SetDeviationAngle()
{ myhasOwnDeviationAngle = Standard_False;} {
myhasOwnDeviationAngle = Standard_False;
}
inline void AIS_Drawer::SetHLRAngle () inline void AIS_Drawer::SetHLRAngle()
{ myhasOwnHLRDeviationAngle = Standard_False;} {
myhasOwnHLRDeviationAngle = Standard_False;
}
inline Standard_Boolean AIS_Drawer::IsOwnDeviationCoefficient () const inline Standard_Boolean AIS_Drawer::IsOwnDeviationCoefficient() const
{ return myhasOwnDeviationCoefficient;} {
return myhasOwnDeviationCoefficient;
}
inline Standard_Boolean AIS_Drawer::IsOwnDeviationAngle () const inline Standard_Boolean AIS_Drawer::IsOwnDeviationAngle() const
{ return myhasOwnDeviationAngle;} {
return myhasOwnDeviationAngle;
}
inline Standard_Boolean AIS_Drawer::IsOwnHLRDeviationCoefficient () const inline Standard_Boolean AIS_Drawer::IsOwnHLRDeviationCoefficient() const
{ return myhasOwnHLRDeviationCoefficient;} {
return myhasOwnHLRDeviationCoefficient;
}
inline Standard_Boolean AIS_Drawer::IsOwnHLRDeviationAngle () const inline Standard_Boolean AIS_Drawer::IsOwnHLRDeviationAngle() const
{ return myhasOwnHLRDeviationAngle;} {
return myhasOwnHLRDeviationAngle;
}
inline Standard_Boolean AIS_Drawer::HasTextAspect () const inline Standard_Boolean AIS_Drawer::HasTextAspect() const
{ return (!myTextAspect.IsNull());} {
return !myTextAspect.IsNull();
}
inline Standard_Boolean AIS_Drawer::HasWireAspect () const inline Standard_Boolean AIS_Drawer::HasWireAspect() const
{ return (!myWireAspect.IsNull());} {
return !myWireAspect.IsNull();
}
inline Standard_Boolean AIS_Drawer::HasLineAspect () const inline Standard_Boolean AIS_Drawer::HasLineAspect() const
{return !myLineAspect.IsNull(); } {
return !myLineAspect.IsNull();
}
inline Standard_Boolean AIS_Drawer::HasShadingAspect () const inline Standard_Boolean AIS_Drawer::HasShadingAspect() const
{ return !myShadingAspect.IsNull();} {
return !myShadingAspect.IsNull();
}
inline Standard_Boolean AIS_Drawer::HasPointAspect () const inline Standard_Boolean AIS_Drawer::HasPointAspect() const
{ return !myPointAspect.IsNull();} {
return !myPointAspect.IsNull();
}
inline Standard_Boolean AIS_Drawer::HasDatumAspect () const inline Standard_Boolean AIS_Drawer::HasDatumAspect() const
{ return !myDatumAspect.IsNull();} {
return !myDatumAspect.IsNull();
}
inline Standard_Boolean AIS_Drawer::HasPlaneAspect () const inline Standard_Boolean AIS_Drawer::HasPlaneAspect() const
{ return !myPlaneAspect.IsNull();} {
return !myPlaneAspect.IsNull();
}
inline Standard_Boolean AIS_Drawer::IsOwnFaceBoundaryDraw () const inline Standard_Boolean AIS_Drawer::IsOwnFaceBoundaryDraw() const
{ return myHasOwnFaceBoundaryDraw; } {
return myHasOwnFaceBoundaryDraw;
}
inline Standard_Boolean AIS_Drawer::IsOwnFaceBoundaryAspect () const inline Standard_Boolean AIS_Drawer::IsOwnFaceBoundaryAspect() const
{ return !myFaceBoundaryAspect.IsNull (); } {
return !myFaceBoundaryAspect.IsNull();
}
inline void AIS_Drawer::SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR) inline void AIS_Drawer::SetTypeOfHLR (const Prs3d_TypeOfHLR theTypeOfHLR)
{ {
myTypeOfHLR = theTypeOfHLR; myTypeOfHLR = theTypeOfHLR;
} }
inline Prs3d_TypeOfHLR AIS_Drawer::TypeOfHLR ( ) const inline Prs3d_TypeOfHLR AIS_Drawer::TypeOfHLR() const
{ {
return (myTypeOfHLR == Prs3d_TOH_NotSet) ? myLink->TypeOfHLR() : myTypeOfHLR; return (myTypeOfHLR == Prs3d_TOH_NotSet) ? myLink->TypeOfHLR() : myTypeOfHLR;
} }

View File

@ -61,6 +61,7 @@ uses
Projector from Prs3d, Projector from Prs3d,
PresentationManager3d from PrsMgr, PresentationManager3d from PrsMgr,
Selection from SelectMgr, Selection from SelectMgr,
Drawer from AIS,
KindOfInteractive from AIS, KindOfInteractive from AIS,
Transformation from Geom, Transformation from Geom,
Drawer from Prs3d, Drawer from Prs3d,
@ -298,7 +299,21 @@ uses
aBox : Box from Bnd; aBox : Box from Bnd;
aDrawer : Drawer from Prs3d) is protected; aDrawer : Drawer from Prs3d) is protected;
setColor (me;
theDrawer : Drawer from AIS;
theColor : Color from Quantity)
is protected;
setWidth (me;
theDrawer : Drawer from AIS;
theWidth : Real from Standard)
is protected;
setTransparency (me;
theDrawer : Drawer from AIS;
theValue : Real from Standard)
is protected;
fields fields
myshape : Shape from TopoDS is protected; myshape : Shape from TopoDS is protected;
myBB : Box from Bnd is protected; myBB : Box from Bnd is protected;

View File

@ -215,23 +215,15 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
} }
case 1: case 1:
{ {
Standard_Real prevangle ; Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
Standard_Real newangle ; Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
Standard_Real prevcoeff ; Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
Standard_Real newcoeff ; if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
|| (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle(newangle,prevangle); {
Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(newcoeff,prevcoeff); BRepTools::Clean (myshape);
if (((Abs (newangle - prevangle) > Precision::Angular()) && isOwnDeviationAngle) ||
((Abs (newcoeff - prevcoeff) > Precision::Confusion()) && isOwnDeviationCoefficient)) {
#ifdef DEB
cout << "AIS_Shape : compute"<<endl;
cout << "newangl : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
#endif
BRepTools::Clean(myshape);
} }
//shading only on face... //shading only on face...
if ((Standard_Integer) myshape.ShapeType()>4) if ((Standard_Integer) myshape.ShapeType()>4)
StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer); StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
@ -496,134 +488,211 @@ void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
} }
//======================================================================= //=======================================================================
//function : SetColor //function : setColor
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_Shape::SetColor(const Quantity_Color &aCol) void AIS_Shape::setColor (const Handle(AIS_Drawer)& theDrawer,
const Quantity_Color& theColor) const
{ {
if( !HasColor() && !IsTransparent() && !HasMaterial() ) { if (!theDrawer->HasShadingAspect())
myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); {
theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
*theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
} }
if (!theDrawer->HasLineAspect())
{
theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
*theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
}
if (!theDrawer->HasWireAspect())
{
theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
*theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
}
if (!theDrawer->HasPointAspect())
{
theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
*theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
}
// disable dedicated line aspects
theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
// override color
theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
theDrawer->SetShadingAspectGlobal (Standard_False);
theDrawer->LineAspect()->SetColor (theColor);
theDrawer->WireAspect()->SetColor (theColor);
theDrawer->PointAspect()->SetColor (theColor);
}
//=======================================================================
//function : SetColor
//purpose :
//=======================================================================
void AIS_Shape::SetColor (const Quantity_Color& theColor)
{
setColor (myDrawer, theColor);
myOwnColor = theColor;
hasOwnColor = Standard_True; hasOwnColor = Standard_True;
myDrawer->ShadingAspect()->SetColor(aCol,myCurrentFacingModel);
myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel);
myDrawer->SetShadingAspectGlobal(Standard_False);
const Standard_Real WW = HasWidth()? Width():AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
myDrawer->SetLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
myDrawer->SetWireAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
// fast shading modification... // fast shading modification...
if(!GetContext().IsNull()){ if (!GetContext().IsNull())
if( GetContext()->MainPrsMgr()->HasPresentation(this,1)){ {
Handle(Prs3d_Presentation) aPresentation = if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded))
GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation(); {
Handle(Graphic3d_Group) aCurGroup = Prs3d_Root::CurrentGroup(aPresentation); Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->CastPresentation (this, AIS_Shaded)->Presentation();
Handle(Graphic3d_Group) aCurGroup = Prs3d_Root::CurrentGroup (aPrs);
Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect(); Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect(); Handle(Graphic3d_AspectLine3d) aLineAspect = myDrawer->LineAspect()->Aspect();
Handle(Graphic3d_AspectMarker3d) aPointAspect = myDrawer->PointAspect()->Aspect();
// Set aspects for presentation and for group // Set aspects for presentation and for group
aPresentation->SetPrimitivesAspect(anAreaAspect); aPrs->SetPrimitivesAspect (anAreaAspect);
aPresentation->SetPrimitivesAspect(aLineAspect); aPrs->SetPrimitivesAspect (aLineAspect);
aPrs->SetPrimitivesAspect (aPointAspect);
// Check if aspect of given type is set for the group, // Check if aspect of given type is set for the group,
// because setting aspect for group with no already set aspect // because setting aspect for group with no already set aspect
// can lead to loss of presentation data // can lead to loss of presentation data
if (aCurGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) if (aCurGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
aCurGroup->SetGroupPrimitivesAspect(anAreaAspect); {
if (aCurGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_LINE)) aCurGroup->SetGroupPrimitivesAspect (anAreaAspect);
aCurGroup->SetGroupPrimitivesAspect(aLineAspect); }
if (aCurGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
{
aCurGroup->SetGroupPrimitivesAspect (aLineAspect);
}
if (aCurGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
{
aCurGroup->SetGroupPrimitivesAspect (aPointAspect);
}
} }
} }
LoadRecomputable(0); LoadRecomputable (AIS_WireFrame);
LoadRecomputable(2); LoadRecomputable (2);
} }
//======================================================================= //=======================================================================
//function : UnsetColor //function : UnsetColor
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_Shape::UnsetColor() void AIS_Shape::UnsetColor()
{ {
if ( !HasColor() ) if (!HasColor())
{ {
myToRecomputeModes.Clear(); myToRecomputeModes.Clear();
return; return;
} }
hasOwnColor = Standard_False; hasOwnColor = Standard_False;
Handle(Prs3d_LineAspect) NullAsp; if (!HasWidth())
Handle(Prs3d_ShadingAspect) NullShA; {
Handle(Prs3d_LineAspect) anEmptyAsp;
if(!HasWidth()) { myDrawer->SetLineAspect (anEmptyAsp);
myDrawer->SetLineAspect(NullAsp); myDrawer->SetWireAspect (anEmptyAsp);
myDrawer->SetWireAspect(NullAsp); myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
myDrawer->SetFreeBoundaryAspect(NullAsp); myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
myDrawer->SetUnFreeBoundaryAspect(NullAsp); myDrawer->SetSeenLineAspect (anEmptyAsp);
myDrawer->SetSeenLineAspect(NullAsp);
} }
else { else
Quantity_Color CC; {
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); Quantity_Color aColor;
myDrawer->LineAspect()->SetColor(CC); AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, aColor);
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC); myDrawer->LineAspect()->SetColor (aColor);
myDrawer->WireAspect()->SetColor(CC); AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Wire, aColor);
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC); myDrawer->WireAspect()->SetColor (aColor);
myDrawer->FreeBoundaryAspect()->SetColor(CC); AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Free, aColor);
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC); myDrawer->FreeBoundaryAspect()->SetColor (aColor);
myDrawer->UnFreeBoundaryAspect()->SetColor(CC); AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_UnFree, aColor);
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC); myDrawer->UnFreeBoundaryAspect()->SetColor (aColor);
myDrawer->SeenLineAspect()->SetColor(CC); AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Seen, aColor);
myDrawer->SeenLineAspect()->SetColor (aColor);
} }
if( HasMaterial() || IsTransparent()) { if (HasMaterial()
|| IsTransparent())
{
Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link()); Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(HasMaterial()? myDrawer : myDrawer->Link());
if( HasMaterial() ) { if (HasMaterial())
Quantity_Color color = myDrawer->Link()->ShadingAspect()->Color(myCurrentFacingModel); {
mat.SetColor(color); Quantity_Color aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
mat.SetColor (aColor);
} }
if( IsTransparent() ) { if (IsTransparent())
Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel); {
mat.SetTransparency(trans); Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
mat.SetTransparency (aTransp);
} }
myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel); myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
} }
else { else
myDrawer->SetShadingAspect(NullShA); {
myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
} }
myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
if(!GetContext().IsNull()){ if (!GetContext().IsNull())
if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){ {
Handle(Prs3d_Presentation) aPresentation = if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded))
GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation(); {
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->CastPresentation (this, AIS_Shaded)->Presentation();
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect(); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->Link()->ShadingAspect()->Aspect();
Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect(); Handle(Graphic3d_AspectLine3d) aLineAsp = myDrawer->Link()->LineAspect()->Aspect();
Quantity_Color CC; Quantity_Color aColor;
AIS_GraphicTool::GetInteriorColor(myDrawer->Link(),CC); AIS_GraphicTool::GetInteriorColor (myDrawer->Link(), aColor);
anAreaAsp->SetInteriorColor(CC); anAreaAsp->SetInteriorColor (aColor);
aPresentation->SetPrimitivesAspect(anAreaAsp); aPrs->SetPrimitivesAspect (anAreaAsp);
aPresentation->SetPrimitivesAspect(aLineAsp); aPrs->SetPrimitivesAspect (aLineAsp);
// Check if aspect of given type is set for the group, // Check if aspect of given type is set for the group,
// because setting aspect for group with no already set aspect // because setting aspect for group with no already set aspect
// can lead to loss of presentation data // can lead to loss of presentation data
if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
aGroup->SetGroupPrimitivesAspect(anAreaAsp); {
if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_LINE)) aGroup->SetGroupPrimitivesAspect (anAreaAsp);
aGroup->SetGroupPrimitivesAspect(aLineAsp); }
if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
{
aGroup->SetGroupPrimitivesAspect (aLineAsp);
}
} }
} }
LoadRecomputable(0); LoadRecomputable (AIS_WireFrame);
LoadRecomputable(2); LoadRecomputable (2);
}
//=======================================================================
//function : setWidth
//purpose :
//=======================================================================
void AIS_Shape::setWidth (const Handle(AIS_Drawer)& theDrawer,
const Standard_Real theLineWidth) const
{
if (!theDrawer->HasLineAspect())
{
theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
*theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
}
if (!theDrawer->HasWireAspect())
{
theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
*theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
}
// disable dedicated line aspects
theDrawer->SetFreeBoundaryAspect (theDrawer->LineAspect());
theDrawer->SetUnFreeBoundaryAspect(theDrawer->LineAspect());
theDrawer->SetSeenLineAspect (theDrawer->LineAspect());
// override width
theDrawer->LineAspect()->SetWidth (theLineWidth);
theDrawer->WireAspect()->SetWidth (theLineWidth);
} }
//======================================================================= //=======================================================================
@ -631,64 +700,48 @@ void AIS_Shape::UnsetColor()
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_Shape::SetWidth(const Standard_Real W) void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
{ {
if(HasColor() || HasWidth()){ setWidth (myDrawer, theLineWidth);
myDrawer->LineAspect()->SetWidth(W); myOwnWidth = theLineWidth;
myDrawer->WireAspect()->SetWidth(W); LoadRecomputable (AIS_WireFrame); // means that it is necessary to recompute only the wireframe....
myDrawer->FreeBoundaryAspect()->SetWidth(W); LoadRecomputable (2); // and the bounding box...
myDrawer->UnFreeBoundaryAspect()->SetWidth(W);
myDrawer->SeenLineAspect()->SetWidth(W);
}
else{
Quantity_Color CC;
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
myDrawer->SetLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Wire,CC);
myDrawer->SetWireAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Free,CC);
myDrawer->SetFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_UnFree,CC);
myDrawer->SetUnFreeBoundaryAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Seen,CC);
myDrawer->SetSeenLineAspect(new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,W));
}
myOwnWidth = W;
LoadRecomputable(0); // means that it is necessary to recompute only the wireframe....
LoadRecomputable(2); // and the bounding box...
} }
//======================================================================= //=======================================================================
//function : UnsetWidth //function : UnsetWidth
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_Shape::UnsetWidth() void AIS_Shape::UnsetWidth()
{ {
if(myOwnWidth == 0.0) if (myOwnWidth == 0.0)
{ {
myToRecomputeModes.Clear(); myToRecomputeModes.Clear();
return; return;
} }
myOwnWidth=0.0;
Handle(Prs3d_LineAspect) NullAsp; myOwnWidth = 0.0;
if(!HasColor()){ Handle(Prs3d_LineAspect) anEmptyAsp;
myDrawer->SetLineAspect(NullAsp);
myDrawer->SetWireAspect(NullAsp); if (!HasColor())
myDrawer->SetFreeBoundaryAspect(NullAsp); {
myDrawer->SetUnFreeBoundaryAspect(NullAsp); myDrawer->SetLineAspect (anEmptyAsp);
myDrawer->SetSeenLineAspect(NullAsp); myDrawer->SetWireAspect (anEmptyAsp);
myDrawer->SetFreeBoundaryAspect (anEmptyAsp);
myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
myDrawer->SetSeenLineAspect (anEmptyAsp);
} }
else{ else
myDrawer->LineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line)); {
myDrawer->WireAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Wire)); myDrawer->LineAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line));
myDrawer->FreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Free)); myDrawer->WireAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Wire));
myDrawer->UnFreeBoundaryAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_UnFree)); myDrawer->FreeBoundaryAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Free));
myDrawer->SeenLineAspect()->SetWidth(AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Seen)); myDrawer->UnFreeBoundaryAspect()->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_UnFree));
myDrawer->SeenLineAspect() ->SetWidth (AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Seen));
} }
LoadRecomputable(0); LoadRecomputable (AIS_WireFrame);
} }
//======================================================================= //=======================================================================
@ -703,146 +756,188 @@ void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
//======================================================================= //=======================================================================
//function : SetMaterial //function : SetMaterial
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_Shape::SetMaterial(const Graphic3d_MaterialAspect& aMat) void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
{ {
if( !HasColor() && !IsTransparent() && !HasMaterial() ) { if (!myDrawer->HasShadingAspect())
myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); {
myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
*myDrawer->ShadingAspect()->Aspect() = *myDrawer->Link()->ShadingAspect()->Aspect();
} }
hasOwnMaterial = Standard_True; hasOwnMaterial = Standard_True;
myDrawer->ShadingAspect()->SetMaterial(aMat,myCurrentFacingModel); myDrawer->ShadingAspect()->SetMaterial (theMat, myCurrentFacingModel);
myDrawer->ShadingAspect()->SetTransparency(myTransparency,myCurrentFacingModel); if (HasColor())
{
myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
}
myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
if(!GetContext().IsNull()){ if (!GetContext().IsNull())
if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){ {
Handle(Prs3d_Presentation) aPresentation = if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded))
GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation(); {
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->CastPresentation (this, AIS_Shaded)->Presentation();
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
aPresentation->SetPrimitivesAspect(anAreaAsp); aPrs->SetPrimitivesAspect (anAreaAsp);
// Check if aspect of given type is set for the group, // Check if aspect of given type is set for the group,
// because setting aspect for group with no already set aspect // because setting aspect for group with no already set aspect
// can lead to loss of presentation data // can lead to loss of presentation data
if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
aGroup->SetGroupPrimitivesAspect(anAreaAsp); {
aGroup->SetGroupPrimitivesAspect (anAreaAsp);
}
} }
myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
myToRecomputeModes.Clear(); myToRecomputeModes.Clear();
} }
} }
//======================================================================= //=======================================================================
//function : UnsetMaterial //function : UnsetMaterial
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_Shape::UnsetMaterial() void AIS_Shape::UnsetMaterial()
{ {
if( !HasMaterial() ) return; if (!HasMaterial())
{
return;
}
if( HasColor() || IsTransparent()) { if (HasColor()
Graphic3d_MaterialAspect mat = AIS_GraphicTool::GetMaterial(myDrawer->Link()); || IsTransparent())
if( HasColor() ) { {
Quantity_Color color = myDrawer->ShadingAspect()->Color(myCurrentFacingModel); myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
mat.SetColor(color); myCurrentFacingModel);
if (HasColor())
{
myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
} }
if( IsTransparent() ) { }
Standard_Real trans = myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel); else
mat.SetTransparency(trans); {
} myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
myDrawer->ShadingAspect()->SetMaterial(mat,myCurrentFacingModel);
} else {
Handle(Prs3d_ShadingAspect) SA;
myDrawer->SetShadingAspect(SA);
} }
hasOwnMaterial = Standard_False; hasOwnMaterial = Standard_False;
if(!GetContext().IsNull()){
if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){ if (!GetContext().IsNull())
Handle(Prs3d_Presentation) aPresentation = {
GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation(); if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded))
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); {
Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->CastPresentation (this, AIS_Shaded)->Presentation();
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
aPresentation->SetPrimitivesAspect(anAreaAsp); aPrs->SetPrimitivesAspect (anAreaAsp);
// Check if aspect of given type is set for the group, // Check if aspect of given type is set for the group,
// because setting aspect for group with no already set aspect // because setting aspect for group with no already set aspect
// can lead to loss of presentation data // can lead to loss of presentation data
if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
aGroup->SetGroupPrimitivesAspect(anAreaAsp); {
aGroup->SetGroupPrimitivesAspect (anAreaAsp);
}
} }
} }
myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
myToRecomputeModes.Clear(); myToRecomputeModes.Clear();
} }
//======================================================================= //=======================================================================
//function : SetTransparency //function : setTransparency
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_Shape::SetTransparency(const Standard_Real AValue) void AIS_Shape::setTransparency (const Handle(AIS_Drawer)& theDrawer,
const Standard_Real theValue) const
{ {
if ( !HasColor() && !HasMaterial() ) { if (!theDrawer->HasShadingAspect())
myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); {
theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
*theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
} }
myDrawer->ShadingAspect()->SetTransparency(AValue,myCurrentFacingModel);
myTransparency = AValue;
if(!GetContext().IsNull()){ // override transparency
if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){ theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
Handle(Prs3d_Presentation) aPresentation = }
GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation); //=======================================================================
//function : SetTransparency
//purpose :
//=======================================================================
void AIS_Shape::SetTransparency (const Standard_Real theValue)
{
setTransparency (myDrawer, theValue);
myTransparency = theValue;
if (!GetContext().IsNull())
{
if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded))
{
Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->CastPresentation (this, AIS_Shaded)->Presentation();
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
aPresentation->SetPrimitivesAspect(anAreaAsp); aPrs->SetPrimitivesAspect (anAreaAsp);
//force highest priority for transparent objects // force highest priority for transparent objects
aPresentation->SetDisplayPriority(10); aPrs->SetDisplayPriority (10);
// Check if aspect of given type is set for the group, // Check if aspect of given type is set for the group,
// because setting aspect for group with no already set aspect // because setting aspect for group with no already set aspect
// can lead to loss of presentation data // can lead to loss of presentation data
if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
aGroup->SetGroupPrimitivesAspect(anAreaAsp); {
aGroup->SetGroupPrimitivesAspect (anAreaAsp);
}
} }
} }
myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
myToRecomputeModes.Clear(); myToRecomputeModes.Clear();
} }
//======================================================================= //=======================================================================
//function : UnsetTransparency //function : UnsetTransparency
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_Shape::UnsetTransparency() void AIS_Shape::UnsetTransparency()
{ {
if( HasColor() || HasMaterial() ) { myTransparency = 0.0;
myDrawer->ShadingAspect()->SetTransparency(0.0,myCurrentFacingModel); if (!myDrawer->HasShadingAspect())
} else { {
Handle(Prs3d_ShadingAspect) SA; return;
myDrawer->SetShadingAspect(SA); }
else if (HasColor() || HasMaterial())
{
myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
}
else
{
myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
} }
myTransparency = 0.0; if (!GetContext().IsNull())
{
if(!GetContext().IsNull()){ if (GetContext()->MainPrsMgr()->HasPresentation (this, AIS_Shaded))
if(GetContext()->MainPrsMgr()->HasPresentation(this,1)){ {
Handle(Prs3d_Presentation) aPresentation = Handle(Prs3d_Presentation) aPrs = GetContext()->MainPrsMgr()->CastPresentation (this, AIS_Shaded)->Presentation();
GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation(); Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPrs);
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect(); Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
aPresentation->SetPrimitivesAspect(anAreaAsp); aPrs->SetPrimitivesAspect (anAreaAsp);
// Check if aspect of given type is set for the group, // Check if aspect of given type is set for the group,
// because setting aspect for group with no already set aspect // because setting aspect for group with no already set aspect
// can lead to loss of presentation data // can lead to loss of presentation data
if (aGroup->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA)) if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
aGroup->SetGroupPrimitivesAspect(anAreaAsp); {
aGroup->SetGroupPrimitivesAspect (anAreaAsp);
aPresentation->ResetDisplayPriority(); }
aPrs->ResetDisplayPriority();
} }
} }
myRecomputeEveryPrs =Standard_False; // no mode to recalculate :only viewer update myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
myToRecomputeModes.Clear(); myToRecomputeModes.Clear();
} }

View File

@ -5,6 +5,8 @@ AIS_LocalContext_1.cxx
AIS_NListTransient.hxx AIS_NListTransient.hxx
AIS_NListIteratorOfListTransient.hxx AIS_NListIteratorOfListTransient.hxx
AIS_NDataMapOfTransientIteratorOfListTransient.hxx AIS_NDataMapOfTransientIteratorOfListTransient.hxx
AIS_ColoredShape.hxx
AIS_ColoredShape.cxx
AIS_TexturedShape.hxx AIS_TexturedShape.hxx
AIS_TexturedShape.cxx AIS_TexturedShape.cxx
AIS_Triangulation.cdl AIS_Triangulation.cdl

View File

@ -392,6 +392,12 @@ is
-- Trigger: when <aRank> is < 1 or > NumberOfMaterials. -- Trigger: when <aRank> is < 1 or > NumberOfMaterials.
---Level: Public ---Level: Public
MaterialFromName (myclass;
theName : CString from Standard)
returns NameOfMaterial from Graphic3d;
---Purpose:
-- Returns the material for specified name or Graphic3d_NOM_DEFAULT if name is unknown.
---------------------------- ----------------------------
-- Category: Private methods -- Category: Private methods
---------------------------- ----------------------------

View File

@ -900,6 +900,48 @@ Standard_CString Graphic3d_MaterialAspect::MaterialName(const Standard_Integer a
return theMaterials[aRank-1].name; return theMaterials[aRank-1].name;
} }
Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::MaterialFromName (const Standard_CString theName)
{
TCollection_AsciiString aName (theName);
aName.LowerCase();
aName.Capitalize();
const Standard_Integer aNbMaterials = Graphic3d_MaterialAspect::NumberOfMaterials();
for (Standard_Integer aMatIter = 1; aMatIter <= aNbMaterials; ++aMatIter)
{
if (aName == Graphic3d_MaterialAspect::MaterialName (aMatIter))
{
return Graphic3d_NameOfMaterial(aMatIter - 1);
}
}
// parse aliases
if (aName == "Plastic") // Plastified
{
return Graphic3d_NOM_PLASTIC;
}
else if (aName == "Shiny_plastic") // Shiny_plastified
{
return Graphic3d_NOM_SHINY_PLASTIC;
}
else if (aName == "Plaster") // Plastered
{
return Graphic3d_NOM_PLASTER;
}
else if (aName == "Satin") // Satined
{
return Graphic3d_NOM_SATIN;
}
else if (aName == "Neon_gnc") // Ionized
{
return Graphic3d_NOM_NEON_GNC;
}
else if (aName == "Neon_phc") // Neon
{
return Graphic3d_NOM_NEON_PHC;
}
return Graphic3d_NOM_DEFAULT;
}
Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType(const Standard_Integer aRank) { Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType(const Standard_Integer aRank) {
if( aRank < 1 || aRank > NumberOfMaterials() ) if( aRank < 1 || aRank > NumberOfMaterials() )

View File

@ -104,15 +104,18 @@ template < class TheKeyType,
myMap(NULL), myMap(NULL),
myIndex(0) {} myIndex(0) {}
//! Constructor //! Constructor
Iterator (const NCollection_IndexedDataMap& theMap) : Iterator (const NCollection_IndexedDataMap& theMap)
myMap((NCollection_IndexedDataMap *) &theMap), : myMap ((NCollection_IndexedDataMap* )&theMap),
myIndex(1) {} myNode (myMap->nodeFromIndex (1)),
myIndex (1) {}
//! Query if the end of collection is reached by iterator //! Query if the end of collection is reached by iterator
virtual Standard_Boolean More(void) const virtual Standard_Boolean More(void) const
{ return (myIndex <= myMap->Extent()); } { return (myIndex <= myMap->Extent()); }
//! Make a step along the collection //! Make a step along the collection
virtual void Next(void) virtual void Next(void)
{ myIndex++; } {
myNode = myMap->nodeFromIndex (++myIndex);
}
//! Value access //! Value access
virtual const TheItemType& Value(void) const virtual const TheItemType& Value(void) const
{ {
@ -120,7 +123,7 @@ template < class TheKeyType,
if (!More()) if (!More())
Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::Iterator::Value"); Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::Iterator::Value");
#endif #endif
return myMap->FindFromIndex(myIndex); return myNode->Value();
} }
//! ChangeValue access //! ChangeValue access
virtual TheItemType& ChangeValue(void) const virtual TheItemType& ChangeValue(void) const
@ -129,12 +132,21 @@ template < class TheKeyType,
if (!More()) if (!More())
Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::Iterator::ChangeValue"); Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::Iterator::ChangeValue");
#endif #endif
return myMap->ChangeFromIndex(myIndex); return myNode->ChangeValue();
}
//! Key
const TheKeyType& Key() const
{
#if !defined No_Exception && !defined No_Standard_NoSuchObject
if (!More())
Standard_NoSuchObject::Raise("NCollection_DataMap::Iterator::Key");
#endif
return myNode->Key1();
} }
private: private:
NCollection_IndexedDataMap * myMap; //!< Pointer to the map being iterated NCollection_IndexedDataMap* myMap; //!< Pointer to the map being iterated
Standard_Integer myIndex; //!< Current index IndexedDataMapNode* myNode; //!< Current node
Standard_Integer myIndex; //!< Current index
}; };
public: public:
@ -365,16 +377,12 @@ template < class TheKeyType,
if (theKey2 < 1 || theKey2 > Extent()) if (theKey2 < 1 || theKey2 > Extent())
Standard_OutOfRange::Raise ("NCollection_IndexedDataMap::FindKey"); Standard_OutOfRange::Raise ("NCollection_IndexedDataMap::FindKey");
#endif #endif
IndexedDataMapNode * pNode2 = IndexedDataMapNode* aNode = nodeFromIndex (theKey2);
(IndexedDataMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; if (aNode == NULL)
while (pNode2)
{ {
if (pNode2->Key2() == theKey2) Standard_NoSuchObject::Raise ("NCollection_IndexedDataMap::FindKey");
return pNode2->Key1();
pNode2 = (IndexedDataMapNode*) pNode2->Next2();
} }
Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::FindKey"); return aNode->Key1();
return pNode2->Key1(); // This for compiler
} }
//! FindFromIndex //! FindFromIndex
@ -384,16 +392,12 @@ template < class TheKeyType,
if (theKey2 < 1 || theKey2 > Extent()) if (theKey2 < 1 || theKey2 > Extent())
Standard_OutOfRange::Raise ("NCollection_IndexedDataMap::FindFromIndex"); Standard_OutOfRange::Raise ("NCollection_IndexedDataMap::FindFromIndex");
#endif #endif
IndexedDataMapNode * pNode2 = IndexedDataMapNode* aNode = nodeFromIndex (theKey2);
(IndexedDataMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; if (aNode == NULL)
while (pNode2)
{ {
if (pNode2->Key2() == theKey2) Standard_NoSuchObject::Raise ("NCollection_IndexedDataMap::FindFromIndex");
return pNode2->Value();
pNode2 = (IndexedDataMapNode*) pNode2->Next2();
} }
Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::FindFromIndex"); return aNode->Value();
return pNode2->Value(); // This for compiler
} }
//! operator () //! operator ()
@ -407,16 +411,12 @@ template < class TheKeyType,
if (theKey2 < 1 || theKey2 > Extent()) if (theKey2 < 1 || theKey2 > Extent())
Standard_OutOfRange::Raise("NCollection_IndexedDataMap::ChangeFromIndex"); Standard_OutOfRange::Raise("NCollection_IndexedDataMap::ChangeFromIndex");
#endif #endif
IndexedDataMapNode * pNode2 = IndexedDataMapNode* aNode = nodeFromIndex (theKey2);
(IndexedDataMapNode *) myData2[::HashCode(theKey2,NbBuckets())]; if (aNode == NULL)
while (pNode2)
{ {
if (pNode2->Key2() == theKey2) Standard_NoSuchObject::Raise ("NCollection_IndexedDataMap::ChangeFromIndex");
return pNode2->ChangeValue();
pNode2 = (IndexedDataMapNode*) pNode2->Next2();
} }
Standard_NoSuchObject::Raise("NCollection_IndexedDataMap::FindFromIndex"); return aNode->ChangeValue();
return pNode2->ChangeValue(); // This for compiler
} }
//! operator () //! operator ()
@ -476,6 +476,27 @@ template < class TheKeyType,
return pNode1->ChangeValue(); return pNode1->ChangeValue();
} }
//! Find value for key with copying.
//! @return true if key was found
Standard_Boolean FindFromKey (const TheKeyType& theKey1,
TheItemType& theValue) const
{
if (IsEmpty())
{
return Standard_False;
}
for (IndexedDataMapNode* aNode = (IndexedDataMapNode* )myData1[Hasher::HashCode (theKey1, NbBuckets())];
aNode != NULL; aNode = (IndexedDataMapNode* )aNode->Next())
{
if (Hasher::IsEqual (aNode->Key1(), theKey1))
{
theValue = aNode->Value();
return Standard_True;
}
}
return Standard_False;
}
//! Clear data. If doReleaseMemory is false then the table of //! Clear data. If doReleaseMemory is false then the table of
//! buckets is not released and will be reused. //! buckets is not released and will be reused.
void Clear(const Standard_Boolean doReleaseMemory = Standard_True) void Clear(const Standard_Boolean doReleaseMemory = Standard_True)
@ -505,6 +526,25 @@ template < class TheKeyType,
CreateIterator(void) const CreateIterator(void) const
{ return *(new (this->IterAllocator()) Iterator(*this)); } { return *(new (this->IterAllocator()) Iterator(*this)); }
//! Find map node associated with specified index.
//! Return NULL if not found (exception-free internal implementation).
IndexedDataMapNode* nodeFromIndex (const Standard_Integer theKey2) const
{
if (Extent() == 0)
{
return NULL;
}
for (IndexedDataMapNode* aNode = (IndexedDataMapNode* )myData2[::HashCode (theKey2, NbBuckets())];
aNode != NULL; aNode = (IndexedDataMapNode* )aNode->Next2())
{
if (aNode->Key2() == theKey2)
{
return aNode;
}
}
return NULL;
}
}; };
#endif #endif

View File

@ -1462,13 +1462,13 @@ OpenGl_AspectMarker::OpenGl_AspectMarker()
// ======================================================================= // =======================================================================
void OpenGl_AspectMarker::SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect) void OpenGl_AspectMarker::SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect)
{ {
myColor.rgb[0] = (float )theAspect.Color.r; myColor.rgb[0] = (float )theAspect.Color.r;
myColor.rgb[1] = (float )theAspect.Color.g; myColor.rgb[1] = (float )theAspect.Color.g;
myColor.rgb[2] = (float )theAspect.Color.b; myColor.rgb[2] = (float )theAspect.Color.b;
myColor.rgb[3] = 1.0f; myColor.rgb[3] = 1.0f;
myMarkerImage = theAspect.MarkerImage; myMarkerImage = theAspect.MarkerImage;
myType = theAspect.MarkerType; myType = theAspect.MarkerType;
myScale = myMarkerSize = theAspect.Scale; myScale = theAspect.Scale;
myShaderProgram = theAspect.ShaderProgram; myShaderProgram = theAspect.ShaderProgram;
// update sprite resource bindings // update sprite resource bindings
@ -1476,13 +1476,11 @@ void OpenGl_AspectMarker::SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect)
TCollection_AsciiString aSpriteAKey = THE_EMPTY_KEY; TCollection_AsciiString aSpriteAKey = THE_EMPTY_KEY;
myResources.SpriteKeys (myMarkerImage, myType, myScale, myColor, aSpriteKey, aSpriteAKey); myResources.SpriteKeys (myMarkerImage, myType, myScale, myColor, aSpriteKey, aSpriteAKey);
if (aSpriteKey.IsEmpty() || myResources.SpriteKey != aSpriteKey) if (aSpriteKey.IsEmpty() || myResources.SpriteKey != aSpriteKey
{ || aSpriteAKey.IsEmpty() || myResources.SpriteAKey != aSpriteAKey)
myResources.ResetSpriteReadiness();
}
if (aSpriteAKey.IsEmpty() || myResources.SpriteAKey != aSpriteAKey)
{ {
myResources.ResetSpriteReadiness(); myResources.ResetSpriteReadiness();
myMarkerSize = theAspect.Scale;
} }
// update shader program resource bindings // update shader program resource bindings

View File

@ -44,4 +44,9 @@ is
theUVScale : Pnt2d from gp); theUVScale : Pnt2d from gp);
---Purpose: Shades <theShape> with texture coordinates. ---Purpose: Shades <theShape> with texture coordinates.
Tessellate (myclass;
theShape : Shape from TopoDS;
theDrawer : Drawer from Prs3d);
---Purpose: Validates triangulation within the shape and performs tessellation if necessary.
end ShadedShape; end ShadedShape;

View File

@ -358,6 +358,32 @@ void StdPrs_ShadedShape::Add (const Handle(Prs3d_Presentation)& thePresentation,
Standard_False, aDummy, aDummy, aDummy); Standard_False, aDummy, aDummy, aDummy);
} }
// =======================================================================
// function : Tessellate
// purpose :
// =======================================================================
void StdPrs_ShadedShape::Tessellate (const TopoDS_Shape& theShape,
const Handle (Prs3d_Drawer)& theDrawer)
{
// Check if it is possible to avoid unnecessary recomputation
// of shape triangulation
Standard_Real aDeflection = GetDeflection (theShape, theDrawer);
if (BRepTools::Triangulation (theShape, aDeflection))
{
return;
}
// retrieve meshing tool from Factory
BRepTools::Clean (theShape);
Handle(BRepMesh_DiscretRoot) aMeshAlgo = BRepMesh_DiscretFactory::Get().Discret (theShape,
aDeflection,
theDrawer->HLRAngle());
if (!aMeshAlgo.IsNull())
{
aMeshAlgo->Perform();
}
}
// ======================================================================= // =======================================================================
// function : Add // function : Add
// purpose : // purpose :
@ -408,22 +434,8 @@ void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePresentation
StdPrs_WFShape::Add (thePresentation, theShape, theDrawer); StdPrs_WFShape::Add (thePresentation, theShape, theDrawer);
} }
} }
Standard_Real aDeflection = GetDeflection (theShape, theDrawer);
// Check if it is possible to avoid unnecessary recomputation
// of shape triangulation
if (!BRepTools::Triangulation (theShape, aDeflection))
{
BRepTools::Clean (theShape);
// retrieve meshing tool from Factory
Handle(BRepMesh_DiscretRoot) aMeshAlgo = BRepMesh_DiscretFactory::Get().Discret (theShape,
aDeflection,
theDrawer->HLRAngle());
if (!aMeshAlgo.IsNull())
aMeshAlgo->Perform();
}
Tessellate (theShape, theDrawer);
ShadeFromShape (theShape, thePresentation, theDrawer, ShadeFromShape (theShape, thePresentation, theDrawer,
theHasTexels, theUVOrigin, theUVRepeat, theUVScale); theHasTexels, theUVOrigin, theUVRepeat, theUVScale);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,48 @@
puts "========"
puts "OCC24762 new interactive object AIS_ColoredShape with customized subshapes presentations"
puts "========"
# draw box in advance which should fit all our markers
box b 0 0 0 1 2 3
box bb 3 0 0 2 3 1
# prepare view
vinit View1
vclear
vglinfo
vsetdispmode 1
vaxo
vdisplay b bb
vfit
# customize box 1
explode b V
vaspects b -subshapes b_1 -setcolor GREEN
explode b E
vaspects b -subshapes b_6 b_12 -setcolor RED -setwidth 6
explode b W
vaspects b -subshapes b_2 -setcolor HOTPINK -setwidth 4
explode b F
vaspects b -subshapes b_3 -setcolor GRAY
# customize box 2
explode bb F
vaspects bb -setcolor GREEN -subshapes bb_6 -setcolor RED
vsetdispmode bb 0
# take snapshot
vdump $imagedir/${casename}.png
# check colors on box 1
set aWireColor [vreadpixel 54 150 rgb name]
set anEdgeColor [vreadpixel 100 90 rgb name]
set aFaceColor [vreadpixel 30 200 rgb name]
if {"$aWireColor" != "HOTPINK"} {
puts "Error: wrong Wire color"
}
if {"$anEdgeColor" != "RED"} {
puts "Error: wrong Edge color"
}
if {"$aFaceColor" != "LEMONCHIFFON1"} {
puts "Error: wrong Face color"
}