1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

Compare commits

...

24 Commits

Author SHA1 Message Date
snn
01296da21c rebase on CR0-OCCT730 (V7_3_0) 2018-08-23 17:34:33 +03:00
ema
ca4b907317 refs 474:Possibility to create and play animations 2018-08-23 12:08:48 +03:00
aba
535b320eaf corrected view cube positioning 2018-08-23 12:08:15 +03:00
ema
173f5b0dcc Corrections afer rebasing on V 7.2.0 2018-08-23 12:08:13 +03:00
aba
15e59662ee 0028954: Visualization - implement interactive object for camera manipulations 2018-08-23 12:07:39 +03:00
ema
d1211c59c5 refs #355: Add possibility to hide clipping plane 2018-08-23 12:07:22 +03:00
apl
33edf52c4d #265 Possibility to display materials by different hatching style when we make clipping 2018-08-23 12:07:20 +03:00
ika
bc6b1013d4 Fix reading name of shape from subtype of PRODUCT_DEFINITION STEP entity 2018-08-23 12:05:18 +03:00
kgv
aef69abba1 Add missing dependences to EXTERNLIB 2018-08-23 12:04:34 +03:00
snn
ed9b49bac1 refs #314: Get notes attached to sub-shapes/attributes of an assembly item 2018-08-23 12:04:33 +03:00
snn
fe07305a54 Notes attached to an assembly item sub-shape overwrite other assembly item notes 2018-08-23 12:04:32 +03:00
ema
284201c834 Saving notes positions in the view 2018-08-23 12:04:30 +03:00
ema
d4e54977cb Saving notes in the view 2018-08-23 12:04:29 +03:00
ema
de486dae37 Storage the parts transparency in the view 2018-08-23 12:04:28 +03:00
ema
75e21c522f Storage image to view 2018-08-23 12:04:27 +03:00
snn
88c31d4658 XCAF: assembly item ref extended to point on attributes and sub-shape indices 2018-08-23 12:04:26 +03:00
snn
691fb5d8c3 XCAF: assembly item ref driver added, file name typo correction 2018-08-23 12:04:24 +03:00
snn
9e053143d0 XCAF: assembly item/part id, notes for assembly items 2018-08-23 12:04:23 +03:00
snn
5ba308215e XCAF: notes Bin/XML drivers 2018-08-23 12:04:22 +03:00
dbv
60243601c0 Improved vrml reading 2018-08-23 12:04:21 +03:00
akz
2e8a449016 Implement reading of vrml assembly into OCAF 2018-08-23 12:04:19 +03:00
msv
9af219655a More correction in the algorithm of merging edges, applying more strict requirement to fluctuation of built curve from initial vertices. 2018-08-23 12:03:33 +03:00
msv
3874482c60 Correct the algorithm of merging edges, applying more strict requirement to planarity when creating a circle. This gives more accurate output. 2018-08-23 12:03:31 +03:00
msv
823d13e218 Implement the new class that allows merging of planar faces constituting a cylindrical surface into one face. The algorithm checks that all merged faces have smooth change of normal within the given angular tolerance.
The algorithm has front end in draw as a command combinetocylinder.
2018-08-23 12:03:30 +03:00
94 changed files with 9414 additions and 1202 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -632,6 +632,9 @@ void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation
{
aShadedGroup = Prs3d_Root::NewGroup (thePrs);
aShadedGroup->SetClosed (isClosed);
if (isClosed
&& !myCappingStyle.IsNull())
aShadedGroup->SetGroupPrimitivesAspect (myCappingStyle);
}
aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect());
aShadedGroup->AddPrimitiveArray (aTriangles);

View File

@@ -21,6 +21,7 @@
#include <Aspect_PolygonOffsetMode.hxx>
#include <Bnd_Box.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_AspectFillCapping.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_AspectMarker3d.hxx>
#include <Graphic3d_AspectText3d.hxx>
@@ -277,6 +278,37 @@ void AIS_InteractiveObject::UnsetMaterial()
hasOwnMaterial = Standard_False;
}
//=======================================================================
//function : SetCappingStyle
//purpose :
//=======================================================================
void AIS_InteractiveObject::SetCappingStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle)
{
myCappingStyle = theStyle;
// Modify existing presentations
for (Standard_Integer aPrsIter = 1, n = myPresentations.Length(); aPrsIter <= n; ++aPrsIter)
{
const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter).Presentation();
if (!aPrs3d.IsNull())
{
const Handle(Graphic3d_Structure)& aStruct = aPrs3d->Presentation();
if (!aStruct.IsNull())
{
const Graphic3d_SequenceOfGroup& aGroups = aStruct->Groups();
for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next())
{
Handle(Graphic3d_Group)& aGrp = aGroupIter.ChangeValue();
if (aGrp.IsNull())
continue;
aGrp->SetGroupPrimitivesAspect (theStyle);
}
}
}
}
}
//=======================================================================
//function : SetTransparency
//purpose :
@@ -621,10 +653,11 @@ void AIS_InteractiveObject::SynchronizeAspects()
continue;
}
Handle(Graphic3d_AspectLine3d) aLineAspect = aGrp->LineAspect();
Handle(Graphic3d_AspectFillArea3d) aFaceAspect = aGrp->FillAreaAspect();
Handle(Graphic3d_AspectMarker3d) aMarkerAspect = aGrp->MarkerAspect();
Handle(Graphic3d_AspectText3d) aTextAspect = aGrp->TextAspect();
Handle(Graphic3d_AspectLine3d) aLineAspect = aGrp->LineAspect();
Handle(Graphic3d_AspectFillArea3d) aFaceAspect = aGrp->FillAreaAspect();
Handle(Graphic3d_AspectFillCapping) aCappingAspect = aGrp->FillCappingAspect();
Handle(Graphic3d_AspectMarker3d) aMarkerAspect = aGrp->MarkerAspect();
Handle(Graphic3d_AspectText3d) aTextAspect = aGrp->TextAspect();
if (!aLineAspect.IsNull())
{
aGrp->SetGroupPrimitivesAspect (aLineAspect);
@@ -633,6 +666,10 @@ void AIS_InteractiveObject::SynchronizeAspects()
{
aGrp->SetGroupPrimitivesAspect (aFaceAspect);
}
if (!aCappingAspect.IsNull())
{
aGrp->SetGroupPrimitivesAspect (aCappingAspect);
}
if (!aMarkerAspect.IsNull())
{
aGrp->SetGroupPrimitivesAspect (aMarkerAspect);
@@ -641,6 +678,7 @@ void AIS_InteractiveObject::SynchronizeAspects()
{
aGrp->SetGroupPrimitivesAspect (aTextAspect);
}
}
}
}

View File

@@ -310,6 +310,12 @@ public:
//! Removes the setting for material.
Standard_EXPORT virtual void UnsetMaterial();
//! Set style of filling capping section created by clipping planes.
Standard_EXPORT virtual void SetCappingStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle);
//! Returns style for filling capping section created by clipping planes.
const Handle(Graphic3d_AspectFillCapping)& CappingStyle() const { return myCappingStyle; }
//! Attributes a setting aValue for transparency.
//! The transparency value should be between 0.0 and 1.0.
//! At 0.0 an object will be totally opaque, and at 1.0, fully transparent.
@@ -416,7 +422,7 @@ protected:
Standard_Boolean hasOwnColor;
Standard_Boolean hasOwnMaterial;
Standard_Boolean myRecomputeEveryPrs;
Handle(Graphic3d_AspectFillCapping) myCappingStyle;
};
DEFINE_STANDARD_HANDLE(AIS_InteractiveObject, SelectMgr_SelectableObject)

View File

@@ -161,10 +161,7 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
try
{
OCC_CATCH_SIGNALS
StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer,
myDrawer->ShadingAspect()->Aspect()->ToMapTexture()
&& !myDrawer->ShadingAspect()->Aspect()->TextureMap().IsNull(),
myUVOrigin, myUVRepeat, myUVScale);
StdPrs_ShadedShape::Add (aPrs, myshape, myDrawer, myCappingStyle);
}
catch (Standard_Failure const& anException)
{

2104
src/AIS/AIS_ViewCube.cxx Normal file

File diff suppressed because it is too large Load Diff

1059
src/AIS/AIS_ViewCube.hxx Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -181,3 +181,5 @@ AIS_TypeOfAxis.hxx
AIS_TypeOfDist.hxx
AIS_TypeOfIso.hxx
AIS_TypeOfPlane.hxx
AIS_ViewCube.hxx
AIS_ViewCube.cxx

View File

@@ -34,6 +34,9 @@ class BinMXCAFDoc_GeomToleranceDriver;
class BinMXCAFDoc_DimensionDriver;
class BinMXCAFDoc_DimTolDriver;
class BinMXCAFDoc_MaterialDriver;
class BinMXCAFDoc_NoteCommentDriver;
class BinMXCAFDoc_NoteBinDataDriver;
class BinMXCAFDoc_NotesToolDriver;
class BinMXCAFDoc_ColorToolDriver;
class BinMXCAFDoc_DocumentToolDriver;
class BinMXCAFDoc_LayerToolDriver;
@@ -42,6 +45,9 @@ class BinMXCAFDoc_DimTolToolDriver;
class BinMXCAFDoc_MaterialToolDriver;
class BinMXCAFDoc_ViewDriver;
class BinMXCAFDoc_ViewToolDriver;
class BinMXCAFDoc_AnimationDriver;
class BinMXCAFDoc_AnimationToolDriver;
@@ -89,6 +95,9 @@ friend class BinMXCAFDoc_DimTolToolDriver;
friend class BinMXCAFDoc_MaterialToolDriver;
friend class BinMXCAFDoc_ViewDriver;
friend class BinMXCAFDoc_ViewToolDriver;
friend class BinMXCAFDoc_AnimationDriver;
friend class BinMXCAFDoc_AnimationToolDriver;
};

View File

@@ -0,0 +1,111 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 <BinMXCAFDoc_AnimationDriver.hxx>
#include <BinObjMgt_Persistent.hxx>
#include <Message_Messenger.hxx>
#include <Standard_Type.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TDF_Attribute.hxx>
#include <XCAFDoc_Animation.hxx>
# include <TColStd_HArray1OfByte.hxx>
IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_AnimationDriver,BinMDF_ADriver)
static Standard_Boolean getByteArray(const BinObjMgt_Persistent& theSource, Handle(TColStd_HArray1OfByte)& theArray)
{
Standard_Integer aFirstInd, aLastInd;
if (!(theSource >> aFirstInd >> aLastInd))
return Standard_False;
if (aLastInd < aFirstInd)
return Standard_False;
theArray.reset(new TColStd_HArray1OfByte(aFirstInd, aLastInd - aFirstInd + 1));
theSource.GetByteArray(&theArray->ChangeFirst(), aLastInd - aFirstInd + 1);
return Standard_True;
}
static void putByteArray(BinObjMgt_Persistent& theTarget, const Handle(TColStd_HArray1OfByte)& theArray)
{
if (theArray.IsNull())
return;
const Standard_Integer aFirstInd = theArray->Lower();
const Standard_Integer aLastInd = theArray->Upper();
if (aLastInd < aFirstInd)
return;
theTarget << aFirstInd << aLastInd;
theTarget.PutByteArray(&theArray->ChangeFirst(), aLastInd - aFirstInd + 1);
}
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
BinMXCAFDoc_AnimationDriver::BinMXCAFDoc_AnimationDriver
(const Handle(Message_Messenger)& theMsgDriver)
: BinMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_Animation)->Name())
{
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) BinMXCAFDoc_AnimationDriver::NewEmpty() const
{
return new XCAFDoc_Animation();
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
Standard_Boolean BinMXCAFDoc_AnimationDriver::Paste(const BinObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
BinObjMgt_RRelocationTable& /*theRelocTable*/) const
{
Handle(XCAFDoc_Animation) anAtt = Handle(XCAFDoc_Animation)::DownCast(theTarget);
TCollection_AsciiString aName;
if (!(theSource >> aName))
return Standard_False;
Handle(TColStd_HArray1OfByte) anImage, anAnimation;
if (!getByteArray(theSource, anImage) || anImage.IsNull())
return Standard_False;
if (!getByteArray(theSource, anAnimation) || anAnimation.IsNull())
return Standard_False;
anAtt->Set(new TCollection_HAsciiString(aName), anImage, anAnimation);
return Standard_True;
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void BinMXCAFDoc_AnimationDriver::Paste(const Handle(TDF_Attribute)& theSource,
BinObjMgt_Persistent& theTarget,
BinObjMgt_SRelocationTable& /*theRelocTable*/) const
{
Handle(XCAFDoc_Animation) anAtt = Handle(XCAFDoc_Animation)::DownCast(theSource);
Handle(TCollection_HAsciiString) aName = anAtt->GetName();
if (!aName.IsNull())
theTarget << aName->String();
putByteArray(theTarget, anAtt->GetImage());
putByteArray(theTarget, anAtt->GetAnimation());
}

View File

@@ -0,0 +1,72 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 _BinMXCAFDoc_AnimationDriver_HeaderFile
#define _BinMXCAFDoc_AnimationDriver_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <BinMDF_ADriver.hxx>
#include <Standard_Boolean.hxx>
#include <BinObjMgt_RRelocationTable.hxx>
#include <BinObjMgt_SRelocationTable.hxx>
class Message_Messenger;
class TDF_Attribute;
class BinObjMgt_Persistent;
class BinMXCAFDoc_AnimationDriver;
DEFINE_STANDARD_HANDLE(BinMXCAFDoc_AnimationDriver, BinMDF_ADriver)
class BinMXCAFDoc_AnimationDriver : public BinMDF_ADriver
{
public:
Standard_EXPORT BinMXCAFDoc_AnimationDriver(const Handle(Message_Messenger)& theMsgDriver);
Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean Paste (const BinObjMgt_Persistent& theSource, const Handle(TDF_Attribute)& theTarget, BinObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE;
Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& theSource, BinObjMgt_Persistent& theTarget, BinObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_AnimationDriver,BinMDF_ADriver)
protected:
private:
};
#endif // _BinMXCAFDoc_AnimationDriver_HeaderFile

View File

@@ -0,0 +1,65 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 <BinMXCAFDoc_AnimationToolDriver.hxx>
#include <BinObjMgt_Persistent.hxx>
#include <Message_Messenger.hxx>
#include <Standard_Type.hxx>
#include <TDF_Attribute.hxx>
#include <XCAFDoc_AnimationTool.hxx>
IMPLEMENT_STANDARD_RTTIEXT(BinMXCAFDoc_AnimationToolDriver, BinMDF_ADriver)
//=======================================================================
//function :
//purpose :
//=======================================================================
BinMXCAFDoc_AnimationToolDriver::BinMXCAFDoc_AnimationToolDriver
(const Handle(Message_Messenger)& theMsgDriver)
: BinMDF_ADriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_AnimationTool)->Name())
{
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Handle(TDF_Attribute) BinMXCAFDoc_AnimationToolDriver::NewEmpty() const
{
return new XCAFDoc_AnimationTool();
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Standard_Boolean BinMXCAFDoc_AnimationToolDriver::Paste
(const BinObjMgt_Persistent& /*theSource*/,
const Handle(TDF_Attribute)& /*theTarget*/,
BinObjMgt_RRelocationTable& /*theRelocTable*/) const
{
return Standard_True;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
void BinMXCAFDoc_AnimationToolDriver::Paste
(const Handle(TDF_Attribute)& /*theSource*/,
BinObjMgt_Persistent& /*theTarget*/,
BinObjMgt_SRelocationTable& /*theRelocTable*/) const {
}

View File

@@ -0,0 +1,50 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 _BinMXCAFDoc_AnimationToolDriver_HeaderFile
#define _BinMXCAFDoc_AnimationToolDriver_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <BinMDF_ADriver.hxx>
#include <Standard_Boolean.hxx>
#include <BinObjMgt_RRelocationTable.hxx>
#include <BinObjMgt_SRelocationTable.hxx>
class Message_Messenger;
class TDF_Attribute;
class BinObjMgt_Persistent;
class BinMXCAFDoc_AnimationToolDriver;
DEFINE_STANDARD_HANDLE(BinMXCAFDoc_AnimationToolDriver, BinMDF_ADriver)
class BinMXCAFDoc_AnimationToolDriver : public BinMDF_ADriver
{
public:
Standard_EXPORT BinMXCAFDoc_AnimationToolDriver(const Handle(Message_Messenger)& theMsgDriver);
Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean Paste(const BinObjMgt_Persistent& theSource, const Handle(TDF_Attribute)& theTarget, BinObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE;
Standard_EXPORT virtual void Paste(const Handle(TDF_Attribute)& theSource, BinObjMgt_Persistent& theTarget, BinObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(BinMXCAFDoc_AnimationToolDriver, BinMDF_ADriver)
};
#endif // _BinMXCAFDoc_AnimationToolDriver_HeaderFile

View File

@@ -53,3 +53,7 @@ BinMXCAFDoc_ViewToolDriver.cxx
BinMXCAFDoc_ViewToolDriver.hxx
BinMXCAFDoc_VolumeDriver.cxx
BinMXCAFDoc_VolumeDriver.hxx
BinMXCAFDoc_AnimationDriver.cxx
BinMXCAFDoc_AnimationDriver.hxx
BinMXCAFDoc_AnimationToolDriver.cxx
BinMXCAFDoc_AnimationToolDriver.hxx

View File

@@ -74,8 +74,8 @@ static Standard_OStream& operator <<(Standard_OStream& OS, const gp_Pnt P)
//purpose :
//=======================================================================
BinTools_ShapeSet::BinTools_ShapeSet(const Standard_Boolean isWithTriangles)
:myFormatNb(3), myWithTriangles(isWithTriangles)
BinTools_ShapeSet::BinTools_ShapeSet(const Standard_Boolean /*isWithTriangles*/)
:myFormatNb(3), myWithTriangles(Standard_True/*isWithTriangles*/)
{}
//=======================================================================
@@ -517,6 +517,12 @@ void BinTools_ShapeSet::Read(TopoDS_Shape& S, Standard_IStream& IS,
anOrient = (TopAbs_Orientation)aChar;
Standard_Integer anIndx;
BinTools::GetInteger(IS, anIndx);
Standard_Integer anInd = nbshapes - anIndx + 1;
if (anInd < 1 || anInd > myShapes.Extent())
{
S = TopoDS_Shape();
return;
}
S = myShapes(nbshapes - anIndx + 1);
S.Orientation(anOrient);

View File

@@ -95,6 +95,8 @@ Standard_Integer BinTools_SurfaceSet::Add(const Handle(Geom_Surface)& S)
Handle(Geom_Surface) BinTools_SurfaceSet::Surface
(const Standard_Integer I)const
{
if (I < 1 || I > myMap.Extent())
return Handle(Geom_Surface)();
return Handle(Geom_Surface)::DownCast(myMap(I));
}

View File

@@ -12,6 +12,8 @@ Graphic3d_ArrayOfTriangles.hxx
Graphic3d_ArrayOfTriangleStrips.hxx
Graphic3d_AspectFillArea3d.cxx
Graphic3d_AspectFillArea3d.hxx
Graphic3d_AspectFillCapping.cxx
Graphic3d_AspectFillCapping.hxx
Graphic3d_AspectLine3d.cxx
Graphic3d_AspectLine3d.hxx
Graphic3d_AspectMarker3d.cxx
@@ -30,7 +32,6 @@ Graphic3d_BufferType.hxx
Graphic3d_Camera.cxx
Graphic3d_Camera.hxx
Graphic3d_CameraTile.hxx
Graphic3d_CappingFlags.hxx
Graphic3d_CLight.cxx
Graphic3d_CLight.hxx
Graphic3d_ClipPlane.cxx

View File

@@ -0,0 +1,110 @@
// Created on: 2017-04-14
// Created by: Anton POLETAEV
// Copyright (c) 2017 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 <Graphic3d_AspectFillCapping.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_AspectFillCapping, Standard_Transient)
// =======================================================================
// function : Graphic3d_AspectFillCapping
// purpose :
// =======================================================================
Graphic3d_AspectFillCapping::Graphic3d_AspectFillCapping()
: myFlags (Flags_None),
myHatchingState (0)
{
Graphic3d_MaterialAspect aMaterial;
aMaterial.SetColor (Quantity_NOC_BLACK);
aMaterial.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
aMaterial.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
aMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
aMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
aMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT);
SetHatchStyle (Aspect_HS_HORIZONTAL);
SetHatchMaterial (aMaterial);
}
// =======================================================================
// function : SetHatchStyle
// purpose :
// =======================================================================
void Graphic3d_AspectFillCapping::SetHatchStyle (const Aspect_HatchStyle theStyle)
{
myStippleHatch = new Graphic3d_HatchStyle (theStyle);
myTextureHatch.Nullify();
myHatchingState++;
}
// =======================================================================
// function : SetHatchStyle
// purpose :
// =======================================================================
void Graphic3d_AspectFillCapping::SetHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle)
{
myStippleHatch = theStyle;
myTextureHatch.Nullify();
myHatchingState++;
}
// =======================================================================
// function : SetHatchStyle
// purpose :
// =======================================================================
void Graphic3d_AspectFillCapping::SetHatchStyle (const Handle(Graphic3d_TextureMap)& theTexture)
{
myStippleHatch.Nullify();
myTextureHatch = theTexture;
myHatchingState++;
}
// =======================================================================
// function : SetHatchMaterial
// purpose :
// =======================================================================
void Graphic3d_AspectFillCapping::SetHatchMaterial (const Graphic3d_MaterialAspect& theMaterial)
{
myHatchMaterial = theMaterial;
myHatchingState++;
}
// =======================================================================
// function : SetToDrawHatch
// purpose :
// =======================================================================
void Graphic3d_AspectFillCapping::SetToDrawHatch (const Standard_Boolean theToDraw)
{
setFlag (theToDraw, Flags_DrawHatching);
myHatchingState++;
}
// =======================================================================
// function : SetHatchZoomPeristent
// purpose :
// =======================================================================
void Graphic3d_AspectFillCapping::SetHatchZoomPeristent (const Standard_Boolean theToSet)
{
setFlag (theToSet, Flags_HatchZoomPersistent);
myHatchingState++;
}
// =======================================================================
// function : SetHatchRotationPeristent
// purpose :
// =======================================================================
void Graphic3d_AspectFillCapping::SetHatchRotationPeristent (const Standard_Boolean theToSet)
{
setFlag (theToSet, Flags_HatchRotationPersistent);
myHatchingState++;
}

View File

@@ -0,0 +1,163 @@
// Created on: 2017-04-14
// Created by: Anton POLETAEV
// Copyright (c) 2017 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 _Graphic3d_AspectFillCapping_HeaderFile
#define _Graphic3d_AspectFillCapping_HeaderFile
#include <Aspect_HatchStyle.hxx>
#include <Graphic3d_HatchStyle.hxx>
#include <Graphic3d_MaterialAspect.hxx>
#include <Graphic3d_ShaderProgram.hxx>
#include <Graphic3d_TextureMap.hxx>
#include <Standard_Transient.hxx>
//! Defines graphical attributes for drawing section planes on solids resulted from clipping (cutting) planes.
class Graphic3d_AspectFillCapping : public Standard_Transient
{
public:
//! Default constructor.
Standard_EXPORT Graphic3d_AspectFillCapping();
public:
//! Sets material for filling section created by clipping.
void SetMaterial (const Graphic3d_MaterialAspect& theMaterial) { myMaterial = theMaterial; }
//! Returns material for filling section created by clipping.
const Graphic3d_MaterialAspect& Material() const { return myMaterial; }
//! Sets flag indicating whether object's material (instead of defined by this aspect) should be used for filling section.
void SetUseObjectMaterial (const Standard_Boolean theToUse) { setFlag (theToUse, Flags_UseObjectMaterial); }
//! Returns flag indicating whether object's material (instead of defined by this aspect) should be used for filling section.
Standard_Boolean ToUseObjectMaterial() const { return (myFlags & Flags_UseObjectMaterial) != 0; }
//! Sets texture for filling section created by clipping.
void SetTexture (const Handle(Graphic3d_TextureMap)& theTexture) { myTexture = theTexture; }
//! Returns texture for filling section created by clipping.
const Handle(Graphic3d_TextureMap)& Texture() const { return myTexture; }
//! Sets flag indicating whether object's texture (instead of defined by this aspect) should be used for filling section.
void SetUseObjectTexture (const Standard_Boolean theToUse) { setFlag (theToUse, Flags_UseObjectTexture); }
//! Returns flag indicating whether object's texture (instead of defined by this aspect) should be used for filling section.
Standard_Boolean ToUseObjectTexture() const { return (myFlags & Flags_UseObjectTexture) != 0; }
//! Sets OpenGL/GLSL shader program.
void SetShader (const Handle(Graphic3d_ShaderProgram)& theShader) { myShader = theShader; }
//! Returns OpenGL/GLSL shader program.
const Handle(Graphic3d_ShaderProgram)& Shader() const { return myShader; }
//! Sets flag indicating whether object's shader (instead of defined by this aspect) should be used for filling section.
void SetUseObjectShader (const Standard_Boolean theToUse) { setFlag (theToUse, Flags_UseObjectShader); }
//! Returns flag indicating whether object's shader (instead of defined by this aspect) should be used for filling section.
Standard_Boolean ToUseObjectShader() const { return (myFlags & Flags_UseObjectShader) != 0; }
public:
//! Sets style of hatch defined by predefined stipple mask.
Standard_EXPORT void SetHatchStyle (const Aspect_HatchStyle theStyle);
//! Sets style of hatch defined by custom stipple mask.
Standard_EXPORT void SetHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle);
//! Sets style of hatch defined by texture map (decal texture with alpha channel should be used).
Standard_EXPORT void SetHatchStyle (const Handle(Graphic3d_TextureMap)& theTexture);
//! Sets material style for hatch lines (texture).
Standard_EXPORT void SetHatchMaterial (const Graphic3d_MaterialAspect& theMaterial);
//! Returns material style for hatch lines (texture).
const Graphic3d_MaterialAspect& HatchMaterial() const { return myHatchMaterial; }
//! Sets boolean flag indicating whether the hatch layer should be drawn or not.
Standard_EXPORT void SetToDrawHatch (const Standard_Boolean theToDraw);
//! Returns boolean flag indicating whether the hatch layer should be drawn or not.
Standard_Boolean ToDrawHatch() const { return (myFlags & Flags_DrawHatching) != 0; }
//! Sets flag controlling behavior of hatch texture mapping on zooming.
//! @param theToSet [in] if passed TRUE the texture will keep constant screen-scale independent of zooming.
Standard_EXPORT void SetHatchZoomPeristent (const Standard_Boolean theToSet);
//! Returns value of flag controlling behavior of hatch texture mapping on zooming.
Standard_Boolean IsHatchZoomPersistent() { return (myFlags & Flags_HatchZoomPersistent) != 0; }
//! Sets flag controlling behavior of hatch texture mapping on camera rotation around heading vector.
Standard_EXPORT void SetHatchRotationPeristent (const Standard_Boolean theToSet);
//! Returns value of flag controlling behavior of hatch texture mapping on camera rotation around heading vector.
Standard_Boolean IsHatchRotationPersistent() { return (myFlags & Flags_HatchRotationPersistent) != 0; }
//! Returns true if hatch is defined by texture.
Standard_Boolean IsTextureHatch() const { return !myTextureHatch.IsNull(); }
//! Returns texture map defining the hatch.
const Handle(Graphic3d_TextureMap)& TextureHatch() const { return myTextureHatch; }
//! Returns true if hatch is defined by stipple mask.
Standard_Boolean IsStippleHatch() const { return !myStippleHatch.IsNull(); }
//! Returns the stipple mask.
const Handle(Graphic3d_HatchStyle)& StippleHatch() const { return myStippleHatch; }
//! Returns modification counter for hatching state.
Standard_Size HatchingState() const { return myHatchingState; }
private:
enum Flags
{
Flags_None = 0x00, //!< no flags
Flags_UseObjectMaterial = 0x01, //!< use object material
Flags_UseObjectTexture = 0x02, //!< use object texture
Flags_UseObjectShader = 0x04, //!< use object GLSL program
Flags_HatchZoomPersistent = 0x08, //!< zoom-persistent texturing
Flags_HatchRotationPersistent = 0x10, //!< rotation-persistent texturing
Flags_DrawHatching = 0x20, //!< draw hatching
Flags_UseObjectProperties = //!< use entire fill area aspect from object
Flags_UseObjectMaterial
| Flags_UseObjectTexture
| Flags_UseObjectShader
};
void setFlag (const Standard_Boolean theToUse, const unsigned int theFlag)
{
myFlags = theToUse ? myFlags | theFlag : myFlags & ~theFlag;
}
private:
Graphic3d_MaterialAspect myMaterial;
Handle(Graphic3d_TextureMap) myTexture;
Handle(Graphic3d_ShaderProgram) myShader;
Handle(Graphic3d_HatchStyle) myStippleHatch;
Handle(Graphic3d_TextureMap) myTextureHatch;
Graphic3d_MaterialAspect myHatchMaterial;
unsigned int myFlags;
Standard_Size myHatchingState;
public:
DEFINE_STANDARD_RTTIEXT(Graphic3d_AspectFillCapping, Standard_Transient)
};
DEFINE_STANDARD_HANDLE (Graphic3d_AspectFillCapping, Standard_Transient)
#endif // _Graphic3d_AspectFillCapping_HeaderFile

View File

@@ -1,29 +0,0 @@
// Created on: 2016-08-04
// Copyright (c) 2016 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 _Graphic3d_CappingFlags_HeaderFile
#define _Graphic3d_CappingFlags_HeaderFile
//! Enumeration of capping flags.
enum Graphic3d_CappingFlags
{
Graphic3d_CappingFlags_None = 0x0000, //!< no flags
Graphic3d_CappingFlags_ObjectMaterial = 0x0001, //!< use object material
Graphic3d_CappingFlags_ObjectTexture = 0x0002, //!< use object texture
Graphic3d_CappingFlags_ObjectShader = 0x0008, //!< use object GLSL program
Graphic3d_CappingFlags_ObjectAspect =
Graphic3d_CappingFlags_ObjectMaterial | Graphic3d_CappingFlags_ObjectTexture | Graphic3d_CappingFlags_ObjectShader //!< use entire fill area aspect from object
};
#endif // _Graphic3d_CappingFlags_HeaderFile

View File

@@ -19,24 +19,11 @@
#include <gp_Pln.hxx>
#include <Standard_Atomic.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient)
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ClipPlane, Standard_Transient)
namespace
{
static volatile Standard_Integer THE_CLIP_PLANE_COUNTER = 0;
static Handle(Graphic3d_AspectFillArea3d) defaultAspect()
{
const Graphic3d_MaterialAspect aMaterial (Graphic3d_NOM_DEFAULT);
Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
anAspect->SetDistinguishOff();
anAspect->SetFrontMaterial (aMaterial);
anAspect->SetHatchStyle (Aspect_HS_HORIZONTAL);
anAspect->SetInteriorStyle (Aspect_IS_SOLID);
anAspect->SetInteriorColor (aMaterial.Color());
anAspect->SetSuppressBackFaces (false);
return anAspect;
}
}
// =======================================================================
@@ -44,69 +31,40 @@ namespace
// purpose :
// =======================================================================
Graphic3d_ClipPlane::Graphic3d_ClipPlane()
: myAspect (defaultAspect()),
myPlane (0.0, 0.0, 1.0, 0.0),
myEquation (0.0, 0.0, 1.0, 0.0),
myFlags (Graphic3d_CappingFlags_None),
myEquationMod(0),
myAspectMod (0),
myIsOn (Standard_True),
myIsCapping (Standard_False)
{
makeId();
init();
}
// =======================================================================
// function : Graphic3d_ClipPlane
// purpose :
// =======================================================================
Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Equation& theEquation)
: myAspect (defaultAspect()),
myPlane (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w()),
myEquation (theEquation),
myFlags (Graphic3d_CappingFlags_None),
myEquationMod(0),
myAspectMod (0),
myIsOn (Standard_True),
myIsCapping (Standard_False)
Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Equation& theEquation)
{
makeId();
init (gp_Pln (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.a()));
}
// =======================================================================
// function : Graphic3d_ClipPlane
// purpose :
// =======================================================================
Graphic3d_ClipPlane::Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther)
: Standard_Transient(theOther),
myAspect (defaultAspect()),
myPlane (theOther.myPlane),
myEquation (theOther.myEquation),
myFlags (theOther.myFlags),
myEquationMod(0),
myAspectMod (0),
myIsOn (theOther.myIsOn),
myIsCapping (theOther.myIsCapping)
Graphic3d_ClipPlane::Graphic3d_ClipPlane (const Graphic3d_ClipPlane& theOther)
: Standard_Transient (theOther)
{
makeId();
*myAspect = *theOther.CappingAspect();
init (theOther.myPlane,
theOther.myIsOn,
theOther.myIsCapping,
theOther.ToOverrideCappingAspect(),
theOther.CappingSectionStyle());
}
// =======================================================================
// function : Graphic3d_ClipPlane
// purpose :
// =======================================================================
Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane)
: myAspect (defaultAspect()),
myPlane (thePlane),
myFlags (Graphic3d_CappingFlags_None),
myEquationMod(0),
myAspectMod (0),
myIsOn (Standard_True),
myIsCapping (Standard_False)
Graphic3d_ClipPlane::Graphic3d_ClipPlane (const gp_Pln& thePlane)
{
thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]);
makeId();
init (thePlane);
}
// =======================================================================
@@ -115,23 +73,20 @@ Graphic3d_ClipPlane::Graphic3d_ClipPlane(const gp_Pln& thePlane)
// =======================================================================
void Graphic3d_ClipPlane::SetEquation (const Equation& theEquation)
{
myPlane = gp_Pln (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w());
myEquation = theEquation;
myEquationMod++;
myPlane = gp_Pln (theEquation.x(), theEquation.y(), theEquation.z(), theEquation.w());
myEquation = theEquation;
myOrientationDirty = Standard_True;
}
// =======================================================================
// function : SetPlane
// function : SetEquation
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::SetEquation (const gp_Pln& thePlane)
{
myPlane = thePlane;
thePlane.Coefficients (myEquation[0],
myEquation[1],
myEquation[2],
myEquation[3]);
myEquationMod++;
thePlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]);
myOrientationDirty = Standard_True;
}
// =======================================================================
@@ -162,117 +117,100 @@ Handle(Graphic3d_ClipPlane) Graphic3d_ClipPlane::Clone() const
}
// =======================================================================
// function : SetCappingMaterial
// function : SetCappingSectionStyle
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::SetCappingMaterial (const Graphic3d_MaterialAspect& theMat)
void Graphic3d_ClipPlane::SetCappingSectionStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle)
{
myAspect->SetFrontMaterial (theMat);
myAspect->SetInteriorColor (theMat.Color());
++myAspectMod;
mySectionStyle = theStyle;
}
// =======================================================================
// function : SetCappingTexture
// function : OrientationMatrix
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture)
const Graphic3d_Mat4& Graphic3d_ClipPlane::OrientationMatrix() const
{
if (!theTexture.IsNull())
if (myOrientationDirty)
{
myAspect->SetTextureMapOn();
Handle(Graphic3d_TextureSet) aTextureSet = myAspect->TextureSet();
if (aTextureSet.IsNull() || aTextureSet->Size() != 1)
const Standard_ShortReal aDirection[] = {
static_cast<Standard_ShortReal> (myEquation[0]),
static_cast<Standard_ShortReal> (myEquation[1]),
static_cast<Standard_ShortReal> (myEquation[2])
};
const Standard_ShortReal aTranslate[] = {
static_cast<Standard_ShortReal> (myEquation[0] * -myEquation[3]),
static_cast<Standard_ShortReal> (myEquation[1] * -myEquation[3]),
static_cast<Standard_ShortReal> (myEquation[2] * -myEquation[3])
};
Standard_ShortReal aSide1[] = { 0.0f, 0.0f, 0.0f };
Standard_ShortReal aSide2[] = { 0.0f, 0.0f, 0.0f };
const Standard_ShortReal aMagintude = static_cast<Standard_ShortReal> (Sqrt (myEquation[0] * myEquation[0] + myEquation[2] * myEquation[2]));
if (aMagintude < ShortRealSmall())
{
aTextureSet = new Graphic3d_TextureSet (theTexture);
aSide1[0] = 1.0f;
}
else
{
aTextureSet->SetFirst (theTexture);
aSide1[0] = aDirection[2] / aMagintude;
aSide1[2] = -aDirection[0] / aMagintude;
}
myAspect->SetTextureSet (aTextureSet);
aSide2[0] = (-aSide1[1] * aDirection[2]) - (-aSide1[2] * aDirection[1]);
aSide2[1] = (-aSide1[2] * aDirection[0]) - (-aSide1[0] * aDirection[2]);
aSide2[2] = (-aSide1[0] * aDirection[1]) - (-aSide1[1] * aDirection[0]);
myOrientationMat.SetValue (0, 0, aSide1[0]);
myOrientationMat.SetValue (1, 0, aSide1[1]);
myOrientationMat.SetValue (2, 0, aSide1[2]);
myOrientationMat.SetValue (3, 0, 0.0F);
myOrientationMat.SetValue (0, 1, aDirection[0]);
myOrientationMat.SetValue (1, 1, aDirection[1]);
myOrientationMat.SetValue (2, 1, aDirection[2]);
myOrientationMat.SetValue (3, 1, 0.0F);
myOrientationMat.SetValue (0, 2, aSide2[0]);
myOrientationMat.SetValue (1, 2, aSide2[1]);
myOrientationMat.SetValue (2, 2, aSide2[2]);
myOrientationMat.SetValue (3, 2, 0.0F);
myOrientationMat.SetValue (0, 3, aTranslate[0]);
myOrientationMat.SetValue (1, 3, aTranslate[1]);
myOrientationMat.SetValue (2, 3, aTranslate[2]);
myOrientationMat.SetValue (3, 3, 1.0F);
myOrientationDirty = Standard_False;
}
else
return myOrientationMat;
}
// =======================================================================
// function : init
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::init (const gp_Pln& thePlane,
const Standard_Boolean theIsOn,
const Standard_Boolean theIsCapping,
const Standard_Boolean theOverrideStyle,
const Handle(Graphic3d_AspectFillCapping)& theStyle)
{
if (myEntityUID.IsEmpty())
{
myAspect->SetTextureMapOff();
myAspect->SetTextureSet (Handle(Graphic3d_TextureSet)());
myEntityUID = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name()
+ TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER));
}
++myAspectMod;
}
// =======================================================================
// function : SetCappingHatch
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::SetCappingHatch (const Aspect_HatchStyle theStyle)
{
myAspect->SetHatchStyle (theStyle);
++myAspectMod;
}
// =======================================================================
// function : SetCappingCustomHatch
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle)
{
myAspect->SetHatchStyle (theStyle);
++myAspectMod;
}
// =======================================================================
// function : SetCappingHatchOn
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::SetCappingHatchOn()
{
myAspect->SetInteriorStyle (Aspect_IS_HATCH);
++myAspectMod;
}
// =======================================================================
// function : SetCappingHatchOff
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::SetCappingHatchOff()
{
myAspect->SetInteriorStyle (Aspect_IS_SOLID);
++myAspectMod;
}
// =======================================================================
// function : SetCappingAspect
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect)
{
myAspect = theAspect;
++myAspectMod;
}
// =======================================================================
// function : setCappingFlag
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::setCappingFlag (bool theToUse, int theFlag)
{
if (theToUse)
{
myFlags |= theFlag;
}
else
{
myFlags &= ~(theFlag);
}
++myAspectMod;
}
// =======================================================================
// function : makeId
// purpose :
// =======================================================================
void Graphic3d_ClipPlane::makeId()
{
myId = TCollection_AsciiString ("Graphic3d_ClipPlane_") //DynamicType()->Name()
+ TCollection_AsciiString (Standard_Atomic_Increment (&THE_CLIP_PLANE_COUNTER));
myPlane = thePlane;
myPlane.Coefficients (myEquation[0], myEquation[1], myEquation[2], myEquation[3]);
myIsOn = theIsOn;
myIsCapping = theIsCapping;
myOverrideObjectStyle = theOverrideStyle;
mySectionStyle = theStyle.IsNull() ? new Graphic3d_AspectFillCapping() : theStyle;
myOrientationDirty = Standard_True;
}

View File

@@ -17,14 +17,16 @@
#define _Graphic3d_ClipPlane_HeaderFile
#include <Aspect_HatchStyle.hxx>
#include <gp_Pln.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_CappingFlags.hxx>
#include <Graphic3d_AspectFillCapping.hxx>
#include <Graphic3d_Mat4.hxx>
#include <Graphic3d_TextureMap.hxx>
#include <NCollection_Handle.hxx>
#include <NCollection_Vec4.hxx>
#include <Standard_Macro.hxx>
#include <Standard_TypeDef.hxx>
#include <Standard_Transient.hxx>
#include <Standard_TypeDef.hxx>
#include <gp_Pln.hxx>
//! Container for properties describing graphic driver clipping planes.
//! It is up to application to create instances of this class and specify its
@@ -45,6 +47,8 @@ public:
typedef NCollection_Vec4<Standard_Real> Equation;
public:
//! Default constructor.
//! Initializes clip plane container with the following properties:
//! - Equation (0.0, 0.0, 1.0, 0)
@@ -58,7 +62,7 @@ public:
//! Copy constructor.
//! @param theOther [in] the copied plane.
Standard_EXPORT Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther);
Standard_EXPORT Graphic3d_ClipPlane (const Graphic3d_ClipPlane& theOther);
//! Construct clip plane for the passed equation.
//! By default the plane is on, capping is turned off.
@@ -82,37 +86,17 @@ public:
//! Get 4-component equation vector for clipping plane.
//! @return clipping plane equation vector.
const Equation& GetEquation() const
{
return myEquation;
}
const Equation& GetEquation() const { return myEquation; }
//! Check that the clipping plane is turned on.
//! @return boolean flag indicating whether the plane is in on or off state.
Standard_Boolean IsOn() const
{
return myIsOn;
}
Standard_Boolean IsOn() const { return myIsOn; }
//! Change state of the clipping plane.
//! @param theIsOn [in] the flag specifying whether the graphic driver
//! clipping by this plane should be turned on or off.
Standard_EXPORT void SetOn(const Standard_Boolean theIsOn);
//! Change state of capping surface rendering.
//! @param theIsOn [in] the flag specifying whether the graphic driver should
//! perform rendering of capping surface produced by this plane. The graphic
//! driver produces this surface for convex graphics by means of stencil-test
//! and multi-pass rendering.
Standard_EXPORT void SetCapping(const Standard_Boolean theIsOn);
//! Check state of capping surface rendering.
//! @return true (turned on) or false depending on the state.
Standard_Boolean IsCapping() const
{
return myIsCapping;
}
//! Get geometrical definition.
//! @return geometrical definition of clipping plane
const gp_Pln& ToPlane() const { return myPlane; }
@@ -123,47 +107,6 @@ public:
//! @return new instance of clipping plane with same properties and attributes.
Standard_EXPORT virtual Handle(Graphic3d_ClipPlane) Clone() const;
public: // @name user-defined graphical attributes
//! Set material for rendering capping surface.
//! @param theMat [in] the material.
Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat);
//! @return capping material.
const Graphic3d_MaterialAspect& CappingMaterial() const { return myAspect->FrontMaterial(); }
//! Set texture to be applied on capping surface.
//! @param theTexture [in] the texture.
Standard_EXPORT void SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture);
//! @return capping texture map.
Handle(Graphic3d_TextureMap) CappingTexture() const { return !myAspect->TextureSet().IsNull() && !myAspect->TextureSet()->IsEmpty()
? myAspect->TextureSet()->First()
: Handle(Graphic3d_TextureMap)(); }
//! Set hatch style (stipple) and turn hatching on.
//! @param theStyle [in] the hatch style.
Standard_EXPORT void SetCappingHatch (const Aspect_HatchStyle theStyle);
//! @return hatching style.
Aspect_HatchStyle CappingHatch() const { return (Aspect_HatchStyle)myAspect->HatchStyle()->HatchType(); }
//! Set custom hatch style (stipple) and turn hatching on.
//! @param theStyle [in] the hatch pattern.
Standard_EXPORT void SetCappingCustomHatch (const Handle(Graphic3d_HatchStyle)& theStyle);
//! @return hatching style.
const Handle(Graphic3d_HatchStyle)& CappingCustomHatch() const { return myAspect->HatchStyle(); }
//! Turn on hatching.
Standard_EXPORT void SetCappingHatchOn();
//! Turn off hatching.
Standard_EXPORT void SetCappingHatchOff();
//! @return True if hatching mask is turned on.
Standard_Boolean IsHatchOn() const { return myAspect->InteriorStyle() == Aspect_IS_HATCH; }
//! This ID is used for managing associated resources in graphical driver.
//! The clip plane can be assigned within a range of IO which can be
//! displayed in separate OpenGl contexts. For each of the context an associated
@@ -171,81 +114,61 @@ public: // @name user-defined graphical attributes
//! The resources are stored in graphical driver for each of individual groups
//! of shared context under the clip plane identifier.
//! @return clip plane resource identifier string.
const TCollection_AsciiString& GetId() const
{
return myId;
}
const TCollection_AsciiString& GetId() const { return myEntityUID; }
public:
//! Return capping aspect.
//! @return capping surface rendering aspect.
const Handle(Graphic3d_AspectFillArea3d)& CappingAspect() const { return myAspect; }
//! Change state of capping surface rendering.
//! @param theIsOn [in] the flag specifying whether the graphic driver should
//! perform rendering of capping surface produced by this plane. The graphic
//! driver produces this surface for convex graphics by means of stencil-test
//! and multi-pass rendering.
Standard_EXPORT void SetCapping(const Standard_Boolean theIsOn);
//! Assign capping aspect.
Standard_EXPORT void SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
//! Check state of capping surface rendering.
//! @return true (turned on) or false depending on the state.
Standard_Boolean IsCapping() const { return myIsCapping; }
//! Flag indicating whether material for capping plane should be taken from object.
//! Default value: FALSE (use dedicated capping plane material).
bool ToUseObjectMaterial() const { return (myFlags & Graphic3d_CappingFlags_ObjectMaterial) != 0; }
//! Sets clipping section filling aspect.
Standard_EXPORT void SetCappingSectionStyle (const Handle(Graphic3d_AspectFillCapping)& theStyle);
//! Set flag for controlling the source of capping plane material.
void SetUseObjectMaterial (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectMaterial); }
//! Returns style used for drawing capping section.
const Handle(Graphic3d_AspectFillCapping)& CappingSectionStyle() const { return mySectionStyle; }
//! Flag indicating whether texture for capping plane should be taken from object.
//! Default value: FALSE.
bool ToUseObjectTexture() const { return (myFlags & Graphic3d_CappingFlags_ObjectTexture) != 0; }
//! Flag indicating whether section style of the plane should overrides similar property of object presentation.
//! Default value: FALSE (use dedicated presentation aspect style).
bool ToOverrideCappingAspect() const { return myOverrideObjectStyle; }
//! Set flag for controlling the source of capping plane texture.
void SetUseObjectTexture (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectTexture); }
//! Sets flag for controlling the preference of using section style between clip plane and object.
void SetToOverrideCappingAspect (const bool theToOverride) { myOverrideObjectStyle = theToOverride; }
//! Flag indicating whether shader program for capping plane should be taken from object.
//! Default value: FALSE.
bool ToUseObjectShader() const { return (myFlags & Graphic3d_CappingFlags_ObjectShader) != 0; }
//! Set flag for controlling the source of capping plane shader program.
void SetUseObjectShader(bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectShader); }
//! Return true if some fill area aspect properties should be taken from object.
bool ToUseObjectProperties() const { return myFlags != Graphic3d_CappingFlags_None; }
public: // @name modification counters
//! @return modification counter for equation.
unsigned int MCountEquation() const
{
return myEquationMod;
}
//! @return modification counter for aspect.
unsigned int MCountAspect() const
{
return myAspectMod;
}
//! Returns plane's orientation matrix.
Standard_EXPORT const Graphic3d_Mat4& OrientationMatrix() const;
private:
//! Generate unique object id for OpenGL graphic resource manager.
void makeId();
//! Set capping flag.
Standard_EXPORT void setCappingFlag (bool theToUse, int theFlag);
//! Initializes plane and makes unique identifier (UID) to differentiate clipping plane entities.
void init (const gp_Pln& thePlane = gp_Pln(),
const Standard_Boolean theIsOn = Standard_True,
const Standard_Boolean theIsCapping = Standard_False,
const Standard_Boolean theOverrideStyle = Standard_False,
const Handle(Graphic3d_AspectFillCapping)& theStyle = Handle(Graphic3d_AspectFillCapping)());
private:
Handle(Graphic3d_AspectFillArea3d) myAspect; //!< fill area aspect
TCollection_AsciiString myId; //!< resource id
gp_Pln myPlane; //!< plane definition
Equation myEquation; //!< plane equation vector
unsigned int myFlags; //!< capping flags
unsigned int myEquationMod; //!< modification counter for equation
unsigned int myAspectMod; //!< modification counter of aspect
Standard_Boolean myIsOn; //!< state of the clipping plane
Standard_Boolean myIsCapping; //!< state of graphic driver capping
TCollection_AsciiString myEntityUID; //!< Unique identifier for the plane
gp_Pln myPlane; //!< Plane definition
Equation myEquation; //!< Plane equation vector
Standard_Boolean myIsOn; //!< State of the clipping plane
Standard_Boolean myIsCapping; //!< State of graphic driver capping
Standard_Boolean myOverrideObjectStyle; //!< Flag forcing to use plane's section style rather than section style defined for object
Handle(Graphic3d_AspectFillCapping) mySectionStyle; //!< Style set for drawing capped solid section.
mutable Standard_Boolean myOrientationDirty; //!< Boolean flag indicating whether orientation matrix is dirty or not.
mutable Graphic3d_Mat4 myOrientationMat; //!< Plane orientation matrix (for visualization purposes).
public:
DEFINE_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient)
DEFINE_STANDARD_RTTIEXT (Graphic3d_ClipPlane, Standard_Transient)
};
DEFINE_STANDARD_HANDLE (Graphic3d_ClipPlane, Standard_Transient)

View File

@@ -231,10 +231,11 @@ Standard_Boolean Graphic3d_Group::IsGroupPrimitivesAspectSet (const Graphic3d_Gr
// function : GroupPrimitivesAspect
// purpose :
// =======================================================================
void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine,
const Handle(Graphic3d_AspectText3d)& theAspText,
const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine,
const Handle(Graphic3d_AspectText3d)& theAspText,
const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
const Handle(Graphic3d_AspectFillArea3d)& theAspFill,
const Handle(Graphic3d_AspectFillCapping)& theAspCapping) const
{
if (!theAspLine.IsNull())
{
@@ -271,6 +272,15 @@ void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d
*theAspFill.operator->() = *aFillAspect;
}
}
if (!theAspCapping.IsNull())
{
Handle(Graphic3d_AspectFillCapping) aCappingAspect = FillCappingAspect();
if (!aCappingAspect.IsNull())
{
*theAspCapping.operator->() = *aCappingAspect;
}
}
}
// =======================================================================

View File

@@ -17,30 +17,30 @@
#ifndef _Graphic3d_Group_HeaderFile
#define _Graphic3d_Group_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Graphic3d_BndBox4f.hxx>
#include <Standard_Boolean.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_AspectText3d.hxx>
#include <Graphic3d_AspectFillCapping.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_AspectMarker3d.hxx>
#include <Standard_Transient.hxx>
#include <Standard_Real.hxx>
#include <Standard_CString.hxx>
#include <Graphic3d_Vertex.hxx>
#include <Graphic3d_TextPath.hxx>
#include <Graphic3d_HorizontalTextAlignment.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
#include <Graphic3d_TypeOfPrimitiveArray.hxx>
#include <Graphic3d_IndexBuffer.hxx>
#include <Graphic3d_Buffer.hxx>
#include <Graphic3d_AspectText3d.hxx>
#include <Graphic3d_BndBox4f.hxx>
#include <Graphic3d_BoundBuffer.hxx>
#include <Standard_Address.hxx>
#include <Graphic3d_Buffer.hxx>
#include <Graphic3d_GroupAspect.hxx>
#include <gp_Ax2.hxx>
#include <Graphic3d_HorizontalTextAlignment.hxx>
#include <Graphic3d_IndexBuffer.hxx>
#include <Graphic3d_TextPath.hxx>
#include <Graphic3d_TypeOfPrimitiveArray.hxx>
#include <Graphic3d_Vertex.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
#include <MMgt_TShared.hxx>
#include <Standard.hxx>
#include <Standard_Address.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_CString.hxx>
#include <Standard_Real.hxx>
#include <Standard_Type.hxx>
#include <TCollection_ExtendedString.hxx>
#include <gp_Ax2.hxx>
class Graphic3d_Structure;
class Graphic3d_ArrayOfPrimitives;
@@ -56,7 +56,7 @@ class Graphic3d_ArrayOfPrimitives;
//! 1) Non-modifiable, or unbounded, group ('black box').
//! Developers can repeat a sequence of
//! SetPrimitivesAspect() with AddPrimitiveArray() methods arbitrary number of times
//! to define arbitrary number of primitive "blocks" each having individual apect values.
//! to define arbitrary number of primitive "blocks" each having individual aspect values.
//! Any modification of such a group is forbidden, as aspects and primitives are mixed
//! in memory without any high-level logical structure, and any modification is very likely to result
//! in corruption of the group internal data.
@@ -78,11 +78,11 @@ class Graphic3d_ArrayOfPrimitives;
class Graphic3d_Group : public Standard_Transient
{
friend class Graphic3d_Structure;
DEFINE_STANDARD_RTTIEXT(Graphic3d_Group,Standard_Transient)
DEFINE_STANDARD_RTTIEXT(Graphic3d_Group, Standard_Transient)
public:
//! Supress all primitives and attributes of <me>.
//! Suppress all primitives and attributes of <me>.
//! To clear group without update in Graphic3d_StructureManager
//! pass Standard_False as <theUpdateStructureMgr>. This
//! used on context and viewer destruction, when the pointer
@@ -91,13 +91,13 @@ public:
//! cross-reference);
Standard_EXPORT virtual void Clear (const Standard_Boolean theUpdateStructureMgr = Standard_True);
//! Supress the group <me> in the structure.
//! Suppress the group <me> in the structure.
Standard_EXPORT virtual ~Graphic3d_Group();
//! Supress the group <me> in the structure.
//! Suppress the group <me> in the structure.
//! Warning: No more graphic operations in <me> after this call.
//! Modifies the current modelling transform persistence (pan, zoom or rotate)
//! Get the current modelling transform persistence (pan, zoom or rotate)
//! Modifies the current modeling transform persistence (pan, zoom or rotate)
//! Get the current modeling transform persistence (pan, zoom or rotate)
Standard_EXPORT void Remove();
public:
@@ -126,6 +126,12 @@ public:
//! Modifies the context for all the marker primitives of the group.
virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspect) = 0;
//! Returns style of filling clipping sections on closed shell primitives.
virtual Handle(Graphic3d_AspectFillCapping) FillCappingAspect() const = 0;
//! Modifies the context for filling clipping section for all closed shell primitives of the group.
virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect) = 0;
//! Modifies the current context of the group to give
//! another aspect for all the line primitives created
//! after this call in the group.
@@ -153,15 +159,17 @@ public:
Standard_EXPORT void GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine,
const Handle(Graphic3d_AspectText3d)& theAspText,
const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const;
const Handle(Graphic3d_AspectFillArea3d)& theAspFill,
const Handle(Graphic3d_AspectFillCapping)& theAspFillCapping) const;
//! Returns the last inserted context in the group for each kind of primitives.
void PrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine,
const Handle(Graphic3d_AspectText3d)& theAspText,
const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
void PrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine,
const Handle(Graphic3d_AspectText3d)& theAspText,
const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
const Handle(Graphic3d_AspectFillArea3d)& theAspFill,
const Handle(Graphic3d_AspectFillCapping)& theAspFillCapping) const
{
GroupPrimitivesAspect (theAspLine, theAspText, theAspMarker, theAspFill);
GroupPrimitivesAspect (theAspLine, theAspText, theAspMarker, theAspFill, theAspFillCapping);
}
public:
@@ -312,6 +320,6 @@ protected:
};
DEFINE_STANDARD_HANDLE(Graphic3d_Group, Standard_Transient)
DEFINE_STANDARD_HANDLE(Graphic3d_Group, MMgt_TShared)
#endif // _Graphic3d_Group_HeaderFile

View File

@@ -21,13 +21,15 @@
//! - ASPECT_LINE: aspect for line primitives;
//! - ASPECT_TEXT: aspect for text primitives;
//! - ASPECT_MARKER: aspect for marker primitives;
//! - ASPECT_FILL_AREA: aspect for face primitives.
//! - ASPECT_FILL_AREA: aspect for face primitives;
//! - Graphic3d_ASPECT_FILL_CAPPING: aspect for filling clipping sections.
enum Graphic3d_GroupAspect
{
Graphic3d_ASPECT_LINE,
Graphic3d_ASPECT_TEXT,
Graphic3d_ASPECT_MARKER,
Graphic3d_ASPECT_FILL_AREA
Graphic3d_ASPECT_LINE,
Graphic3d_ASPECT_TEXT,
Graphic3d_ASPECT_MARKER,
Graphic3d_ASPECT_FILL_AREA,
Graphic3d_ASPECT_FILL_CAPPING
};
#endif // _Graphic3d_GroupAspect_HeaderFile

View File

@@ -291,7 +291,7 @@ public:
//! Compute per-element multiplication.
//! @param theFactor [in] the scale factor.
//! @return the result of multiplicaton.
//! @return the result of multiplication.
NCollection_Mat4 operator* (const Element_t theFactor) const
{
return Multiplied (theFactor);
@@ -299,7 +299,7 @@ public:
//! Compute per-element multiplication.
//! @param theFactor [in] the scale factor.
//! @return the result of multiplicaton.
//! @return the result of multiplication.
NCollection_Mat4 Multiplied (const Element_t theFactor) const
{
NCollection_Mat4 aTempMat (*this);

View File

@@ -7,6 +7,8 @@ OpenGl_ArbTBO.hxx
OpenGl_ArbTexBindless.hxx
OpenGl_AspectFace.cxx
OpenGl_AspectFace.hxx
OpenGl_AspectFillCapping.cxx
OpenGl_AspectFillCapping.hxx
OpenGl_AspectLine.cxx
OpenGl_AspectLine.hxx
OpenGl_AspectMarker.cxx
@@ -69,10 +71,8 @@ OpenGl_BVHClipPrimitiveTrsfPersSet.cxx
OpenGl_BVHClipPrimitiveTrsfPersSet.hxx
OpenGl_BVHTreeSelector.cxx
OpenGl_BVHTreeSelector.hxx
OpenGl_CappingAlgo.cxx
OpenGl_CappingAlgo.hxx
OpenGl_CappingPlaneResource.cxx
OpenGl_CappingPlaneResource.hxx
OpenGl_CappingRenderer.cxx
OpenGl_CappingRenderer.hxx
OpenGl_Caps.cxx
OpenGl_Caps.hxx
OpenGl_Clipping.cxx

View File

@@ -0,0 +1,247 @@
// Created on: 2017-04-14
// Created by: Anton POLETAEV
// Copyright (c) 2017 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 <OpenGl_AspectFillCapping.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_Workspace.hxx>
namespace
{
Handle(Graphic3d_AspectFillArea3d) defaultMaterial()
{
Handle(Graphic3d_AspectFillArea3d) anAspect;
const Graphic3d_MaterialAspect aMaterial (Graphic3d_NOM_DEFAULT);
anAspect = new Graphic3d_AspectFillArea3d();
anAspect->SetDistinguishOff();
anAspect->SetFrontMaterial (aMaterial);
anAspect->SetInteriorStyle (Aspect_IS_SOLID);
anAspect->SetInteriorColor (aMaterial.Color());
anAspect->SetSuppressBackFaces (false);
return anAspect;
}
}
// =======================================================================
// function : OpenGl_AspectFillCapping
// purpose :
// =======================================================================
OpenGl_AspectFillCapping::OpenGl_AspectFillCapping (const Handle(Graphic3d_AspectFillCapping)& theAspect)
: myCappingAspect (defaultMaterial()),
myHatchingAspect (defaultMaterial()),
myHatchingState (0)
{
SetAspect (theAspect);
}
// =======================================================================
// function : ~OpenGl_AspectFillCapping
// purpose :
// =======================================================================
OpenGl_AspectFillCapping::~OpenGl_AspectFillCapping()
{
//
}
// =======================================================================
// function : SetAspect
// purpose :
// =======================================================================
void OpenGl_AspectFillCapping::SetAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect)
{
myAspect = theAspect;
if (theAspect.IsNull())
{
return;
}
if (!theAspect->ToUseObjectMaterial()
|| !theAspect->ToUseObjectTexture()
|| !theAspect->ToUseObjectShader())
{
Handle(Graphic3d_AspectFillArea3d) aFillAspect = myCappingAspect.Aspect();
if (!theAspect->ToUseObjectMaterial())
{
aFillAspect->SetFrontMaterial (theAspect->Material());
aFillAspect->SetInteriorColor (theAspect->Material().Color());
}
if (!theAspect->ToUseObjectTexture())
{
aFillAspect->SetTextureMap (theAspect->Texture());
if (!theAspect->Texture().IsNull())
{
aFillAspect->SetTextureMapOn();
}
else
{
aFillAspect->SetTextureMapOff();
}
}
else
{
aFillAspect->SetTextureMap (Handle(Graphic3d_TextureMap)());
aFillAspect->SetTextureMapOff();
}
if (!theAspect->ToUseObjectShader())
{
aFillAspect->SetShaderProgram (theAspect->Shader());
}
myCappingAspect.SetAspect (aFillAspect);
}
if (theAspect->ToDrawHatch()
&& (theAspect->IsTextureHatch()
|| theAspect->IsStippleHatch()))
{
Handle(Graphic3d_AspectFillArea3d) aFillAspect = myHatchingAspect.Aspect();
aFillAspect->SetInteriorStyle (theAspect->IsStippleHatch() ? Aspect_IS_HATCH : Aspect_IS_SOLID);
aFillAspect->SetHatchStyle (theAspect->IsStippleHatch() ? theAspect->StippleHatch() : Handle(Graphic3d_HatchStyle)());
aFillAspect->SetTextureMap (theAspect->IsTextureHatch() ? theAspect->TextureHatch() : Handle(Graphic3d_TextureMap)());
aFillAspect->SetFrontMaterial (theAspect->HatchMaterial());
aFillAspect->SetInteriorColor (theAspect->HatchMaterial().Color());
if (theAspect->IsTextureHatch())
{
aFillAspect->SetTextureMapOn();
}
else
{
aFillAspect->SetTextureMapOff();
}
myHatchingAspect.SetAspect (aFillAspect);
myHatchingState = theAspect->HatchingState();
}
}
// =======================================================================
// function : Release
// purpose :
// =======================================================================
void OpenGl_AspectFillCapping::Release (OpenGl_Context* theContext)
{
myCappingAspect .Release (theContext);
myHatchingAspect.Release (theContext);
}
// =======================================================================
// function : CappingFaceAspect
// purpose :
// =======================================================================
const OpenGl_AspectFace* OpenGl_AspectFillCapping::CappingFaceAspect (const OpenGl_AspectFace* theObjectAspect) const
{
if (myAspect.IsNull())
{
return NULL;
}
Handle(Graphic3d_AspectFillArea3d) aFillAspect = myCappingAspect.Aspect();
if (myAspect->ToUseObjectMaterial() && theObjectAspect != NULL)
{
// only front material currently supported by capping rendering
aFillAspect->SetFrontMaterial (theObjectAspect->Aspect()->FrontMaterial());
aFillAspect->SetInteriorColor (theObjectAspect->Aspect()->InteriorColor());
}
else
{
aFillAspect->SetFrontMaterial (myAspect->Material());
aFillAspect->SetInteriorColor (myAspect->Material().Color());
}
if (myAspect->ToUseObjectTexture() && theObjectAspect != NULL)
{
if (theObjectAspect->Aspect()->ToMapTexture())
{
aFillAspect->SetTextureMap (theObjectAspect->Aspect()->TextureMap());
aFillAspect->SetTextureMapOn();
}
else
{
aFillAspect->SetTextureMapOff();
}
}
else
{
aFillAspect->SetTextureMap (myAspect->Texture());
if (!myAspect->Texture().IsNull())
{
aFillAspect->SetTextureMapOn();
}
else
{
aFillAspect->SetTextureMapOff();
}
}
if (myAspect->ToUseObjectShader() && theObjectAspect != NULL)
{
aFillAspect->SetShaderProgram (theObjectAspect->Aspect()->ShaderProgram());
}
else
{
aFillAspect->SetShaderProgram (myAspect->Shader());
}
myCappingAspect.SetAspect (aFillAspect);
return &myCappingAspect;
}
// =======================================================================
// function : HatchingFaceAspect
// purpose :
// =======================================================================
const OpenGl_AspectFace* OpenGl_AspectFillCapping::HatchingFaceAspect() const
{
if (myAspect.IsNull())
{
return NULL;
}
const Standard_Size aHatchingState = myAspect->HatchingState();
if (myHatchingState != aHatchingState)
{
if (myAspect->ToDrawHatch())
{
Handle(Graphic3d_AspectFillArea3d) aFillAspect = myHatchingAspect.Aspect();
aFillAspect->SetInteriorStyle (myAspect->IsStippleHatch() ? Aspect_IS_HATCH : Aspect_IS_SOLID);
aFillAspect->SetHatchStyle (myAspect->IsStippleHatch() ? myAspect->StippleHatch() : Handle(Graphic3d_HatchStyle)());
aFillAspect->SetTextureMap (myAspect->IsTextureHatch() ? myAspect->TextureHatch() : Handle(Graphic3d_TextureMap)());
aFillAspect->SetFrontMaterial (myAspect->HatchMaterial());
aFillAspect->SetInteriorColor (myAspect->HatchMaterial().Color());
if (myAspect->IsTextureHatch())
{
aFillAspect->SetTextureMapOn();
}
else
{
aFillAspect->SetTextureMapOff();
}
myHatchingAspect.SetAspect (aFillAspect);
myHatchingState = aHatchingState;
}
}
return &myHatchingAspect;
}

View File

@@ -0,0 +1,73 @@
// Created on: 2017-04-14
// Created by: Anton POLETAEV
// Copyright (c) 2017 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 _OpenGl_AspectFillCapping_Header
#define _OpenGl_AspectFillCapping_Header
#include <Graphic3d_AspectFillCapping.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_Resource.hxx>
//! Gl resource holding particular aspects for filling capping.
class OpenGl_AspectFillCapping : public OpenGl_Resource
{
public:
//! Create and assign style.
Standard_EXPORT OpenGl_AspectFillCapping (const Handle(Graphic3d_AspectFillCapping)& theAspect);
//! Destructor.
Standard_EXPORT ~OpenGl_AspectFillCapping();
//! Assign section style.
Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect);
//! Returns section style parameters.
const Handle(Graphic3d_AspectFillCapping)& Aspect() const { return myAspect; }
//! Release any allocated GL resources.
Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
//! Returns true if capping should draw hatch layer.
Standard_Boolean ToDrawHatch() const
{
return myAspect->ToDrawHatch()
&& (myAspect->IsStippleHatch()
|| myAspect->IsTextureHatch());
}
//! Returns the shading aspect for drawing face of a clipping section itself.
//! @param theObjectAspect [in] the aspect of an object if it requires combining.
Standard_EXPORT const OpenGl_AspectFace* CappingFaceAspect (const OpenGl_AspectFace* theObjectAspect) const;
//! Returns the shading aspect for drawing hatch layer of a section.
Standard_EXPORT const OpenGl_AspectFace* HatchingFaceAspect() const;
//! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
Standard_Size EstimatedDataSize() const Standard_OVERRIDE{ return 0; }
protected:
Handle(Graphic3d_AspectFillCapping) myAspect; //!< Section style settings from application's level.
mutable OpenGl_AspectFace myCappingAspect; //!< GL aspect for shading base layer of a capping section.
mutable OpenGl_AspectFace myHatchingAspect; //!< GL aspect for shading hatching layer (additional to base) of a capping section.
mutable Standard_Size myHatchingState;
public:
DEFINE_STANDARD_ALLOC
};
#endif //_OpenGl_AspectFillCapping_Header

View File

@@ -19,6 +19,7 @@
#include <Aspect_GradientFillMethod.hxx>
#include <Aspect_FillMethod.hxx>
#include <Graphic3d_TypeOfBackground.hxx>
#include <Graphic3d_TransformPers.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_PrimitiveArray.hxx>
#include <OpenGl_Vec.hxx>

View File

@@ -1,232 +0,0 @@
// Created on: 2013-09-05
// Created by: Anton POLETAEV
// Copyright (c) 2013-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 <OpenGl_CappingAlgo.hxx>
#include <OpenGl_Workspace.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_PrimitiveArray.hxx>
#include <OpenGl_CappingPlaneResource.hxx>
#include <OpenGl_Vec.hxx>
#include <OpenGl_Structure.hxx>
#include <OpenGl_ShaderManager.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_CappingAlgoFilter,OpenGl_RenderFilter)
namespace
{
//! Render infinite capping plane.
//! @param theWorkspace [in] the GL workspace, context state.
//! @param thePlane [in] the graphical plane, for which the capping surface is rendered.
static void renderPlane (const Handle(OpenGl_Workspace)& theWorkspace,
const Handle(OpenGl_CappingPlaneResource)& thePlane,
const OpenGl_AspectFace* theAspectFace)
{
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
thePlane->Update (aContext, theAspectFace != NULL ? theAspectFace->Aspect() : Handle(Graphic3d_AspectFillArea3d)());
const OpenGl_AspectFace* aFaceAspect = theWorkspace->AspectFace();
theWorkspace->SetAspectFace (thePlane->AspectFace());
// set identity model matrix
aContext->ModelWorldState.Push();
aContext->ModelWorldState.SetCurrent (OpenGl_Mat4::Map (*thePlane->Orientation()->mat));
aContext->ApplyModelViewMatrix();
thePlane->Primitives().Render (theWorkspace);
aContext->ModelWorldState.Pop();
aContext->ApplyModelViewMatrix();
theWorkspace->SetAspectFace (aFaceAspect);
}
//! Render capping for specific structure.
static void renderCappingForStructure (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Structure& theStructure,
const OpenGl_ClippingIterator& thePlaneIter,
const Handle(OpenGl_CappingPlaneResource)& thePlane)
{
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
const Handle(Graphic3d_ClipPlane)& aRenderPlane = thePlane->Plane();
for (OpenGl_Structure::GroupIterator aGroupIter (theStructure.Groups()); aGroupIter.More(); aGroupIter.Next())
{
if (!aGroupIter.Value()->IsClosed())
{
continue;
}
// enable only the rendering plane to generate stencil mask
aContext->ChangeClipping().DisableAllExcept (aContext, thePlaneIter);
aContext->ShaderManager()->UpdateClippingState();
glClear (GL_STENCIL_BUFFER_BIT);
const bool aColorMaskBack = aContext->SetColorMask (false);
// override aspects, disable culling
theWorkspace->SetAspectFace (&theWorkspace->NoneCulling());
theWorkspace->ApplyAspectFace();
// evaluate number of pair faces
if (theWorkspace->UseZBuffer())
{
glDisable (GL_DEPTH_TEST);
}
if (theWorkspace->UseDepthWrite())
{
glDepthMask (GL_FALSE);
}
glStencilFunc (GL_ALWAYS, 1, 0x01);
glStencilOp (GL_KEEP, GL_INVERT, GL_INVERT);
// render closed primitives
if (aRenderPlane->ToUseObjectProperties())
{
aGroupIter.Value()->Render (theWorkspace);
}
else
{
for (; aGroupIter.More(); aGroupIter.Next())
{
if (aGroupIter.Value()->IsClosed())
{
aGroupIter.Value()->Render (theWorkspace);
}
}
}
// override material, cull back faces
theWorkspace->SetAspectFace (&theWorkspace->FrontCulling());
theWorkspace->ApplyAspectFace();
// enable all clip plane except the rendered one
aContext->ChangeClipping().EnableAllExcept (aContext, thePlaneIter);
aContext->ShaderManager()->UpdateClippingState();
// render capping plane using the generated stencil mask
aContext->SetColorMask (aColorMaskBack);
if (theWorkspace->UseDepthWrite())
{
glDepthMask (GL_TRUE);
}
glStencilFunc (GL_EQUAL, 1, 0x01);
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
if (theWorkspace->UseZBuffer())
{
glEnable (GL_DEPTH_TEST);
}
renderPlane (theWorkspace, thePlane, aRenderPlane->ToUseObjectProperties()
? aGroupIter.Value()->AspectFace()
: NULL);
// turn on the current plane to restore initial state
aContext->ChangeClipping().SetEnabled (aContext, thePlaneIter, Standard_True);
aContext->ShaderManager()->RevertClippingState();
aContext->ShaderManager()->RevertClippingState();
}
if (theStructure.InstancedStructure() != NULL)
{
renderCappingForStructure (theWorkspace, *theStructure.InstancedStructure(), thePlaneIter, thePlane);
}
}
}
// =======================================================================
// function : RenderCapping
// purpose :
// =======================================================================
void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Structure& theStructure)
{
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
if (!aContext->Clipping().IsCappingOn())
{
// do not perform algorithm if there is nothing to render
return;
}
// remember current aspect face defined in workspace
const OpenGl_AspectFace* aFaceAsp = theWorkspace->AspectFace();
// replace primitive groups rendering filter
Handle(OpenGl_RenderFilter) aRenderFilter = theWorkspace->GetRenderFilter();
Handle(OpenGl_CappingAlgoFilter) aCappingFilter = theWorkspace->DefaultCappingAlgoFilter();
aCappingFilter->SetPreviousFilter (aRenderFilter);
theWorkspace->SetRenderFilter (aCappingFilter);
// prepare for rendering the clip planes
glEnable (GL_STENCIL_TEST);
// remember current state of depth
// function and change its value
GLint aDepthFuncPrev;
glGetIntegerv (GL_DEPTH_FUNC, &aDepthFuncPrev);
glDepthFunc (GL_LESS);
// generate capping for every clip plane
for (OpenGl_ClippingIterator aCappingIt (aContext->Clipping()); aCappingIt.More(); aCappingIt.Next())
{
// get plane being rendered
const Handle(Graphic3d_ClipPlane)& aRenderPlane = aCappingIt.Value();
if (!aRenderPlane->IsCapping()
|| aCappingIt.IsDisabled())
{
continue;
}
// get resource for the plane
const TCollection_AsciiString& aResId = aRenderPlane->GetId();
Handle(OpenGl_CappingPlaneResource) aPlaneRes;
if (!aContext->GetResource (aResId, aPlaneRes))
{
// share and register for release once the resource is no longer used
aPlaneRes = new OpenGl_CappingPlaneResource (aRenderPlane);
aContext->ShareResource (aResId, aPlaneRes);
}
renderCappingForStructure (theWorkspace, theStructure, aCappingIt, aPlaneRes);
// set delayed resource release
aPlaneRes.Nullify();
aContext->ReleaseResource (aResId, Standard_True);
}
// restore previous application state
glClear (GL_STENCIL_BUFFER_BIT);
glDepthFunc (aDepthFuncPrev);
glStencilFunc (GL_ALWAYS, 0, 0xFF);
glDisable (GL_STENCIL_TEST);
// restore rendering aspects
theWorkspace->SetAspectFace (aFaceAsp);
theWorkspace->SetRenderFilter (aRenderFilter);
}
// =======================================================================
// function : CanRender
// purpose :
// =======================================================================
Standard_Boolean OpenGl_CappingAlgoFilter::ShouldRender (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Element* theGlElement)
{
if (!myFilter.IsNull() && !myFilter->ShouldRender (theWorkspace, theGlElement))
{
return Standard_False;
}
return theGlElement->IsFillDrawMode();
}

View File

@@ -1,71 +0,0 @@
// Created on: 2013-09-05
// Created by: Anton POLETAEV
// Copyright (c) 2013-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 _OpenGl_CappingAlgo_H__
#define _OpenGl_CappingAlgo_H__
#include <OpenGl_RenderFilter.hxx>
#include <OpenGl_Group.hxx>
// Forward declaration
class OpenGl_CappingAlgoFilter;
class OpenGl_CappingPlaneResource;
class OpenGl_Structure;
DEFINE_STANDARD_HANDLE (OpenGl_CappingAlgoFilter, OpenGl_RenderFilter)
//! Capping surface rendering algorithm.
class OpenGl_CappingAlgo
{
public:
//! Draw capping surfaces by OpenGl for the clipping planes enabled in current context state.
//! Depth buffer must be generated for the passed groups.
//! @param theWorkspace [in] the GL workspace, context state
//! @param theStructure [in] the structure to be capped
Standard_EXPORT static void RenderCapping (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Structure& theStructure);
};
//! Graphical capping rendering algorithm filter.
//! Filters out everything except shaded primitives.
class OpenGl_CappingAlgoFilter : public OpenGl_RenderFilter
{
public:
//! Default constructor.
OpenGl_CappingAlgoFilter() {}
//! Sets the current active filter in workspace.
//! @param thePrevFilter [in] the previously active filter that should have additive effect.
void SetPreviousFilter (const Handle(OpenGl_RenderFilter)& thePrevFitler) { myFilter = thePrevFitler; }
//! Checks whether the element can be rendered or not.
//! @param theElement [in] the element to check.
//! @return True if element can be rendered.
virtual Standard_Boolean ShouldRender (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Element* theGlElement) Standard_OVERRIDE;
private:
Handle(OpenGl_RenderFilter) myFilter; //!< Previous active filter that should be combined.
public:
DEFINE_STANDARD_RTTIEXT(OpenGl_CappingAlgoFilter,OpenGl_RenderFilter)
};
#endif

View File

@@ -1,244 +0,0 @@
// Created on: 2013-08-15
// Created by: Anton POLETAEV
// Copyright (c) 2013-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 <NCollection_AlignedAllocator.hxx>
#include <OpenGl_CappingPlaneResource.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_Vec.hxx>
#include <Precision.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_CappingPlaneResource,OpenGl_Resource)
namespace
{
//! 12 plane vertices, interleaved:
//! - 4 floats, position
//! - 4 floats, normal
//! - 4 floats, UV texture coordinates
static const GLfloat THE_CAPPING_PLN_VERTS[12 * (4 + 4 + 4)] =
{
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f,-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f,-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f
};
static const OpenGl_Matrix OpenGl_IdentityMatrix =
{
// mat[4][4]
{ { 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f } }
};
}
// =======================================================================
// function : OpenGl_CappingPlaneResource
// purpose :
// =======================================================================
OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d_ClipPlane)& thePlane)
: myPrimitives (NULL),
myOrientation (OpenGl_IdentityMatrix),
myAspect (NULL),
myPlaneRoot (thePlane),
myEquationMod ((unsigned int )-1),
myAspectMod ((unsigned int )-1)
{
// Fill primitive array
Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (anAlloc);
Graphic3d_Attribute anAttribInfo[] =
{
{ Graphic3d_TOA_POS, Graphic3d_TOD_VEC4 },
{ Graphic3d_TOA_NORM, Graphic3d_TOD_VEC4 },
{ Graphic3d_TOA_UV, Graphic3d_TOD_VEC4 }
};
if (anAttribs->Init (12, anAttribInfo, 3))
{
memcpy (anAttribs->ChangeData(), THE_CAPPING_PLN_VERTS, sizeof(THE_CAPPING_PLN_VERTS));
myPrimitives.InitBuffers (NULL, Graphic3d_TOPA_TRIANGLES, NULL, anAttribs, NULL);
}
}
// =======================================================================
// function : OpenGl_CappingPlaneResource
// purpose :
// =======================================================================
OpenGl_CappingPlaneResource::~OpenGl_CappingPlaneResource()
{
Release (NULL);
}
// =======================================================================
// function : Update
// purpose :
// =======================================================================
void OpenGl_CappingPlaneResource::Update (const Handle(OpenGl_Context)& ,
const Handle(Graphic3d_AspectFillArea3d)& theObjAspect)
{
updateTransform();
updateAspect (theObjAspect);
}
// =======================================================================
// function : Release
// purpose :
// =======================================================================
void OpenGl_CappingPlaneResource::Release (OpenGl_Context* theContext)
{
OpenGl_Element::Destroy (theContext, myAspect);
myPrimitives.Release (theContext);
myEquationMod = (unsigned int )-1;
myAspectMod = (unsigned int )-1;
}
// =======================================================================
// function : updateAspect
// purpose :
// =======================================================================
void OpenGl_CappingPlaneResource::updateAspect (const Handle(Graphic3d_AspectFillArea3d)& theObjAspect)
{
if (myAspect == NULL)
{
myAspect = new OpenGl_AspectFace();
myAspectMod = myPlaneRoot->MCountAspect() - 1; // mark out of sync
}
if (theObjAspect.IsNull())
{
if (myAspectMod != myPlaneRoot->MCountAspect())
{
myAspect->SetAspect (myPlaneRoot->CappingAspect());
myAspectMod = myPlaneRoot->MCountAspect();
}
return;
}
if (myFillAreaAspect.IsNull())
{
myFillAreaAspect = new Graphic3d_AspectFillArea3d();
}
if (myAspectMod != myPlaneRoot->MCountAspect())
{
*myFillAreaAspect = *myPlaneRoot->CappingAspect();
}
if (myPlaneRoot->ToUseObjectMaterial())
{
// only front material currently supported by capping rendering
myFillAreaAspect->SetFrontMaterial (theObjAspect->FrontMaterial());
myFillAreaAspect->SetInteriorColor (theObjAspect->InteriorColor());
}
if (myPlaneRoot->ToUseObjectTexture())
{
myFillAreaAspect->SetTextureSet (theObjAspect->TextureSet());
if (theObjAspect->ToMapTexture())
{
myFillAreaAspect->SetTextureMapOn();
}
else
{
myFillAreaAspect->SetTextureMapOff();
}
}
if (myPlaneRoot->ToUseObjectShader())
{
myFillAreaAspect->SetShaderProgram (theObjAspect->ShaderProgram());
}
myAspect->SetAspect (myFillAreaAspect);
}
// =======================================================================
// function : updateTransform
// purpose :
// =======================================================================
void OpenGl_CappingPlaneResource::updateTransform()
{
const Graphic3d_ClipPlane::Equation& anEquation = myPlaneRoot->GetEquation();
if (myEquationMod == myPlaneRoot->MCountEquation())
{
return; // nothing to update
}
// re-evaluate infinite plane transformation matrix
Standard_ShortReal N[3] =
{ (Standard_ShortReal)anEquation[0],
(Standard_ShortReal)anEquation[1],
(Standard_ShortReal)anEquation[2] };
Standard_ShortReal T[3] =
{ (Standard_ShortReal)(anEquation[0] * -anEquation[3]),
(Standard_ShortReal)(anEquation[1] * -anEquation[3]),
(Standard_ShortReal)(anEquation[2] * -anEquation[3]) };
Standard_ShortReal L[3] = { 0.0f, 0.0f, 0.0f };
Standard_ShortReal F[3] = { 0.0f, 0.0f, 0.0f };
// project plane normal onto OX to find left vector
Standard_ShortReal aProjLen =
sqrt ( (Standard_ShortReal)(anEquation[0] * anEquation[0])
+ (Standard_ShortReal)(anEquation[2] * anEquation[2]));
if (aProjLen < ShortRealSmall())
{
L[0] = 1.0f;
}
else
{
L[0] = N[2] / aProjLen;
L[2] = -N[0] / aProjLen;
}
// (-aLeft) x aNorm
F[0] = (-L[1])*N[2] - (-L[2])*N[1];
F[1] = (-L[2])*N[0] - (-L[0])*N[2];
F[2] = (-L[0])*N[1] - (-L[1])*N[0];
myOrientation.mat[0][0] = L[0];
myOrientation.mat[0][1] = L[1];
myOrientation.mat[0][2] = L[2];
myOrientation.mat[0][3] = 0.0f;
myOrientation.mat[1][0] = N[0];
myOrientation.mat[1][1] = N[1];
myOrientation.mat[1][2] = N[2];
myOrientation.mat[1][3] = 0.0f;
myOrientation.mat[2][0] = F[0];
myOrientation.mat[2][1] = F[1];
myOrientation.mat[2][2] = F[2];
myOrientation.mat[2][3] = 0.0f;
myOrientation.mat[3][0] = T[0];
myOrientation.mat[3][1] = T[1];
myOrientation.mat[3][2] = T[2];
myOrientation.mat[3][3] = 1.0f;
myEquationMod = myPlaneRoot->MCountEquation();
}

View File

@@ -1,96 +0,0 @@
// Created on: 2013-08-15
// Created by: Anton POLETAEV
// Copyright (c) 2013-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 _OpenGl_CappingPlaneResource_H__
#define _OpenGl_CappingPlaneResource_H__
#include <OpenGl_PrimitiveArray.hxx>
#include <OpenGl_Resource.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_Matrix.hxx>
#include <Graphic3d_ClipPlane.hxx>
class OpenGl_CappingPlaneResource;
DEFINE_STANDARD_HANDLE (OpenGl_CappingPlaneResource, OpenGl_Resource)
//! Container of graphical resources for rendering capping plane
//! associated to graphical clipping plane.
//! This resource holds data necessary for OpenGl_CappingAlgo.
//! This object is implemented as OpenGl resource for the following reasons:
//! - one instance should be shared between contexts.
//! - instance associated to Graphic3d_ClipPlane data by id.
//! - should created and released within context (owns OpenGl elements and resources).
class OpenGl_CappingPlaneResource : public OpenGl_Resource
{
public:
//! Constructor.
//! Create capping plane presentation associated to clipping plane data.
//! @param thePlane [in] the plane data.
Standard_EXPORT OpenGl_CappingPlaneResource (const Handle(Graphic3d_ClipPlane)& thePlane);
//! Destroy object.
Standard_EXPORT virtual ~OpenGl_CappingPlaneResource();
//! Update resource data in the passed context.
//! @param theContext [in] the context
//! @param theObjAspect [in] object aspect
Standard_EXPORT void Update (const Handle(OpenGl_Context)& theContext,
const Handle(Graphic3d_AspectFillArea3d)& theObjAspect);
//! Release associated OpenGl resources.
//! @param theContext [in] the resource context.
Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE;
//! Returns estimated GPU memory usage - not implemented.
virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
//! Return parent clipping plane structure.
const Handle(Graphic3d_ClipPlane)& Plane() const { return myPlaneRoot; }
//! @return aspect face for rendering capping surface.
inline const OpenGl_AspectFace* AspectFace() const { return myAspect; }
//! @return evaluated orientation matrix to transform infinite plane.
inline const OpenGl_Matrix* Orientation() const { return &myOrientation; }
//! @return primitive array of vertices to render infinite plane.
inline const OpenGl_PrimitiveArray& Primitives() const { return myPrimitives; }
private:
//! Update precomputed plane orientation matrix.
void updateTransform();
//! Update resources.
void updateAspect (const Handle(Graphic3d_AspectFillArea3d)& theObjAspect);
private:
OpenGl_PrimitiveArray myPrimitives; //!< vertices and texture coordinates for rendering
OpenGl_Matrix myOrientation; //!< plane transformation matrix.
OpenGl_AspectFace* myAspect; //!< capping face aspect.
Handle(Graphic3d_ClipPlane) myPlaneRoot; //!< parent clipping plane structure.
Handle(Graphic3d_AspectFillArea3d) myFillAreaAspect; //!< own capping aspect
unsigned int myEquationMod; //!< modification counter for plane equation.
unsigned int myAspectMod; //!< modification counter for aspect.
public:
DEFINE_STANDARD_RTTIEXT(OpenGl_CappingPlaneResource,OpenGl_Resource) // Type definition
};
#endif

View File

@@ -0,0 +1,447 @@
// Created on: 2013-09-05
// Created by: Anton POLETAEV
// Copyright (c) 2013-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 <OpenGl_CappingRenderer.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_AspectFillCapping.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_Element.hxx>
#include <OpenGl_PrimitiveArray.hxx>
#include <OpenGl_Resource.hxx>
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_Structure.hxx>
#include <OpenGl_View.hxx>
#include <OpenGl_Workspace.hxx>
#include <Graphic3d_Camera.hxx>
#include <NCollection_AlignedAllocator.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_CappingRenderFilter, OpenGl_RenderFilter)
namespace
{
//! interleaved (4x position, 4x normals, 4x (u,v) coordinates).
//! o ----o
//! representing | \ / |
//! these | o |
//! triangles: | / \ |
//! o --- o
static const GLfloat THE_CAPPING_PLN_VERTS[12 * (4 + 4 + 4)] =
{
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
-1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f,-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f,-1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f
};
class OpenGl_SharedElement : public OpenGl_Resource
{
public:
OpenGl_SharedElement (OpenGl_Element* theGlElement) : myGlElement (theGlElement) {}
virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE
{
OpenGl_Element::Destroy (theGlCtx, myGlElement);
}
OpenGl_Element* GlElement() const { return myGlElement; }
//! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
private:
OpenGl_Element* myGlElement;
public:
DEFINE_STANDARD_RTTI_INLINE (OpenGl_SharedElement, OpenGl_Resource)
};
static const TCollection_AsciiString THE_QUAD_PARRAY = "OpenGl_CappingRenderer_Quad";
static const TCollection_AsciiString THE_PLANE_STYLE = "OpenGl_CappingRenderer_CappingStyle_";
static const OpenGl_AspectFillCapping THE_DEFAULT_ASPECT = OpenGl_AspectFillCapping (new Graphic3d_AspectFillCapping);
}
// =======================================================================
// function : Render
// purpose : Renders capping surfaces for enabled clipping planes.
// =======================================================================
void OpenGl_CappingRenderer::Render (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Structure& theStructure)
{
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
if (!aContext->Clipping().IsCappingOn())
{
return;
}
const OpenGl_PrimitiveArray* aCappingQuad = initQuad (aContext);
if (!aCappingQuad)
{
return;
}
const OpenGl_AspectFace* aPrevAspect = theWorkspace->AspectFace();
Handle(OpenGl_RenderFilter) aPrevFilter = theWorkspace->GetRenderFilter();
Handle(OpenGl_CappingRenderFilter) aCappingFilter = theWorkspace->CappingRenderFilter();
aCappingFilter->SetPreviousFilter (aPrevFilter);
theWorkspace->SetRenderFilter (aCappingFilter);
GLint aDepthFuncPrev;
glGetIntegerv (GL_DEPTH_FUNC, &aDepthFuncPrev);
glDepthFunc (GL_LESS);
glEnable (GL_STENCIL_TEST);
GLboolean aPrevBlend = glIsEnabled (GL_BLEND);
GLint aPrevBlendSrc = GL_ONE;
GLint aPrevBlendDst = GL_ZERO;
if (aPrevBlend == GL_TRUE)
{
glGetIntegerv (GL_BLEND_SRC_ALPHA, &aPrevBlendSrc);
glGetIntegerv (GL_BLEND_DST_ALPHA, &aPrevBlendDst);
glDisable (GL_BLEND);
}
for (OpenGl_ClippingIterator aCappingIt (aContext->Clipping()); aCappingIt.More(); aCappingIt.Next())
{
const Handle(Graphic3d_ClipPlane)& aPlane = aCappingIt.Value();
if (!aPlane->IsCapping()
|| aCappingIt.IsDisabled())
{
continue;
}
Handle(OpenGl_AspectFillCapping) anAspect;
TCollection_AsciiString aSharedStyleId;
if (!aPlane->CappingSectionStyle().IsNull())
{
aSharedStyleId = THE_PLANE_STYLE + aPlane->GetId();
if (!aContext->GetResource (aSharedStyleId, anAspect))
{
anAspect = new OpenGl_AspectFillCapping (aPlane->CappingSectionStyle());
aContext->ShareResource (aSharedStyleId, anAspect);
}
}
renderOne (theWorkspace, theStructure, aCappingIt, anAspect.get(), aCappingQuad);
if (!aSharedStyleId.IsEmpty())
{
// schedule release of resource if not used
aContext->ReleaseResource (aSharedStyleId, Standard_True);
}
}
glClear (GL_STENCIL_BUFFER_BIT);
glDepthFunc (aDepthFuncPrev);
glStencilFunc (GL_ALWAYS, 0, 0xFF);
glDisable (GL_STENCIL_TEST);
if (aPrevBlend == GL_TRUE)
{
glEnable (GL_BLEND);
glBlendFunc (aPrevBlendSrc, aPrevBlendDst);
}
theWorkspace->SetRenderFilter (aPrevFilter);
theWorkspace->SetAspectFace (aPrevAspect);
}
// =======================================================================
// function : renderOne
// purpose : method to render capping section of one given plane for a structure.
// =======================================================================
void OpenGl_CappingRenderer::renderOne (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Structure& theStructure,
const OpenGl_ClippingIterator& thePlaneIter,
const OpenGl_AspectFillCapping* thePlaneAspectCapping,
const OpenGl_PrimitiveArray* theQuad)
{
const Handle(Graphic3d_ClipPlane)& aPlane = thePlaneIter.Value();
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
const Handle(Graphic3d_Camera) aCamera = theWorkspace->View() != NULL
? theWorkspace->View()->Camera()
: Handle(Graphic3d_Camera)();
const OpenGl_Mat4& aPlaneMat = OpenGl_Mat4::Map (aPlane->OrientationMatrix());
Standard_ShortReal aRotateAngle = 0.0;
Standard_ShortReal aViewScale = ShortRealLast();
OpenGl_Mat4 aRotateZoomMat;
for (OpenGl_Structure::GroupIterator aGroupIter (theStructure.Groups()); aGroupIter.More(); aGroupIter.Next())
{
if (!aGroupIter.Value()->IsClosed())
{
continue;
}
// enable only the rendering plane to generate stencil mask
aContext->ChangeClipping().DisableAllExcept (aContext, thePlaneIter);
aContext->ShaderManager()->UpdateClippingState();
glClear (GL_STENCIL_BUFFER_BIT);
const bool aColorMaskBack = aContext->SetColorMask(false);
// override aspects, disable culling
theWorkspace->SetAspectFace (&theWorkspace->NoneCulling());
theWorkspace->ApplyAspectFace();
// evaluate number of pair faces
if (theWorkspace->UseZBuffer())
{
glDisable (GL_DEPTH_TEST);
}
if (theWorkspace->UseDepthWrite())
{
glDepthMask (GL_FALSE);
}
glStencilFunc (GL_ALWAYS, 1, 0x01);
glStencilOp (GL_KEEP, GL_INVERT, GL_INVERT);
aGroupIter.Value()->Render (theWorkspace);
// override material, cull back faces
theWorkspace->SetAspectFace (&theWorkspace->FrontCulling());
theWorkspace->ApplyAspectFace();
// enable all clip plane except the rendered one
aContext->ChangeClipping().EnableAllExcept (aContext, thePlaneIter);
aContext->ShaderManager()->UpdateClippingState();
// render capping plane using the generated stencil mask
aContext->SetColorMask(aColorMaskBack);
if (theWorkspace->UseDepthWrite())
{
glDepthMask (GL_TRUE);
}
glStencilFunc (GL_EQUAL, 1, 0x01);
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
if (theWorkspace->UseZBuffer())
{
glEnable (GL_DEPTH_TEST);
}
const OpenGl_AspectFace* aGroupAspectFace = aGroupIter.Value()->AspectFace();
const OpenGl_AspectFillCapping* aGroupAspectCapping = aGroupIter.Value()->AspectFillCapping();
const OpenGl_AspectFillCapping* anAspectCapping =
thePlaneAspectCapping && (!aGroupAspectCapping || aGroupAspectCapping->Aspect().IsNull() || aPlane->ToOverrideCappingAspect())
? thePlaneAspectCapping
: aGroupAspectCapping;
if (anAspectCapping == NULL)
{
anAspectCapping = &THE_DEFAULT_ASPECT;
}
const OpenGl_AspectFace* anAspectFace = anAspectCapping->CappingFaceAspect (aGroupAspectFace);
const Standard_Boolean hasHatch = anAspectCapping->Aspect()->ToDrawHatch();
const OpenGl_AspectFace* anAspectHatching = hasHatch ? anAspectCapping->HatchingFaceAspect() : NULL;
const Standard_Boolean hasTextureHatch = hasHatch && !anAspectCapping->Aspect()->TextureHatch().IsNull();
const Standard_Boolean isRotatePers = hasTextureHatch && !aCamera.IsNull() && anAspectCapping->Aspect()->IsHatchRotationPersistent();
const Standard_Boolean isZoomPers = hasTextureHatch && !aCamera.IsNull() && anAspectCapping->Aspect()->IsHatchZoomPersistent();
Standard_ShortReal aHatchScale = 1.0;
Standard_ShortReal aHatchAngle = 0.0;
if (isRotatePers || isZoomPers)
{
if (isRotatePers)
{
if (aRotateAngle == 0.0)
{
const gp_Dir aPlaneSide (aPlaneMat.GetValue (0, 0), aPlaneMat.GetValue (1, 0), aPlaneMat.GetValue (2, 0));
const gp_Dir aPlaneUp (aPlaneMat.GetValue (0, 2), aPlaneMat.GetValue (1, 2), aPlaneMat.GetValue (2, 2));
const gp_Dir& aCameraUp = aCamera->Up();
const gp_Vec aCameraPln = aPlaneSide.Dot (aCameraUp) * aPlaneSide + aPlaneUp.Dot (aCameraUp) * aPlaneUp;
const gp_Dir& aCameraDir = aCamera->Direction();
aRotateAngle = static_cast<Standard_ShortReal> (aCameraPln.AngleWithRef (aPlaneUp, aCameraDir) / M_PI * 180.0);
}
aHatchAngle = aRotateAngle;
}
if (isZoomPers)
{
if (aViewScale == ShortRealLast())
{
const Standard_Real aFocus = aCamera->IsOrthographic()
? aCamera->Distance()
: (aCamera->ZFocusType() == Graphic3d_Camera::FocusType_Relative
? Standard_Real(aCamera->ZFocus() * aCamera->Distance())
: Standard_Real(aCamera->ZFocus()));
const gp_XYZ aViewDim = aCamera->ViewDimensions (aFocus);
aViewScale = static_cast<Standard_ShortReal> (aViewDim.Y() / aContext->Viewport()[3]);
}
aHatchScale = 1.0f / (aViewScale * anAspectHatching->TextureSet(aContext)->First()->SizeY());
}
}
renderSection (theWorkspace, theQuad, anAspectFace, hasHatch ? anAspectCapping->HatchingFaceAspect() : NULL, aPlaneMat, aHatchScale, aHatchAngle);
// turn on the current plane to restore initial state
aContext->ChangeClipping().SetEnabled (aContext, thePlaneIter, Standard_True);
aContext->ShaderManager()->RevertClippingState();
aContext->ShaderManager()->RevertClippingState();
}
if (theStructure.InstancedStructure() != NULL)
{
renderOne (theWorkspace, *theStructure.InstancedStructure(), thePlaneIter, thePlaneAspectCapping, theQuad);
}
}
// =======================================================================
// function : renderSection
// purpose :
// =======================================================================
void OpenGl_CappingRenderer::renderSection (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_PrimitiveArray* theQuad,
const OpenGl_AspectFace* theCappingAspect,
const OpenGl_AspectFace* theHatchAspect,
const OpenGl_Mat4& theCappingMatrix,
const Standard_ShortReal theHatchScale,
const Standard_ShortReal theHatchRotate)
{
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
const Standard_Boolean isTextureHatch =
theHatchAspect != NULL
&& theHatchAspect->Aspect()->TextureMapState();
aContext->ModelWorldState.Push();
aContext->ModelWorldState.SetCurrent (theCappingMatrix);
aContext->ApplyModelViewMatrix();
theWorkspace->SetAspectFace (theCappingAspect);
theWorkspace->ApplyAspectFace();
theQuad->Render (theWorkspace);
if (theHatchAspect != NULL)
{
Graphic3d_Vec2 aPrevScale;
Standard_ShortReal aPrevRotate = 0.0;
if (isTextureHatch)
{
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (theHatchScale != 1.0 || theHatchRotate != 0.0)
{
const Handle(Graphic3d_TextureParams)& aTexParams = theHatchAspect->TextureSet(aContext)->First()->Sampler()->Parameters();
aPrevScale = aTexParams->Scale();
aPrevRotate = aTexParams->Rotation();
const Standard_Boolean isMirror = aPrevScale.x() * aPrevScale.y() < 0.0;
aTexParams->SetScale (aPrevScale * theHatchScale);
aTexParams->SetRotation (isMirror ? aPrevRotate - theHatchRotate : aPrevRotate + theHatchRotate);
}
}
theWorkspace->SetAspectFace (theHatchAspect);
theWorkspace->ApplyAspectFace();
glDepthFunc (GL_LEQUAL);
theQuad->Render (theWorkspace);
glDepthFunc (GL_LESS);
if (isTextureHatch)
{
glDisable (GL_BLEND);
if (theHatchScale != 1.0 || theHatchRotate != 0.0)
{
const Handle(Graphic3d_TextureParams)& aTexParams = theHatchAspect->TextureSet(aContext)->First()->Sampler()->Parameters();
aTexParams->SetScale (aPrevScale);
aTexParams->SetRotation (aPrevRotate);
}
}
}
aContext->ModelWorldState.Pop();
aContext->ApplyModelViewMatrix();
}
// =======================================================================
// function : initQuad
// purpose : initializes and returns vertex buffer for plane section
// =======================================================================
OpenGl_PrimitiveArray* OpenGl_CappingRenderer::initQuad (const Handle(OpenGl_Context)& theContext)
{
Handle(OpenGl_SharedElement) aSharedResource;
if (!theContext->GetResource (THE_QUAD_PARRAY, aSharedResource))
{
OpenGl_PrimitiveArray* aPArray = NULL;
Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (anAlloc);
Graphic3d_Attribute anAttribInfo[] =
{
{ Graphic3d_TOA_POS, Graphic3d_TOD_VEC4 },
{ Graphic3d_TOA_NORM, Graphic3d_TOD_VEC4 },
{ Graphic3d_TOA_UV, Graphic3d_TOD_VEC4 }
};
if (anAttribs->Init (12, anAttribInfo, 3))
{
memcpy (anAttribs->ChangeData(), THE_CAPPING_PLN_VERTS, sizeof (THE_CAPPING_PLN_VERTS));
aPArray = new OpenGl_PrimitiveArray (NULL);
aPArray->InitBuffers (NULL, Graphic3d_TOPA_TRIANGLES, NULL, anAttribs, NULL);
}
aSharedResource = new OpenGl_SharedElement (aPArray);
theContext->ShareResource (THE_QUAD_PARRAY, aSharedResource);
}
return dynamic_cast<OpenGl_PrimitiveArray*> (aSharedResource->GlElement());
}
// =======================================================================
// function : CanRender
// purpose :
// =======================================================================
Standard_Boolean OpenGl_CappingRenderFilter::ShouldRender (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Element* theGlElement)
{
if (!myFilter.IsNull() && !myFilter->ShouldRender (theWorkspace, theGlElement))
{
return Standard_False;
}
return theGlElement->IsFillDrawMode();
}

View File

@@ -0,0 +1,120 @@
// Created on: 2013-09-05
// Created by: Anton POLETAEV
// Copyright (c) 2013-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 _OpenGl_CappingRenderer_H__
#define _OpenGl_CappingRenderer_H__
#include <OpenGl_RenderFilter.hxx>
#include <OpenGl_Vec.hxx>
// Forward declaration
class OpenGl_AspectFace;
class OpenGl_AspectFillCapping;
class OpenGl_AspectSection;
class OpenGl_CappingStyle;
class OpenGl_ClippingIterator;
class OpenGl_Context;
class OpenGl_Element;
class OpenGl_PrimitiveArray;
class OpenGl_Structure;
class OpenGl_Texture;
class OpenGl_Workspace;
//! Class implementing an OpenGL rasterization algorithm for drawing capping planes over clipped geometry.
class OpenGl_CappingRenderer
{
public:
//! Renders capping surfaces for enabled clipping planes.
//! @note Depth buffer must be generated for the passed groups.
//! @param theWorkspace [in] the GL workspace, context state
//! @param theStructure [in] the structure to be capped
Standard_EXPORT static void Render (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Structure& theStructure);
private:
//! Method to render capping section of one given plane for a structure.
static void renderOne (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Structure& theStructure,
const OpenGl_ClippingIterator& thePlaneIter,
const OpenGl_AspectFillCapping* thePlaneAspectCapping,
const OpenGl_PrimitiveArray* theQuad);
//! Render section plane using the given aspects.
static void renderSection (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_PrimitiveArray* theQuad,
const OpenGl_AspectFace* theCappingAspect,
const OpenGl_AspectFace* theHatchAspect,
const OpenGl_Mat4& theCappingMatrix,
const Standard_ShortReal theHatchScale,
const Standard_ShortReal theHatchRotate);
//! Initializes and returns face draw element for rendering section plane.
//! @note once initialized, context will hold resource until destroyed.
static OpenGl_PrimitiveArray* initQuad (const Handle(OpenGl_Context)& theContext);
//! Set rotation persistence components for the matrix to support persistent texturing.
//! @param theWorkspace [in] the GL workspace, context state.
//! @param thePlane [in] the plane.
//! @param theRotateScaleMat [in/out] the matrix combining rotation and scaling persistence components.
static void computePersistence (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_ClippingIterator& thePlane,
const Handle(OpenGl_Texture)& theTexture,
const bool theRotatePers,
const bool theZoomPers,
OpenGl_Mat4& theRotateScaleMat);
//! Set zoom persistence components for the matrix to support persistent texturing.
//! @param theWorkspace [in] the GL workspace, context state.
//! @param thePlane [in] the plane.
//! @param theTexture [in] the texture.
//! @param theRotateScaleMat [in/out] the matrix combining rotation and scaling persistence components.
static void setZoomPersistence (const Handle(OpenGl_Workspace)& theWorkspace,
const Handle(OpenGl_Texture)& theTexture,
OpenGl_Mat4& theRotateScaleMat);
};
//! Filters out everything except face primitives of solids.
class OpenGl_CappingRenderFilter : public OpenGl_RenderFilter
{
public:
//! Default constructor.
OpenGl_CappingRenderFilter() {}
//! Sets the current active filter in workspace.
//! @param thePrevFilter [in] the previously active filter that should have additive effect.
void SetPreviousFilter (const Handle(OpenGl_RenderFilter)& thePrevFitler) { myFilter = thePrevFitler; }
//! Checks whether the element can be rendered or not.
//! @param theElement [in] the element to check.
//! @return True if element can be rendered.
Standard_EXPORT virtual
Standard_Boolean ShouldRender (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Element* theGlElement) Standard_OVERRIDE;
private:
Handle(OpenGl_RenderFilter) myFilter; //!< Previous active filter that should be combined.
public:
DEFINE_STANDARD_RTTIEXT (OpenGl_CappingRenderFilter, OpenGl_RenderFilter)
};
DEFINE_STANDARD_HANDLE (OpenGl_CappingRenderFilter, OpenGl_RenderFilter)
#endif

View File

@@ -68,7 +68,7 @@ public:
//! @param theWorkspace [in] the rendering workspace.
//! @param theFilter [in] the rendering filter to check whether the element
//! should be rendered or not.
//! @return True if element passes the check and renders,
//! @return True if element passes the filtering check and is rendered.
inline Standard_Boolean
RenderFiltered (const Handle(OpenGl_Workspace)& theWorkspace,
const Handle(OpenGl_RenderFilter)& theFilter) const

View File

@@ -242,6 +242,28 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& th
Update();
}
// =======================================================================
// function : SetGroupPrimitivesAspect
// purpose :
// =======================================================================
void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect)
{
if (IsDeleted())
{
return;
}
if (myAspectFillCapping == NULL)
{
myAspectFillCapping = new OpenGl_AspectFillCapping (theAspect);
}
else
{
myAspectFillCapping->SetAspect (theAspect);
}
Update();
}
// =======================================================================
// function : AddPrimitiveArray
// purpose :

View File

@@ -22,6 +22,7 @@
#include <NCollection_List.hxx>
#include <OpenGl_AspectLine.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_AspectFillCapping.hxx>
#include <OpenGl_AspectMarker.hxx>
#include <OpenGl_AspectText.hxx>
#include <OpenGl_Element.hxx>
@@ -103,6 +104,17 @@ public:
//! Append text aspect as an element.
Standard_EXPORT virtual void SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspect) Standard_OVERRIDE;
//! Update section style aspect.
Standard_EXPORT virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillCapping)& theAspect) Standard_OVERRIDE;
//! Returns section style aspect.
virtual Handle(Graphic3d_AspectFillCapping) FillCappingAspect() const Standard_OVERRIDE
{
return myAspectFillCapping != NULL
? myAspectFillCapping->Aspect()
: Handle(Graphic3d_AspectFillCapping)();
}
//! Add primitive array element
Standard_EXPORT virtual void AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
const Handle(Graphic3d_IndexBuffer)& theIndices,
@@ -153,6 +165,9 @@ public:
//! Returns OpenGL face aspect.
const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
//! Returns OpenGL capping filling aspect.
const OpenGl_AspectFillCapping* AspectFillCapping() const { return myAspectFillCapping; }
//! Is the group ray-tracable (contains ray-tracable elements)?
Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
@@ -162,10 +177,11 @@ protected:
protected:
OpenGl_AspectLine* myAspectLine;
OpenGl_AspectFace* myAspectFace;
OpenGl_AspectMarker* myAspectMarker;
OpenGl_AspectText* myAspectText;
OpenGl_AspectLine* myAspectLine;
OpenGl_AspectFace* myAspectFace;
OpenGl_AspectMarker* myAspectMarker;
OpenGl_AspectText* myAspectText;
OpenGl_AspectFillCapping* myAspectFillCapping;
OpenGl_ElementNode* myFirst;
OpenGl_ElementNode* myLast;

View File

@@ -1178,11 +1178,11 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFont()
EOL"}";
TCollection_AsciiString
aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occSamplerBaseColor, TexCoord.st).a; }";
aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, TexCoord.st).a; }";
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core11 == NULL)
{
aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occSamplerBaseColor, TexCoord.st).r; }";
aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, TexCoord.st).r; }";
}
#endif
@@ -1291,8 +1291,8 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFboBlit()
}
myContext->BindProgram (myBlitProgram);
myBlitProgram->SetSampler (myContext, "uColorSampler", Graphic3d_TextureUnit_0);
myBlitProgram->SetSampler (myContext, "uDepthSampler", Graphic3d_TextureUnit_1);
myBlitProgram->SetSampler(myContext, "uColorSampler", Graphic3d_TextureUnit_0);
myBlitProgram->SetSampler(myContext, "uDepthSampler", Graphic3d_TextureUnit_1);
myContext->BindProgram (NULL);
return Standard_True;
}
@@ -1385,8 +1385,8 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramOitCompositing (const St
}
myContext->BindProgram (aProgram);
aProgram->SetSampler (myContext, "uAccumTexture", Graphic3d_TextureUnit_0);
aProgram->SetSampler (myContext, "uWeightTexture", Graphic3d_TextureUnit_1);
aProgram->SetSampler(myContext, "uAccumTexture", Graphic3d_TextureUnit_0);
aProgram->SetSampler(myContext, "uWeightTexture", Graphic3d_TextureUnit_1);
myContext->BindProgram (Handle(OpenGl_ShaderProgram)());
return Standard_True;
}
@@ -1397,12 +1397,12 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramOitCompositing (const St
// =======================================================================
TCollection_AsciiString OpenGl_ShaderManager::pointSpriteAlphaSrc (const Standard_Integer theBits)
{
TCollection_AsciiString aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occSamplerBaseColor, " THE_VEC2_glPointCoord ").a; }";
TCollection_AsciiString aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord ").a; }";
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core11 == NULL
&& (theBits & OpenGl_PO_TextureA) != 0)
{
aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occSamplerBaseColor, " THE_VEC2_glPointCoord ").r; }";
aSrcGetAlpha = EOL"float getAlpha(void) { return occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord ").r; }";
}
#else
(void )theBits;
@@ -1445,7 +1445,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha
if ((theBits & OpenGl_PO_TextureRGB) != 0)
{
aSrcFragGetColor =
EOL"vec4 getColor(void) { return occTexture2D(occSamplerBaseColor, " THE_VEC2_glPointCoord "); }";
EOL"vec4 getColor(void) { return occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord "); }";
}
if (textureUsed (theBits))
@@ -1483,7 +1483,10 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha
aSrcVertExtraMain += THE_VARY_TexCoord_Trsf;
aSrcFragGetColor =
EOL"vec4 getColor(void) { return occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w); }";
EOL"vec4 getColor(void)"
EOL"{"
EOL" return occTexture2D(occActiveSampler, TexCoord.st / TexCoord.w) * occColor;"
EOL"}";
}
else if ((theBits & OpenGl_PO_TextureEnv) != 0)
{
@@ -1500,7 +1503,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha
EOL" TexCoord = vec4(aReflect.xy * inversesqrt (dot (aReflect, aReflect)) * 0.5 + vec2 (0.5), 0.0, 1.0);";
aSrcFragGetColor =
EOL"vec4 getColor(void) { return occTexture2D (occSamplerBaseColor, TexCoord.st); }";
EOL"vec4 getColor(void) { return occTexture2D (occActiveSampler, TexCoord.st); }";
}
}
if ((theBits & OpenGl_PO_VertColor) != 0)
@@ -1677,7 +1680,7 @@ TCollection_AsciiString OpenGl_ShaderManager::pointSpriteShadingSrc (const TColl
EOL"vec4 getColor(void)"
EOL"{"
EOL" vec4 aColor = " + theBaseColorSrc + ";"
EOL" aColor = occTexture2D(occSamplerBaseColor, " THE_VEC2_glPointCoord ") * aColor;"
EOL" aColor = occTexture2D(occActiveSampler, " THE_VEC2_glPointCoord ") * aColor;"
EOL" if (aColor.a <= 0.1) discard;"
EOL" return aColor;"
EOL"}";
@@ -1864,7 +1867,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramGouraud (Handle(OpenGl_S
EOL"vec4 getColor(void)"
EOL"{"
EOL" vec4 aColor = gl_FrontFacing ? FrontColor : BackColor;"
EOL" return occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w) * aColor;"
EOL" return occTexture2D(occActiveSampler, TexCoord.st / TexCoord.w) * aColor;"
EOL"}";
}
}
@@ -2030,7 +2033,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramPhong (Handle(OpenGl_Sha
EOL"vec4 getColor(void)"
EOL"{"
EOL" vec4 aColor = " thePhongCompLight ";"
EOL" return occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w) * aColor;"
EOL" return occTexture2D(occActiveSampler, TexCoord.st / TexCoord.w) * aColor;"
EOL"}";
}
}
@@ -2383,8 +2386,8 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramStereo (Handle(OpenGl_Sh
}
myContext->BindProgram (theProgram);
theProgram->SetSampler (myContext, "uLeftSampler", Graphic3d_TextureUnit_0);
theProgram->SetSampler (myContext, "uRightSampler", Graphic3d_TextureUnit_1);
theProgram->SetSampler(myContext, "uLeftSampler", Graphic3d_TextureUnit_0);
theProgram->SetSampler(myContext, "uRightSampler", Graphic3d_TextureUnit_1);
myContext->BindProgram (NULL);
return Standard_True;
}

View File

@@ -13,7 +13,7 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <OpenGl_CappingAlgo.hxx>
#include <OpenGl_CappingRenderer.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_GraphicDriver.hxx>
@@ -657,10 +657,9 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con
}
// Render capping for structure groups
if (hasClosedPrims
&& aCtx->Clipping().IsCappingOn())
if (hasClosedPrims && aCtx->Clipping().IsCappingOn())
{
OpenGl_CappingAlgo::RenderCapping (theWorkspace, *this);
OpenGl_CappingRenderer::Render (theWorkspace, *this);
}
// Revert structure clippings

View File

@@ -16,18 +16,14 @@
#include <OpenGl_Workspace.hxx>
#include <OpenGl_ArbFBO.hxx>
#include <OpenGl_AspectLine.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_AspectMarker.hxx>
#include <OpenGl_AspectText.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_Element.hxx>
#include <OpenGl_FrameBuffer.hxx>
#include <OpenGl_GlCore15.hxx>
#include <OpenGl_SceneGeometry.hxx>
#include <OpenGl_Structure.hxx>
#include <OpenGl_Sampler.hxx>
#include <OpenGl_SceneGeometry.hxx>
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_Structure.hxx>
#include <OpenGl_Texture.hxx>
#include <OpenGl_View.hxx>
#include <OpenGl_Window.hxx>
@@ -167,7 +163,7 @@ OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Wi
#endif
}
myDefaultCappingAlgoFilter = new OpenGl_CappingAlgoFilter();
myCappingRenderFilter = new OpenGl_CappingRenderFilter();
myFontFaceAspect.Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Mask, 0.285f);
myFontFaceAspect.Aspect()->SetShadingModel (Graphic3d_TOSM_UNLIT);

View File

@@ -17,9 +17,13 @@
#define _OpenGl_Workspace_Header
#include <Graphic3d_BufferType.hxx>
#include <Graphic3d_PresentationAttributes.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_CappingAlgo.hxx>
#include <OpenGl_AspectMarker.hxx>
#include <OpenGl_AspectLine.hxx>
#include <OpenGl_AspectText.hxx>
#include <OpenGl_CappingRenderer.hxx>
#include <OpenGl_FrameBuffer.hxx>
#include <OpenGl_Material.hxx>
#include <OpenGl_Matrix.hxx>
@@ -260,8 +264,17 @@ public:
//! Returns face aspect for textured font rendering.
const OpenGl_AspectFace& FontFaceAspect() const { return myFontFaceAspect; }
//! Sets and applies current polygon offset.
void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams);
//! Returns currently applied polygon offset parameters.
const Graphic3d_PolygonOffset& AppliedPolygonOffset() { return myPolygonOffsetApplied; }
//! Returns capping algorithm rendering filter.
const Handle(OpenGl_CappingAlgoFilter)& DefaultCappingAlgoFilter() const { return myDefaultCappingAlgoFilter; }
const Handle(OpenGl_CappingRenderFilter)& CappingRenderFilter() const
{
return myCappingRenderFilter;
}
//! Returns face aspect for none culling mode.
const OpenGl_AspectFace& NoneCulling() const { return myNoneCulling; }
@@ -282,7 +295,7 @@ protected: //! @name protected fields
Handle(OpenGl_Context) myGlContext;
Standard_Boolean myUseZBuffer;
Standard_Boolean myUseDepthWrite;
Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter;
Handle(OpenGl_CappingRenderFilter) myCappingRenderFilter;
OpenGl_AspectFace myNoneCulling;
OpenGl_AspectFace myFrontCulling;
OpenGl_AspectFace myFontFaceAspect;
@@ -306,6 +319,8 @@ protected: //! @name fields related to status
OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
Graphic3d_PolygonOffset myPolygonOffsetApplied; //!< currently applied polygon offset
OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect
Handle(OpenGl_TextureSet) myEnvironmentTexture;

View File

@@ -39,6 +39,7 @@
#include <StepBasic_ProductDefinition.hxx>
#include <StepBasic_ProductDefinitionFormation.hxx>
#include <StepBasic_ProductDefinitionRelationship.hxx>
#include <StepBasic_ProductDefinitionWithAssociatedDocuments.hxx>
#include <StepBasic_SiUnit.hxx>
#include <StepBasic_SiUnitAndLengthUnit.hxx>
#include <StepBasic_Unit.hxx>
@@ -1158,6 +1159,7 @@ Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSe
Standard_Integer nb = Model->NbEntities();
Handle(Standard_Type) tNAUO = STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
Handle(Standard_Type) tPDWAD = STANDARD_TYPE(StepBasic_ProductDefinitionWithAssociatedDocuments);
Handle(TCollection_HAsciiString) name;
TDF_Label L;
for (Standard_Integer i = 1; i <= nb; i++) {
@@ -1190,7 +1192,7 @@ Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSe
}
// for PD get name of associated product
if ( enti->DynamicType() == tPD ) {
if (enti->DynamicType() == tPD || enti->DynamicType() == tPDWAD) {
L.Nullify();
Handle(StepBasic_ProductDefinition) PD =
Handle(StepBasic_ProductDefinition)::DownCast(enti);

View File

@@ -43,6 +43,7 @@
#include <ShapeFix.hxx>
#include <ShapeFix_ComposeShell.hxx>
#include <ShapeUpgrade.hxx>
#include <ShapeUpgrade_CombineToCylinder.hxx>
#include <ShapeUpgrade_RemoveInternalWires.hxx>
#include <ShapeUpgrade_RemoveLocations.hxx>
#include <ShapeUpgrade_ShapeConvertToBezier.hxx>
@@ -1477,6 +1478,69 @@ static Standard_Integer reshape(Draw_Interpretor& /*theDI*/,
return 0;
}
//=======================================================================
// CombineToCylinder
//=======================================================================
static Standard_Integer CombineToCylinder(Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n < 3)
{
di << "Use combinetocyl result shape [-t val] [-a val]\n";
di << "options:\n";
di << "-t val to set linear tolerance (default is 1e-7)\n";
di << "-a val to set angular tolerance (default is 1e-12)\n";
return 1;
}
TopoDS_Shape aShape = DBRep::Get(a[2]);
if (aShape.IsNull())
return 1;
// default values
Standard_Real aLinTol = Precision::Confusion();
Standard_Real aAngTol = Precision::Angular();
if (n > 3)
{
for (int i = 3; i < n; i++)
{
if (!strcmp(a[i], "-t") || !strcmp(a[i], "-a"))
{
if (++i < n)
{
if (a[i - 1][1] == 't')
aLinTol = Draw::Atof(a[i]);
else
aAngTol = Draw::Atof(a[i]) * M_PI / 180.;
}
else
{
di << "value expected after " << a[i - 1];
return 1;
}
}
}
}
ShapeUpgrade_CombineToCylinder aTool;
aTool.SetShape(aShape);
aTool.SetLinearTolerance(aLinTol);
aTool.SetAngularTolerance(aAngTol);
aTool.Build();
if (!aTool.IsDone())
{
di << "Not done";
}
else
{
di << "Number of new merged faces: " << aTool.NbNewFaces();
di << "\nNumber of replaced faces: " << aTool.NbReplacedFaces();
const TopoDS_Shape& Result = aTool.Shape();
DBRep::Set(a[1], Result);
}
return 0;
}
//=======================================================================
//function : InitCommands
//purpose :
@@ -1591,4 +1655,7 @@ static Standard_Integer reshape(Draw_Interpretor& /*theDI*/,
"\n '-remove what' Removes 'what' sub-shape"
"\n Requests '-replace' and '-remove' can be repeated many times.",
__FILE__, reshape, g);
theCommands.Add("combinetocylinder",
"run w/o arguments to get help", __FILE__, CombineToCylinder, g);
}

View File

@@ -4,6 +4,8 @@ ShapeUpgrade_ClosedEdgeDivide.cxx
ShapeUpgrade_ClosedEdgeDivide.hxx
ShapeUpgrade_ClosedFaceDivide.cxx
ShapeUpgrade_ClosedFaceDivide.hxx
ShapeUpgrade_CombineToCylinder.cxx
ShapeUpgrade_CombineToCylinder.hxx
ShapeUpgrade_ConvertCurve2dToBezier.cxx
ShapeUpgrade_ConvertCurve2dToBezier.hxx
ShapeUpgrade_ConvertCurve3dToBezier.cxx

View File

@@ -0,0 +1,901 @@
//-Copyright: Open CASCADE 2016
// Created on: 2016-08-01
// Created by: Mikhail Sazonov
// Copyright (c) 2016 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 <ShapeUpgrade_CombineToCylinder.hxx>
#include <BRep_Builder.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepTools.hxx>
#include <BRepTools_ReShape.hxx>
#include <ElCLib.hxx>
#include <GCPnts_AbscissaPoint.hxx>
#include <Geom_Circle.hxx>
#include <Geom_BSplineCurve.hxx>
#include <GeomAPI_PointsToBSpline.hxx>
#include <gce_MakeCirc.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax3.hxx>
#include <gp_Circ.hxx>
#include <gp_Cylinder.hxx>
#include <gp_Pln.hxx>
#include <IntAna_IntConicQuad.hxx>
#include <ShapeAnalysis_Curve.hxx>
#include <ShapeFix_Shape.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <Precision.hxx>
//=======================================================================
//function : ShapeUpgrade_CombineToCylinder
//purpose :
//=======================================================================
ShapeUpgrade_CombineToCylinder::ShapeUpgrade_CombineToCylinder()
: myLinTol(Precision::Confusion()),
myAngTol(Precision::Angular()),
myNbNewFaces(0),
myNbReplacedFaces(0),
myDone(Standard_False)
{
myContext = new BRepTools_ReShape;
}
//=======================================================================
//function : sortEdges
//purpose :
//=======================================================================
static void sortEdges(const TopoDS_Shape& theShape,
const TopTools_IndexedDataMapOfShapeListOfShape& theMapEF,
const Standard_Real theLinTol,
const Standard_Real theAngTol,
TopTools_MapOfShape& theStopEdges,
NCollection_DataMap<TopoDS_Shape,gp_Cylinder>& theMapECyl)
{
TopExp_Explorer anEx(theShape, TopAbs_EDGE);
for (; anEx.More(); anEx.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge(anEx.Current());
const TopTools_ListOfShape* pFaces = theMapEF.Seek(anEdge);
if (!pFaces)
continue;
// check for manifold edge
if (pFaces->Extent() != 2)
{
theStopEdges.Add(anEdge);
continue;
}
// Get curve of the edge and check if it is a line
BRepAdaptor_Curve aCurve(anEdge);
if (aCurve.GetType() != GeomAbs_Line)
{
theStopEdges.Add(anEdge);
continue;
}
// Check if the edge has enough length
Standard_Real aLength = GCPnts_AbscissaPoint::Length(aCurve);
if (aLength < 2.*theLinTol)
{
theStopEdges.Add(anEdge);
continue;
}
// check that both faces are planar, if no then add the edge to stop list
TopoDS_Face aFaces[2] = { TopoDS::Face(pFaces->First()), TopoDS::Face(pFaces->Last()) };
BRepAdaptor_Surface aSurf[2] = {
BRepAdaptor_Surface(aFaces[0], Standard_False),
BRepAdaptor_Surface(aFaces[1], Standard_False) };
if (aSurf[0].GetType() != GeomAbs_Plane || aSurf[1].GetType() != GeomAbs_Plane)
{
theStopEdges.Add(anEdge);
continue;
}
// check if edge is sharp, if yes then add it to stop list
gp_Pln aPl1 = aSurf[0].Plane();
gp_Pln aPl2 = aSurf[1].Plane();
if (aPl1.Axis().Direction().Angle(aPl2.Axis().Direction()) > theAngTol)
{
theStopEdges.Add(anEdge);
continue;
}
// Create plane perpendicular to the edge
gp_Lin aLin = aCurve.Line();
gp_Pln aPln(aLin.Location(), aLin.Direction());
// Get opposite edges on each face
TopoDS_Edge anOpEdges[2];
gp_Lin anOpLines[2];
Standard_Integer i;
for (i = 0; i < 2; i++)
{
TopExp_Explorer anEx1(aFaces[i], TopAbs_EDGE);
Standard_Integer nbE = 0;
for (; anEx1.More(); anEx1.Next(), nbE++)
{
if (anOpEdges[i].IsNull())
{
const TopoDS_Edge& aE = TopoDS::Edge(anEx1.Current());
if (!aE.IsSame(anEdge))
{
BRepAdaptor_Curve aC(aE);
if (aC.GetType() == GeomAbs_Line)
{
gp_Lin aL = aC.Line();
if (aL.Direction().IsParallel(aLin.Direction(), theAngTol))
{
anOpEdges[i] = aE;
anOpLines[i] = aL;
}
}
}
}
}
if (nbE != 4)
break; // face has non-rectangular form
}
if (anOpEdges[0].IsNull() || anOpEdges[1].IsNull())
{
theStopEdges.Add(anEdge);
continue;
}
// intersect all 3 edges with the plane
gp_Lin aLines[3] = { anOpLines[0], aLin, anOpLines[1] };
gp_Pnt anIntPnt[3];
for (i = 0; i < 3; i++)
{
IntAna_IntConicQuad anInter(aLines[i], aPln, theAngTol);
if (!anInter.IsDone() || anInter.NbPoints() != 1)
break;
anIntPnt[i] = anInter.Point(1);
}
if (i < 3)
{
theStopEdges.Add(anEdge);
continue;
}
// check that distances to points on opposite edges are equal
Standard_Real aDist1 = anIntPnt[0].Distance(anIntPnt[1]);
Standard_Real aDist2 = anIntPnt[2].Distance(anIntPnt[1]);
if (fabs(aDist1 - aDist2) > theLinTol)
{
theStopEdges.Add(anEdge);
continue;
}
// compute the circle radius
gce_MakeCirc aCircMaker(anIntPnt[0], anIntPnt[1], anIntPnt[2]);
if (!aCircMaker.IsDone())
{
theStopEdges.Add(anEdge);
continue;
}
Standard_Real aRadius = aCircMaker.Value().Radius();
const gp_Ax1& aCylAxis = aCircMaker.Value().Axis();
gp_Cylinder aCyl(gp_Ax3(aCylAxis.Location(), aCylAxis.Direction()), aRadius);
theMapECyl.Bind(anEdge, aCyl);
}
}
//=======================================================================
//function : updateBoundary
//purpose :
//=======================================================================
static void updateBoundary(TopTools_ListOfShape& theBoundary,
const TopoDS_Shape& theFace,
const TopoDS_Shape& theConnectingEdge,
const TopTools_MapOfShape& theStopEdges)
{
// iterate on all edges of the face
TopExp_Explorer anEx(theFace, TopAbs_EDGE);
for (; anEx.More(); anEx.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge(anEx.Current());
if (anEdge.IsSame(theConnectingEdge) || theStopEdges.Contains(anEdge))
continue; // skip stop edges
// find this edge in the boundary
TopTools_ListIteratorOfListOfShape anIt(theBoundary);
while (anIt.More())
{
if (anIt.Value().IsSame(anEdge))
break;
anIt.Next();
}
if (anIt.More())
{
// found, remove it from boundary
theBoundary.Remove(anIt);
}
else
{
// not found, add to boundary
theBoundary.Append(anEdge);
}
}
}
//=======================================================================
//function : Auxiliary structures
//purpose :
//=======================================================================
namespace CombineToCylinder
{
struct Area
{
TopoDS_Compound Faces;
const gp_Cylinder* pCylinder;
Standard_Integer nbFaces;
Area() : pCylinder(0L), nbFaces(0)
{}
void Init()
{
Faces.Nullify();
nbFaces = 0;
BRep_Builder().MakeCompound(Faces);
}
void AddFace(const TopoDS_Shape& theFace)
{
BRep_Builder().Add(Faces, theFace);
nbFaces++;
}
};
}
//=======================================================================
//function : EqualCylinders
//purpose :
//=======================================================================
inline Standard_Boolean EqualCylinders(const gp_Cylinder& theCyl1,
const gp_Cylinder& theCyl2,
const Standard_Real theLinTol,
const Standard_Real theAngTol)
{
// check radii
if (fabs(theCyl1.Radius() - theCyl2.Radius()) > theLinTol)
return Standard_False;
// check if parallel
if (!theCyl1.Axis().Direction().IsParallel(theCyl2.Axis().Direction(), theAngTol))
return Standard_False;
// check distance between axes
gp_XYZ aVecO1O2 = theCyl2.Location().XYZ() - theCyl1.Location().XYZ();
Standard_Real aDist1 = aVecO1O2.CrossSquareMagnitude(theCyl2.Axis().Direction().XYZ());
Standard_Real aDist2 = aVecO1O2.CrossSquareMagnitude(theCyl1.Axis().Direction().XYZ());
Standard_Real aTol = theLinTol * theLinTol;
return aDist1 <= aTol && aDist2 < aTol;
}
//=======================================================================
//function : collectAreas
//purpose :
//=======================================================================
static void collectAreas(const TopoDS_Shape& theShape,
const TopTools_IndexedDataMapOfShapeListOfShape& theMapEF,
const TopTools_MapOfShape& theStopEdges,
const NCollection_DataMap<TopoDS_Shape, gp_Cylinder>& theMapECyl,
const Standard_Real theLinTol,
const Standard_Real theAngTol,
NCollection_List<CombineToCylinder::Area>& theAreas)
{
TopTools_MapOfShape aPassedFaces;
// Repeat while there are unprocessed faces
for (;;)
{
// get first unprocessed face
TopoDS_Shape aCurFace;
TopExp_Explorer anEx(theShape, TopAbs_FACE);
for (; anEx.More(); anEx.Next())
{
aCurFace = anEx.Current();
if (!aPassedFaces.Contains(aCurFace))
break;
}
if (!anEx.More())
break; // all are processed, stop
// Start area with it
CombineToCylinder::Area anArea;
anArea.Init();
anArea.AddFace(aCurFace);
aPassedFaces.Add(aCurFace);
// Define edges of boundary of area
TopTools_ListOfShape aBoundary;
updateBoundary(aBoundary, aCurFace, TopoDS_Shape(), theStopEdges);
// Add all neighbors to the area while there are unprocessed edges of boundary
while (!aBoundary.IsEmpty())
{
TopTools_ListIteratorOfListOfShape anIt(aBoundary);
while (anIt.More())
{
const TopoDS_Shape& anEdge = anIt.Value();
const gp_Cylinder* pCyl = theMapECyl.Seek(anEdge);
const TopTools_ListOfShape* pFaces = theMapEF.Seek(anEdge);
Standard_ASSERT_RAISE(pCyl && pFaces && pFaces->Extent() == 2, "collectAreas");
if (!anArea.pCylinder || EqualCylinders(*anArea.pCylinder, *pCyl, theLinTol, theAngTol))
{
anArea.pCylinder = pCyl;
aCurFace = (aPassedFaces.Contains(pFaces->First()) ? pFaces->Last() : pFaces->First());
if (!aPassedFaces.Contains(aCurFace))
{
// Update boundary adding the next face
updateBoundary(aBoundary, aCurFace, anEdge, theStopEdges);
anArea.AddFace(aCurFace);
aPassedFaces.Add(aCurFace);
}
}
aBoundary.Remove(anIt);
}
}
// check if area is well formed
if (anArea.pCylinder && anArea.nbFaces > 2)
{
// Add area to the result list
theAreas.Append(anArea);
}
}
}
//=======================================================================
//function : getNextEdge
//purpose :
//=======================================================================
static Standard_Boolean getNextEdge(const TopTools_ListOfShape& theChain,
const Standard_Boolean theFwd,
const TopTools_IndexedDataMapOfShapeListOfShape& theMapVE,
const Standard_Real theSmoothAng,
TopoDS_Edge& theNextEdge)
{
// Get end edge and vertex
TopoDS_Edge anEndE, anOppoEdge;
TopoDS_Vertex anEndV;
if (theFwd)
{
anEndE = TopoDS::Edge(theChain.Last());
anOppoEdge = TopoDS::Edge(theChain.First());
anEndV = TopExp::LastVertex(anEndE, Standard_True);
}
else
{
anEndE = TopoDS::Edge(theChain.First());
anOppoEdge = TopoDS::Edge(theChain.Last());
anEndV = TopExp::FirstVertex(anEndE, Standard_True);
}
// Get next edge using topology map; reject the case of multi-connected vertex,
// when there are more than one candidate edge
const TopTools_ListOfShape& aConnEdges = theMapVE.FindFromKey(anEndV);
// Note! aConnEdges can contain duplicates
theNextEdge.Nullify();
TopTools_ListIteratorOfListOfShape itL(aConnEdges);
for (; itL.More(); itL.Next())
{
const TopoDS_Shape& aE = itL.Value();
if (aE.IsSame(anEndE))
continue;
if (theNextEdge.IsNull())
theNextEdge = TopoDS::Edge(aE);
else if(!aE.IsSame(theNextEdge))
return Standard_False; // multi-connected vertex
}
// check for closed chain
if (theNextEdge.IsSame(anOppoEdge))
return Standard_False;
// Orient the next edge
TopoDS_Vertex aNextEndV = (theFwd ? TopExp::FirstVertex(theNextEdge, Standard_True) :
TopExp::LastVertex(theNextEdge, Standard_True));
if (!aNextEndV.IsSame(anEndV))
theNextEdge.Reverse();
if (theSmoothAng > 0.)
{
// Check that the edge is linear
BRepAdaptor_Curve aNextC(theNextEdge);
if (aNextC.GetType() != GeomAbs_Line)
return Standard_False;
// Verify smoothness of connection
BRepAdaptor_Curve anEndC(anEndE);
gp_Lin anEndLin = anEndC.Line();
gp_Lin aNextLin = aNextC.Line();
const gp_Dir& anEndDir = anEndLin.Direction();
const gp_Dir& aNextDir = aNextLin.Direction();
if (!anEndDir.IsParallel(aNextDir, theSmoothAng))
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : makeEdgesChain
//purpose :
//=======================================================================
static void makeEdgesChain(TopTools_ListOfShape& theChain,
const TopTools_IndexedDataMapOfShapeListOfShape& theMapVE,
const Standard_Real theSmoothAng)
{
// Cycle for both ends of the chain
Standard_Boolean isFwd[2] = { Standard_True, Standard_False };
for (Standard_Integer i = 0; i < 2; i++)
{
TopoDS_Edge aNextEdge;
while (getNextEdge(theChain, isFwd[i], theMapVE, theSmoothAng, aNextEdge))
{
// add next edge to the chain
if (isFwd[i])
theChain.Append(aNextEdge);
else
theChain.Prepend(aNextEdge);
}
}
}
//=======================================================================
//function : createCylFaceFromArea
//purpose :
//=======================================================================
static TopoDS_Face createCylFaceFromArea(const TopoDS_Compound& theFaces,
const gp_Cylinder& theCylinder)
{
// Find boundary edges of the area
TopTools_IndexedDataMapOfShapeListOfShape aMapEF, aMapVE;
TopExp::MapShapesAndAncestors(theFaces, TopAbs_EDGE, TopAbs_FACE, aMapEF);
TopTools_ListOfShape aBoundary;
Standard_Integer i;
for (i = 1; i <= aMapEF.Extent(); i++)
{
if (aMapEF(i).Extent() == 1)
{
const TopoDS_Shape& aE = aMapEF.FindKey(i);
aBoundary.Append(aE);
TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
}
}
// Check the case of closed cylinder. In this case there will be two
// distinct chains of boundary edges, and we need to create a seam edge
TopoDS_Edge aSeamEdge;
TopTools_ListOfShape aChain;
aChain.Append(aBoundary.First());
makeEdgesChain(aChain, aMapVE, 0.);
TopTools_MapOfShape aMapChain;
TopTools_ListIteratorOfListOfShape itC(aChain);
for (; itC.More(); itC.Next())
aMapChain.Add(itC.Value());
TopTools_ListIteratorOfListOfShape itB(aBoundary);
for (; itB.More(); itB.Next())
{
if (!aMapChain.Contains(itB.Value()))
break;
}
if (itB.More())
{
// It is the case.
// Get any multi-connected edge and use it as a seam
for (i = 1; i <= aMapEF.Extent(); i++)
if (aMapEF(i).Extent() == 2)
aSeamEdge = TopoDS::Edge(aMapEF.FindKey(i));
}
// Build new cylindrical face
TopoDS_Wire aWire;
BRep_Builder().MakeWire(aWire);
for (itB.Init(aBoundary); itB.More(); itB.Next())
{
BRep_Builder().Add(aWire, itB.Value());
}
if (!aSeamEdge.IsNull())
{
BRep_Builder().Add(aWire, aSeamEdge);
BRep_Builder().Add(aWire, aSeamEdge.Reversed());
}
TopoDS_Face aCylFace = BRepBuilderAPI_MakeFace(theCylinder, aWire);
// Check orientation of an initial face, so that possibly to reverse the new face.
// The new cylindrical surface always has normal directed outside of cylinder.
// If an initial face has normal (taking face orientation into account) directed
// inside then we must reverse the new face.
const TopoDS_Edge& aE = TopoDS::Edge(aBoundary.First());
const TopoDS_Face& aF = TopoDS::Face(aMapEF.FindFromKey(aE).First());
BRepAdaptor_Surface aSurf(aF, Standard_False);
Standard_Real aParF, aParL;
Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(aE, aF, aParF, aParL);
Standard_ASSERT_RAISE(!aPCurve.IsNull(), "createCylFaceFromArea");
gp_Pnt2d aP2d = aPCurve->Value(aParF);
gp_Pnt aP;
gp_Vec aDU, aDV;
aSurf.D1(aP2d.X(), aP2d.Y(), aP, aDU, aDV);
gp_XYZ aN = aDU.XYZ() ^ aDV.XYZ();
if (aF.Orientation() == TopAbs_REVERSED)
aN.Reverse();
gp_XYZ aVecFromAxis = aP.XYZ() - theCylinder.Location().XYZ();
if (aVecFromAxis * aN < 0.)
{
// need reverse
aCylFace.Reverse();
}
return aCylFace;
}
//=======================================================================
//function : updateVertexOnCirc
//purpose :
//=======================================================================
static Standard_Boolean updateVertexOnCirc(const TopoDS_Vertex& theV,
const gp_Circ& theCirc,
Standard_Real theMaxDist,
Standard_Real& thePar)
{
Standard_Real aTol = BRep_Tool::Tolerance(theV);
gp_Pnt aP = BRep_Tool::Pnt(theV);
thePar = ElCLib::Parameter(theCirc, aP);
gp_Pnt aProj = ElCLib::Value(thePar, theCirc);
Standard_Real aDist = aProj.SquareDistance(aP);
Standard_Boolean isOK = Standard_False;
if (aDist > aTol*aTol)
{
if (aDist < theMaxDist*theMaxDist)
{
BRep_Builder().UpdateVertex(theV, sqrt(aDist)*1.001);
isOK = Standard_True;
}
}
return isOK;
}
//=======================================================================
//function : createCurveEdge
//purpose :
//=======================================================================
static TopoDS_Edge createCurveEdge(const TopTools_ListOfShape& theChain,
const TopTools_IndexedDataMapOfShapeListOfShape& theMapEF,
const Standard_Real theLinTol)
{
// Find a cylindrical face common for all edges
TopTools_ListOfShape aCylFaces;
TopTools_ListIteratorOfListOfShape itL(theChain);
for (; itL.More(); itL.Next())
{
const TopoDS_Shape& aE = itL.Value();
const TopTools_ListOfShape& aFaces = theMapEF.FindFromKey(aE);
// get cyl faces of the current edge
TopTools_ListOfShape aCurCylFaces;
TopTools_ListIteratorOfListOfShape itF(aFaces);
for (; itF.More(); itF.Next())
{
const TopoDS_Face& aF = TopoDS::Face(itF.Value());
BRepAdaptor_Surface aSurf(aF, Standard_False);
if (aSurf.GetType() == GeomAbs_Cylinder)
aCurCylFaces.Append(aF);
}
if (aCylFaces.IsEmpty())
// initialize cyl faces with the first edge
aCylFaces.Append(aCurCylFaces);
else
{
// filter cyl faces leaving only common ones
TopTools_ListIteratorOfListOfShape itCF(aCylFaces);
while (itCF.More())
{
const TopoDS_Shape& aF = itCF.Value();
TopTools_ListIteratorOfListOfShape itCF1(aCurCylFaces);
for (; itCF1.More(); itCF1.Next())
if (itCF1.Value().IsSame(aF))
break;
if (!itCF1.More())
aCylFaces.Remove(itCF);
else
itCF.Next();
}
}
if (aCylFaces.IsEmpty())
return TopoDS_Edge(); // no common cyl faces
}
if (aCylFaces.IsEmpty())
return TopoDS_Edge();
const TopoDS_Face& aCylFace = TopoDS::Face(aCylFaces.First());
BRepAdaptor_Surface aCylSurf(aCylFace, Standard_False);
gp_Cylinder aCyl = aCylSurf.Cylinder();
const gp_Dir& aCylDir = aCyl.Axis().Direction();
const gp_Pnt& aCylLoc = aCyl.Location();
const Standard_Real aRadius = aCyl.Radius();
// Check if the chain is closed
TopoDS_Vertex aVF, aVL;
aVF = TopoDS::Vertex(TopExp::FirstVertex(TopoDS::Edge(theChain.First()), Standard_True));
aVL = TopoDS::Vertex(TopExp::LastVertex(TopoDS::Edge(theChain.Last()), Standard_True));
Standard_Boolean isClosed = aVF.IsSame(aVL);
// Check if all points are in plane perpendicular to the cylinder axis;
// in such case the curve is a circle
TColgp_Array1OfPnt aPnts(1, theChain.Extent()+1);
Standard_Real aTol = 0.;
Standard_Integer i = 1;
for (itL.Init(theChain); itL.More(); itL.Next(), i++)
{
const TopoDS_Edge& aE = TopoDS::Edge(itL.Value());
TopoDS_Shape aV = TopExp::FirstVertex(aE, Standard_True);
aPnts(i) = BRep_Tool::Pnt(TopoDS::Vertex(aV));
aTol = Max(aTol, BRep_Tool::Tolerance(aE));
}
aPnts(i) = BRep_Tool::Pnt(aVL);
gp_XYZ aMidPnt(0, 0, 0);
for (i = 1; i <= aPnts.Length(); i++)
aMidPnt += aPnts(i).XYZ();
aMidPnt /= aPnts.Length();
aTol = Min(aTol, theLinTol);
for (i = 1; i <= aPnts.Length(); i++)
{
Standard_Real aDist = fabs((aPnts(i).XYZ() - aMidPnt) * aCylDir.XYZ());
if (aDist > aTol)
break;
}
Standard_Boolean isCircle = (i > aPnts.Length());
// Create new edge
TopoDS_Edge aNewEdge;
if (isCircle)
{
// Create circular edge.
// Find center by projecting aMidPnt to the cylinder axis
gp_XYZ aVecOM = aMidPnt - aCylLoc.XYZ();
gp_Pnt aCenter = aCylLoc.Translated(aCylDir.XYZ() * (aVecOM * aCylDir.XYZ()));
gp_XYZ aXDir = aPnts(1).XYZ() - aCenter.XYZ();
gp_XYZ aCircDir = aCylDir.XYZ();
gp_XYZ aTanDir = aPnts(2).XYZ() - aPnts(1).XYZ();
if ((aXDir ^ aTanDir)* aCylDir.XYZ() < 0.)
aCircDir.Reverse();
gp_Circ aCirc(gp_Ax2(aCenter, aCircDir, aXDir), aRadius);
Handle(Geom_Circle) aCurve = new Geom_Circle(aCirc);
// update vertices tolerance, but not more than on a value aTol,
// otherwise skip building a circle, and build bspline.
Standard_Real aPar;
if (updateVertexOnCirc(aVF, aCirc, aTol, aPar))
{
if (isClosed)
{
// full circle
aNewEdge = BRepBuilderAPI_MakeEdge(aCurve, aVF, aVL, 0, M_PI*2.);
}
else
{
// an arc
if (updateVertexOnCirc(aVL, aCirc, aTol, aPar))
aNewEdge = BRepBuilderAPI_MakeEdge(aCurve, aVF, aVL, 0., aPar);
}
}
}
if (aNewEdge.IsNull())
{
// not a circle, try building bspline
gp_Pnt aPnts1[3];
const gp_Pnt* pPnts = &aPnts(1);
Standard_Integer np = aPnts.Length();
if (np == 2)
{
gp_XYZ anEdgeDir = aPnts(2).XYZ() - aPnts(1).XYZ();
const Standard_Real anEpsAng = 1e-4;
if (aCylDir.IsParallel(anEdgeDir, anEpsAng))
return aNewEdge;
// we have only two points; create additional point in the middle of the segment
aPnts1[0] = aPnts(1);
aPnts1[2] = aPnts(2);
aPnts1[1] = (aPnts1[0].XYZ() + aPnts1[2].XYZ()) * 0.5;
pPnts = aPnts1;
np = 3;
}
TColgp_Array1OfPnt aPntA(*pPnts, 1, np);
// Create b-spline curve
Standard_Integer aDegMin = 3;
Standard_Integer aDegMax = 3;
GeomAbs_Shape aCont = GeomAbs_C2;
GeomAPI_PointsToBSpline aCreator(aPntA, aDegMin, aDegMax, aCont, aTol);
if (aCreator.IsDone())
{
const Handle(Geom_BSplineCurve)& aCurve = aCreator.Curve();
Standard_Real aTol = BRep_Tool::Tolerance(aVF);
Standard_Real aParF = aCurve->FirstParameter();
Standard_Real aParL = aCurve->LastParameter();
Standard_Real aDist = aCurve->Value(aParF).SquareDistance(aPntA(1));
if (aDist > aTol*aTol)
BRep_Builder().UpdateVertex(aVF, sqrt(aDist));
if (!isClosed)
{
aTol = BRep_Tool::Tolerance(aVL);
aDist = aCurve->Value(aParL).SquareDistance(aPntA(np));
if (aDist > aTol*aTol)
BRep_Builder().UpdateVertex(aVL, sqrt(aDist));
}
aNewEdge = BRepBuilderAPI_MakeEdge(aCurve, aVF, aVL, aParF, aParL);
}
}
return aNewEdge;
}
//=======================================================================
//function : mergeEdges
//purpose :
//=======================================================================
static void mergeEdges(const TopoDS_Shape& theShape,
const Standard_Real theLinTol,
const Standard_Real theAngTol,
const Handle(BRepTools_ReShape)& theContext)
{
// Create topological data maps
TopTools_IndexedDataMapOfShapeListOfShape aMapVE, aMapEF;
TopExp::MapShapesAndAncestors(theShape, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
TopExp::MapShapesAndAncestors(theShape, TopAbs_EDGE, TopAbs_FACE, aMapEF);
// The idea is to gather chains of edges in which all intermediate vertices
// have only two neighboring edges, and do not have connection to any other edges
// from the shape.
// Prepare set of all edges
TopTools_IndexedMapOfShape anEdges;
TopExp::MapShapes(theShape, TopAbs_EDGE, anEdges);
TColStd_MapOfInteger anEdgesInd; // set of indices of left edges
Standard_Integer i;
for (i = 1; i <= anEdges.Extent(); i++)
anEdgesInd.Add(i);
// Process while there are unprocessed edges
while (!anEdgesInd.IsEmpty())
{
// Get an unprocessed edge
Standard_Integer aEInd = TColStd_MapIteratorOfMapOfInteger(anEdgesInd).Value();
anEdgesInd.Remove(aEInd);
TopoDS_Edge aFirstEdge = TopoDS::Edge(anEdges(aEInd));
BRepAdaptor_Curve aCurve(aFirstEdge);
if (aCurve.GetType() != GeomAbs_Line)
continue; // only linear edges are to be merged
// Start a new chain
TopTools_ListOfShape aChain;
aChain.Append(aFirstEdge.Oriented(TopAbs_FORWARD));
makeEdgesChain(aChain, aMapVE, theAngTol);
// Remove it from the left edges
TopTools_ListIteratorOfListOfShape itL(aChain);
for (; itL.More(); itL.Next())
{
const TopoDS_Shape& aE = itL.Value();
Standard_Integer aEI = anEdges.FindIndex(aE);
anEdgesInd.Remove(aEI);
}
if (aChain.Extent() > 0)
{
// Create a new curvilinear edge from the polyline
TopoDS_Edge aNewEdge = createCurveEdge(aChain, aMapEF, theLinTol);
if (!aNewEdge.IsNull())
{
aNewEdge.Orientation(aFirstEdge.Orientation());
// Replace edges from the chain with the new edge.
Standard_Integer nbMerged = 0;
for (itL.Init(aChain); itL.More(); itL.Next(), nbMerged++)
{
const TopoDS_Shape& aE = itL.Value();
if (nbMerged == 0)
theContext->Replace(aE, aNewEdge);
else
theContext->Remove(aE);
}
}
}
}
}
//=======================================================================
//function : Build
//purpose :
//=======================================================================
void ShapeUpgrade_CombineToCylinder::Build()
{
myDone = Standard_False;
myNbNewFaces = myNbReplacedFaces = 0;
myShape.Nullify();
TopTools_IndexedDataMapOfShapeListOfShape aMapEF;
TopExp::MapShapesAndAncestors(myInitShape, TopAbs_EDGE, TopAbs_FACE, aMapEF);
// Sort edges in the shape on two groups - stop edges and smooth edges that are
// to be located on a cylinder wall parallel to its axis.
TopTools_MapOfShape aStopEdges;
NCollection_DataMap<TopoDS_Shape, gp_Cylinder> aMapECyl;
sortEdges(myInitShape, aMapEF, myLinTol, myAngTol, aStopEdges, aMapECyl);
#ifdef DEBUG_CombineToCylinder_StopEdges
TopoDS_Compound aCompE;
BRep_Builder().MakeCompound(aCompE);
TopTools_MapIteratorOfMapOfShape aMapIt(aStopEdges);
for (; aMapIt.More(); aMapIt.Next())
BRep_Builder().Add(aCompE, aMapIt.Value());
BRepTools::Write(aCompE, "stope.brep");
#endif
// Collect faces forming same-cylinder areas
NCollection_List<CombineToCylinder::Area> anAreas;
collectAreas(myInitShape, aMapEF, aStopEdges, aMapECyl, myLinTol, myAngTol, anAreas);
#ifdef DEBUG_CombineToCylinder_Areas
TopoDS_Compound aComp;
BRep_Builder().MakeCompound(aComp);
TopTools_ListIteratorOfListOfShape anItA(anAreas);
for (; anItA.More(); anItA.Next())
BRep_Builder().Add(aComp, anItA.Value());
BRepTools::Write(aComp, "areas.brep");
#endif
// Process each area
NCollection_List<CombineToCylinder::Area>::Iterator anItAreas(anAreas);
for (; anItAreas.More(); anItAreas.Next())
{
const CombineToCylinder::Area& anArea = anItAreas.Value();
if (!anArea.pCylinder)
continue;
TopoDS_Shape aCylFace = createCylFaceFromArea(anArea.Faces, *anArea.pCylinder);
// Replace faces from the list with the new face.
TopExp_Explorer anEx(anArea.Faces, TopAbs_FACE);
Standard_Integer nbMerged = 0;
for (; anEx.More(); anEx.Next(), nbMerged++)
{
const TopoDS_Shape& aFace = anEx.Current();
if (nbMerged == 0)
myContext->Replace(aFace, aCylFace);
else
myContext->Remove(aFace);
}
myNbNewFaces++;
myNbReplacedFaces += nbMerged;
}
// Build intermediate result shape using replacement context.
// This shape will contain chains of linear edges along cylinders
// instead of circles or whatever curves.
// The next step is to merge them.
TopoDS_Shape aTempShape = myContext->Apply(myInitShape);
mergeEdges(aTempShape, myLinTol, myAngTol, myContext);
// Rebuild the result shape using replacement context.
myShape = myContext->Apply(myInitShape);
// build pcurves
ShapeFix_Shape aFix(myShape);
aFix.Perform();
myShape = aFix.Shape();
myDone = Standard_True;
}

View File

@@ -0,0 +1,93 @@
//-Copyright: Open CASCADE 2016
// Created on: 2016-08-01
// Created by: Mikhail Sazonov
// Copyright (c) 2016 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 _ShapeUpgrade_CombineToCylinder_HeaderFile
#define _ShapeUpgrade_CombineToCylinder_HeaderFile
#include <Standard_TypeDef.hxx>
#include <TopoDS_Shape.hxx>
class BRepTools_ReShape;
//! This tool tries to merge planar faces constituting a cylindrical surface into one face.
//! The algorithm checks that all merged faces have smooth change of normal within the given
//! angular tolerance.
class ShapeUpgrade_CombineToCylinder
{
public:
//! empty constructor
Standard_EXPORT ShapeUpgrade_CombineToCylinder();
//! Sets input shape
void SetShape(const TopoDS_Shape& theShape)
{
myInitShape = theShape;
}
//! Sets the linear tolerance. Default value is Precision::Confusion().
void SetLinearTolerance(const Standard_Real theValue)
{
myLinTol = theValue;
}
//! Sets the angular tolerance. Default value is Precision::Angular().
void SetAngularTolerance(const Standard_Real theValue)
{
myAngTol = theValue;
}
//! Builds the resulting shape
Standard_EXPORT void Build();
//! Returns true if the result shape was successfully built.
Standard_Boolean IsDone() const
{
return myDone;
}
//! Returns the result shape.
const TopoDS_Shape& Shape() const
{
return myShape;
}
//! Returns the number of new faces built by merging
Standard_Integer NbNewFaces() const
{
return myNbNewFaces;
}
//! Returns the number of replaced faces
Standard_Integer NbReplacedFaces() const
{
return myNbReplacedFaces;
}
private:
TopoDS_Shape myInitShape;
Standard_Real myLinTol;
Standard_Real myAngTol;
TopoDS_Shape myShape;
Handle(BRepTools_ReShape) myContext;
Standard_Integer myNbNewFaces;
Standard_Integer myNbReplacedFaces;
Standard_Boolean myDone;
};
#endif // _ShapeUpgrade_CombineToCylinder_HeaderFile

View File

@@ -278,14 +278,15 @@ namespace
}
//! Prepare shaded presentation for specified shape
static Standard_Boolean shadeFromShape (const TopoDS_Shape& theShape,
const Handle(Prs3d_Presentation)& thePrs,
const Handle(Prs3d_Drawer)& theDrawer,
const Standard_Boolean theHasTexels,
const gp_Pnt2d& theUVOrigin,
const gp_Pnt2d& theUVRepeat,
const gp_Pnt2d& theUVScale,
const bool theIsClosed)
static Standard_Boolean shadeFromShape (const TopoDS_Shape& theShape,
const Handle(Prs3d_Presentation)& thePrs,
const Handle(Prs3d_Drawer)& theDrawer,
const Handle(Graphic3d_AspectFillCapping)& theCappingStyle,
const Standard_Boolean theHasTexels,
const gp_Pnt2d& theUVOrigin,
const gp_Pnt2d& theUVRepeat,
const gp_Pnt2d& theUVScale,
const bool theIsClosed)
{
Handle(Graphic3d_ArrayOfTriangles) aPArray = fillTriangles (theShape, theHasTexels, theUVOrigin, theUVRepeat, theUVScale);
if (aPArray.IsNull())
@@ -296,6 +297,9 @@ namespace
Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
aGroup->SetClosed (theIsClosed);
aGroup->SetGroupPrimitivesAspect (theDrawer->ShadingAspect()->Aspect());
if (!theCappingStyle.IsNull())
aGroup->SetGroupPrimitivesAspect (theCappingStyle);
aGroup->AddPrimitiveArray (aPArray);
return Standard_True;
}
@@ -498,28 +502,30 @@ void StdPrs_ShadedShape::ExploreSolids (const TopoDS_Shape& theShape,
// function : Add
// purpose :
// =======================================================================
void StdPrs_ShadedShape::Add (const Handle(Prs3d_Presentation)& thePrs,
const TopoDS_Shape& theShape,
const Handle(Prs3d_Drawer)& theDrawer,
const StdPrs_Volume theVolume)
void StdPrs_ShadedShape::Add (const Handle(Prs3d_Presentation)& thePrs,
const TopoDS_Shape& theShape,
const Handle(Prs3d_Drawer)& theDrawer,
const Handle(Graphic3d_AspectFillCapping)& theCappingStyle,
const StdPrs_Volume theVolume)
{
gp_Pnt2d aDummy;
StdPrs_ShadedShape::Add (thePrs, theShape, theDrawer,
Standard_False, aDummy, aDummy, aDummy, theVolume);
Standard_False, aDummy, aDummy, aDummy, theCappingStyle, theVolume);
}
// =======================================================================
// function : Add
// purpose :
// =======================================================================
void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs,
const TopoDS_Shape& theShape,
const Handle (Prs3d_Drawer)& theDrawer,
const Standard_Boolean theHasTexels,
const gp_Pnt2d& theUVOrigin,
const gp_Pnt2d& theUVRepeat,
const gp_Pnt2d& theUVScale,
const StdPrs_Volume theVolume)
void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs,
const TopoDS_Shape& theShape,
const Handle (Prs3d_Drawer)& theDrawer,
const Standard_Boolean theHasTexels,
const gp_Pnt2d& theUVOrigin,
const gp_Pnt2d& theUVRepeat,
const gp_Pnt2d& theUVScale,
const Handle(Graphic3d_AspectFillCapping)& theCappingStyle,
const StdPrs_Volume theVolume)
{
if (theShape.IsNull())
{
@@ -557,21 +563,21 @@ void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs,
TopoDS_Iterator aShapeIter (aClosed);
if (aShapeIter.More())
{
shadeFromShape (aClosed, thePrs, theDrawer,
shadeFromShape (aClosed, thePrs, theDrawer, theCappingStyle,
theHasTexels, theUVOrigin, theUVRepeat, theUVScale, true);
}
aShapeIter.Initialize (anOpened);
if (aShapeIter.More())
{
shadeFromShape (anOpened, thePrs, theDrawer,
shadeFromShape (anOpened, thePrs, theDrawer, theCappingStyle,
theHasTexels, theUVOrigin, theUVRepeat, theUVScale, false);
}
}
else
{
// if the shape type is not compound, composolid or solid, use autodetection back-facing filled
shadeFromShape (theShape, thePrs, theDrawer,
shadeFromShape (theShape, thePrs, theDrawer, theCappingStyle,
theHasTexels, theUVOrigin, theUVRepeat, theUVScale,
theVolume == StdPrs_Volume_Closed);
}

View File

@@ -43,13 +43,25 @@ public:
//! @param theVolumeType defines the way how to interpret input shapes - as Closed volumes (to activate back-face
//! culling and capping plane algorithms), as Open volumes (shells or solids with holes)
//! or to perform Autodetection (would split input shape into two groups)
Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation, const TopoDS_Shape& theShape, const Handle(Prs3d_Drawer)& theDrawer, const StdPrs_Volume theVolume = StdPrs_Volume_Autodetection);
Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation,
const TopoDS_Shape& theShape,
const Handle(Prs3d_Drawer)& theDrawer,
const Handle(Graphic3d_AspectFillCapping)& theCappingStyle = Handle(Graphic3d_AspectFillCapping)(),
StdPrs_Volume theVolume = StdPrs_Volume_Autodetection);
//! Shades <theShape> with texture coordinates.
//! @param theVolumeType defines the way how to interpret input shapes - as Closed volumes (to activate back-face
//! culling and capping plane algorithms), as Open volumes (shells or solids with holes)
//! or to perform Autodetection (would split input shape into two groups)
Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation, const TopoDS_Shape& theShape, const Handle(Prs3d_Drawer)& theDrawer, const Standard_Boolean theHasTexels, const gp_Pnt2d& theUVOrigin, const gp_Pnt2d& theUVRepeat, const gp_Pnt2d& theUVScale, const StdPrs_Volume theVolume = StdPrs_Volume_Autodetection);
Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation,
const TopoDS_Shape& theShape,
const Handle(Prs3d_Drawer)& theDrawer,
const Standard_Boolean theHasTexels,
const gp_Pnt2d& theUVOrigin,
const gp_Pnt2d& theUVRepeat,
const gp_Pnt2d& theUVScale,
const Handle(Graphic3d_AspectFillCapping)& theCappingStyle = Handle(Graphic3d_AspectFillCapping)(),
const StdPrs_Volume theVolume = StdPrs_Volume_Autodetection);
//! Searches closed and unclosed subshapes in shape structure and puts them
//! into two compounds for separate processing of closed and unclosed sub-shapes

View File

@@ -11,3 +11,5 @@ TKHLR
TKService
TKGeomAlgo
TKV3d
TKSTL
TKShHealing

View File

@@ -24,3 +24,4 @@ TKDCAF
TKViewerTest
TKBinXCAF
TKXmlXCAF
TKVRML

View File

@@ -8491,6 +8491,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
{
aClipPlane->SetCapping (toEnable);
anArgIter += 1;
}
else
@@ -8511,7 +8512,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
{
aClipPlane->SetUseObjectMaterial (toEnable == Standard_True);
aClipPlane->CappingSectionStyle()->SetUseObjectMaterial (toEnable == Standard_True);
anArgIter += 1;
}
}
@@ -8528,7 +8529,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
{
aClipPlane->SetUseObjectTexture (toEnable == Standard_True);
aClipPlane->CappingSectionStyle()->SetUseObjectTexture (toEnable == Standard_True);
anArgIter += 1;
}
}
@@ -8543,7 +8544,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
{
aClipPlane->SetUseObjectShader (toEnable == Standard_True);
aClipPlane->CappingSectionStyle()->SetUseObjectShader (toEnable == Standard_True);
anArgIter += 1;
}
}
@@ -8560,14 +8561,29 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
return 1;
}
Graphic3d_MaterialAspect aMat = aClipPlane->CappingMaterial();
Graphic3d_MaterialAspect aMat = aClipPlane->CappingSectionStyle()->Material();
aMat.SetAmbientColor (aColor);
aMat.SetDiffuseColor (aColor);
aClipPlane->SetCappingMaterial (aMat);
aClipPlane->CappingSectionStyle()->SetMaterial (aMat);
anArgIter += aNbParsed;
}
else if (aChangeArg == "-texname"
|| aChangeArg == "texname")
else if (aChangeArg == "-overrideaspect"
|| aChangeArg == "overrideaspect")
{
if (aNbChangeArgs < 2)
{
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
{
aClipPlane->SetToOverrideCappingAspect (toEnable == Standard_True);
anArgIter += 1;
}
}
else if (aChangeArg == "-texture"
|| aChangeArg == "texture")
{
if (aNbChangeArgs < 2)
{
@@ -8579,20 +8595,22 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
if (!aTexture->IsDone())
{
aClipPlane->SetCappingTexture (NULL);
aClipPlane->CappingSectionStyle()->SetTexture (Handle(Graphic3d_TextureMap)());
}
else
{
aTexture->EnableModulate();
aTexture->EnableRepeat();
aClipPlane->SetCappingTexture (aTexture);
aClipPlane->CappingSectionStyle()->SetTexture (aTexture.get());
}
anArgIter += 1;
}
else if (aChangeArg == "-texscale"
|| aChangeArg == "texscale")
{
if (aClipPlane->CappingTexture().IsNull())
const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->Texture();
if (aHatchTexture.IsNull())
{
std::cout << "Error: no texture is set.\n";
return 1;
@@ -8606,13 +8624,15 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
aClipPlane->CappingTexture()->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
aHatchTexture->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
anArgIter += 2;
}
else if (aChangeArg == "-texorigin"
|| aChangeArg == "texorigin") // texture origin
{
if (aClipPlane->CappingTexture().IsNull())
const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->Texture();
if (aHatchTexture.IsNull())
{
std::cout << "Error: no texture is set.\n";
return 1;
@@ -8627,13 +8647,15 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
aClipPlane->CappingTexture()->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
aHatchTexture->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
anArgIter += 2;
}
else if (aChangeArg == "-texrotate"
|| aChangeArg == "texrotate") // texture rotation
{
if (aClipPlane->CappingTexture().IsNull())
const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->Texture();
if (aHatchTexture.IsNull())
{
std::cout << "Error: no texture is set.\n";
return 1;
@@ -8646,7 +8668,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
}
Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
aClipPlane->CappingTexture()->GetParams()->SetRotation (aRot);
aHatchTexture->GetParams()->SetRotation (aRot);
anArgIter += 1;
}
else if (aChangeArg == "-hatch"
@@ -8658,22 +8680,165 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
return 1;
}
TCollection_AsciiString aHatchStr (aChangeArgs[1]);
aHatchStr.LowerCase();
if (aHatchStr == "on")
if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
{
aClipPlane->SetCappingHatchOn();
aClipPlane->CappingSectionStyle()->SetToDrawHatch (toEnable == Standard_True);
anArgIter += 1;
}
else if (aHatchStr == "off")
}
else if (aChangeArg == "-hatchtexture"
|| aChangeArg == "hatchtexture")
{
if (aNbChangeArgs < 2)
{
aClipPlane->SetCappingHatchOff();
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
TCollection_AsciiString aTextureName (aChangeArgs[1]);
Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
if (!aTexture->IsDone())
{
aClipPlane->CappingSectionStyle()->SetHatchStyle (Handle(Graphic3d_TextureMap)());
}
else
{
aClipPlane->SetCappingHatch ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
aTexture->EnableModulate();
aTexture->EnableRepeat();
aClipPlane->CappingSectionStyle()->SetHatchStyle (aTexture.get());
aClipPlane->CappingSectionStyle()->SetToDrawHatch (true);
}
anArgIter += 1;
}
else if (aChangeArg == "-hatchstipple"
|| aChangeArg == "hatchstipple")
{
if (aNbChangeArgs < 2)
{
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
aClipPlane->CappingSectionStyle()->SetHatchStyle ((Aspect_HatchStyle)Draw::Atoi (aChangeArgs[1]));
aClipPlane->CappingSectionStyle()->SetToDrawHatch (true);
anArgIter += 1;
}
else if (aChangeArg == "-hatchcolor"
|| aChangeArg == "hatchcolor")
{
Quantity_Color aColor;
Standard_Integer aNbParsed = ViewerTest::ParseColor (aNbChangeArgs - 1,
aChangeArgs + 1,
aColor);
if (aNbParsed == 0)
{
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
Graphic3d_MaterialAspect aMat = aClipPlane->CappingSectionStyle()->HatchMaterial();
aMat.SetAmbientColor (aColor);
aMat.SetDiffuseColor (aColor);
aClipPlane->CappingSectionStyle()->SetHatchMaterial (aMat);
anArgIter += aNbParsed;
}
else if (aChangeArg == "-hatchscale"
|| aChangeArg == "hatchscale")
{
const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->TextureHatch();
if (aHatchTexture.IsNull())
{
std::cout << "Error: no texture is set.\n";
return 1;
}
if (aNbChangeArgs < 3)
{
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
Standard_ShortReal aSx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
Standard_ShortReal aSy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
aHatchTexture->GetParams()->SetScale (Graphic3d_Vec2 (aSx, aSy));
anArgIter += 2;
}
else if (aChangeArg == "-hatchorigin"
|| aChangeArg == "hatchorigin") // texture origin
{
const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->TextureHatch();
if (aHatchTexture.IsNull())
{
std::cout << "Error: no texture is set.\n";
return 1;
}
if (aNbChangeArgs < 3)
{
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
Standard_ShortReal aTx = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
Standard_ShortReal aTy = (Standard_ShortReal)Draw::Atof (aChangeArgs[2]);
aHatchTexture->GetParams()->SetTranslation (Graphic3d_Vec2 (aTx, aTy));
anArgIter += 2;
}
else if (aChangeArg == "-hatchrotate"
|| aChangeArg == "hatchrotate") // texture rotation
{
const Handle(Graphic3d_TextureMap)& aHatchTexture = aClipPlane->CappingSectionStyle()->TextureHatch();
if (aHatchTexture.IsNull())
{
std::cout << "Error: no texture is set.\n";
return 1;
}
if (aNbChangeArgs < 2)
{
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
Standard_ShortReal aRot = (Standard_ShortReal)Draw::Atof (aChangeArgs[1]);
aHatchTexture->GetParams()->SetRotation (aRot);
anArgIter += 1;
}
else if (aChangeArg == "-hatchzoompers"
|| aChangeArg == "hatchzoompers")
{
if (aNbChangeArgs < 2)
{
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
{
aClipPlane->CappingSectionStyle()->SetHatchZoomPeristent (toEnable == Standard_True);
anArgIter += 1;
}
}
else if (aChangeArg == "-hatchrotatepers"
|| aChangeArg == "hatchrotatepers")
{
if (aNbChangeArgs < 2)
{
std::cout << "Syntax error: need more arguments.\n";
return 1;
}
if (ViewerTest::ParseOnOff (aChangeArgs[1], toEnable))
{
aClipPlane->CappingSectionStyle()->SetHatchRotationPeristent (toEnable == Standard_True);
anArgIter += 1;
}
}
else if (aChangeArg == "-delete"
|| aChangeArg == "delete")
{
@@ -12397,11 +12562,18 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
"\n\t\t: [-set|-unset|-setOverrideGlobal [objects|views]]"
"\n\t\t: [-maxPlanes]"
"\n\t\t: [-capping {0|1}]"
"\n\t\t: [-color R G B] [-hatch {on|off|ID}]"
"\n\t\t: [-texName Texture] [-texScale SX SY] [-texOrigin TX TY]"
"\n\t\t: [-texRotate Angle]"
"\n\t\t: [-overrideAspect {0|1}]"
"\n\t\t: [-color R G B]"
"\n\t\t: [-texture Texture] [-texScale SX SY]"
"\n\t\t: [-texOrigin TX TY] [-texRotate Angle]"
"\n\t\t: [-hatch {on|off}] [-hatchStipple mask]"
"\n\t\t: [-hatchColor R G B] [-hatchTexture texture]"
"\n\t\t: [-hatchScale SX SY] [-hatchOrigin TX TY]"
"\n\t\t: [-hatchRotate Angle]"
"\n\t\t: [-hatchZoomPers {0|1}]"
"\n\t\t: [-hatchRotatePers {0|1}]"
"\n\t\t: [-useObjMaterial {0|1}] [-useObjTexture {0|1}]"
"\n\t\t: [-useObjShader {0|1}]"
"\n\t\t: [-useObjShader {0|1}]"
"\n\t\t: Clipping planes management:"
"\n\t\t: -maxPlanes print plane limit for view"
"\n\t\t: -delete delete plane with given name"
@@ -12412,12 +12584,21 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
"\n\t\t: -clone SourcePlane NewPlane clone the plane definition."
"\n\t\t: Capping options:"
"\n\t\t: -capping {off|on|0|1} turn capping on/off"
"\n\t\t: -overrideAspect override presentation aspect (if defined)"
"\n\t\t: -color R G B set capping color"
"\n\t\t: -texName Texture set capping texture"
"\n\t\t: -texture Texture set capping texture"
"\n\t\t: -texScale SX SY set capping tex scale"
"\n\t\t: -texOrigin TX TY set capping tex origin"
"\n\t\t: -texRotate Angle set capping tex rotation"
"\n\t\t: -hatch {on|off|ID} set capping hatching mask"
"\n\t\t: -hatch {on|off} turn on/off hatch style on capping"
"\n\t\t: -hatchStipple ID set stipple mask for drawing hatch"
"\n\t\t: -hatchColor R G B set color for hatch material"
"\n\t\t: -hatchTexture Texture set texture (semi-opaque) for drawing hatch"
"\n\t\t: -hatchScale SX SY set hatch texture scale"
"\n\t\t: -hatchOrigin TX TY set hatch texture origin"
"\n\t\t: -hatchRotate Angle set hatch texture rotation"
"\n\t\t: -hatchZoomPers allow hatch tetxure mapping to be constant when zooming"
"\n\t\t: -hatchRotatePers allow hatch tetxure mapping to be constant when rotating"
"\n\t\t: -useObjMaterial {off|on|0|1} use material of clipped object"
"\n\t\t: -useObjTexture {off|on|0|1} use texture of clipped object"
"\n\t\t: -useObjShader {off|on|0|1} use shader program of object",

View File

@@ -29,6 +29,26 @@
#include <Poly.hxx>
#include <TShort_HArray1OfShortReal.hxx>
#include <TopoDS_Face.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <TopoDS_Compound.hxx>
#include <BRep_Builder.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <BRepBuilderAPI_CellFilter.hxx>
//#include <StlMesh_Mesh.hxx>
//#include <StlMesh_MeshExplorer.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <StlAPI.hxx>
#include <ShapeUpgrade_UnifySameDomain.hxx>
#include <BRepClass3d_SolidClassifier.hxx>
#include <ShapeUpgrade_CombineToCylinder.hxx>
IMPLEMENT_STANDARD_RTTIEXT(VrmlData_IndexedFaceSet,VrmlData_Faceted)
#ifdef _MSC_VER
@@ -36,9 +56,240 @@ IMPLEMENT_STANDARD_RTTIEXT(VrmlData_IndexedFaceSet,VrmlData_Faceted)
#pragma warning (disable:4996)
#endif
//// Auxiliary tools
//namespace
//{
// // Tool to get triangles from triangulation taking into account face
// // orientation and location
// class TriangleAccessor
// {
// public:
// TriangleAccessor (const TopoDS_Face& aFace)
// {
// TopLoc_Location aLoc;
// myPoly = BRep_Tool::Triangulation (aFace, aLoc);
// myTrsf = aLoc.Transformation();
// myNbTriangles = (myPoly.IsNull() ? 0 : myPoly->Triangles().Length());
// myInvert = (aFace.Orientation() == TopAbs_REVERSED);
// if (myTrsf.IsNegative())
// myInvert = ! myInvert;
// }
//
// int NbTriangles () const { return myNbTriangles; }
//
// // get i-th triangle and outward normal
// void GetTriangle (int iTri, gp_Vec &theNormal, gp_Pnt &thePnt1, gp_Pnt &thePnt2, gp_Pnt &thePnt3)
// {
// // get positions of nodes
// int iNode1, iNode2, iNode3;
// myPoly->Triangles()(iTri).Get (iNode1, iNode2, iNode3);
// thePnt1 = myPoly->Nodes()(iNode1);
// thePnt2 = myPoly->Nodes()(myInvert ? iNode3 : iNode2);
// thePnt3 = myPoly->Nodes()(myInvert ? iNode2 : iNode3);
//
// // apply transormation if not identity
// if (myTrsf.Form() != gp_Identity)
// {
// thePnt1.Transform (myTrsf);
// thePnt2.Transform (myTrsf);
// thePnt3.Transform (myTrsf);
// }
//
// // calculate normal
// theNormal = (thePnt2.XYZ() - thePnt1.XYZ()) ^ (thePnt3.XYZ() - thePnt1.XYZ());
// Standard_Real aNorm = theNormal.Magnitude();
// if (aNorm > gp::Resolution())
// theNormal /= aNorm;
// }
//
// private:
// Handle(Poly_Triangulation) myPoly;
// gp_Trsf myTrsf;
// int myNbTriangles;
// bool myInvert;
// };
//
// // convert to float and, on big-endian platform, to little-endian representation
// inline float convertFloat (Standard_Real aValue)
// {
//#ifdef OCCT_BINARY_FILE_DO_INVERSE
// return OSD_BinaryFile::InverseShortReal ((float)aValue);
//#else
// return (float)aValue;
//#endif
// }
//
// // A static method adding nodes to a mesh and keeping coincident (sharing) nodes.
// static Standard_Integer AddVertex(Handle(StlMesh_Mesh)& mesh,
// BRepBuilderAPI_CellFilter& filter,
// BRepBuilderAPI_VertexInspector& inspector,
// const gp_XYZ& p)
// {
// Standard_Integer index;
// inspector.SetCurrent(p);
// gp_XYZ minp = inspector.Shift(p, -Precision::Confusion());
// gp_XYZ maxp = inspector.Shift(p, +Precision::Confusion());
// filter.Inspect(minp, maxp, inspector);
// else
// const TColStd_ListOfInteger& indices = inspector.ResInd();
// if (indices.IsEmpty() == Standard_False)
// {
// index = indices.First(); // it should be only one
// inspector.ClearResList();
// }
// {
// index = mesh->AddVertex(p.X(), p.Y(), p.Z());
// filter.Add(index, p);
// inspector.Add(p);
// }
// return index;
// }
//
// void createFromMesh(Handle(TopoDS_TShape)& theShapeWithMesh)
// {
// TopoDS_Shape aShape;
// //aShape.Orientation(TopAbs_FORWARD);
//
// aShape.TShape(theShapeWithMesh);
// if (aShape.IsNull())
// return;
//
// // Write to STL and then read again to get BRep model (vrml fills only triangulation)
// //StlAPI::Write(aShape, "D:/Temp/tempfile");
// //StlAPI::Read(aShape, "D:/Temp/tempfile");
//
// gp_XYZ p1, p2, p3;
// TopoDS_Vertex Vertex1, Vertex2, Vertex3;
// TopoDS_Face AktFace;
// TopoDS_Wire AktWire;
// BRepBuilderAPI_Sewing aSewingTool;
// Standard_Real x1, y1, z1;
// Standard_Real x2, y2, z2;
// Standard_Real x3, y3, z3;
// Standard_Integer i1,i2,i3;
//
// aSewingTool.Init(1.0e-06,Standard_True);
//
// TopoDS_Compound aComp;
// BRep_Builder BuildTool;
// BuildTool.MakeCompound( aComp );
//
// Handle(StlMesh_Mesh) aSTLMesh = new StlMesh_Mesh();
// aSTLMesh->AddDomain();
//
// // Filter unique vertices to share the nodes of the mesh.
// BRepBuilderAPI_CellFilter uniqueVertices(Precision::Confusion());
// BRepBuilderAPI_VertexInspector inspector(Precision::Confusion());
//
// // Read mesh
// for (TopExp_Explorer exp (aShape, TopAbs_FACE); exp.More(); exp.Next())
// {
// TriangleAccessor aTool (TopoDS::Face (exp.Current()));
// for (int iTri = 1; iTri <= aTool.NbTriangles(); iTri++)
// {
// gp_Vec aNorm;
// gp_Pnt aPnt1, aPnt2, aPnt3;
// aTool.GetTriangle(iTri, aNorm, aPnt1, aPnt2, aPnt3);
//
// i1 = AddVertex(aSTLMesh, uniqueVertices, inspector, aPnt1.XYZ());
// i2 = AddVertex(aSTLMesh, uniqueVertices, inspector, aPnt2.XYZ());
// i3 = AddVertex(aSTLMesh, uniqueVertices, inspector, aPnt3.XYZ());
// aSTLMesh->AddTriangle(i1, i2, i3, aNorm.X(), aNorm.Y(), aNorm.Z());
// }
// }
//
// StlMesh_MeshExplorer aMExp (aSTLMesh);
// Standard_Integer NumberDomains = aSTLMesh->NbDomains();
// Standard_Integer iND;
// for (iND=1;iND<=NumberDomains;iND++)
// {
// for (aMExp.InitTriangle (iND); aMExp.MoreTriangle (); aMExp.NextTriangle ())
// {
// aMExp.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3);
// p1.SetCoord(x1,y1,z1);
// p2.SetCoord(x2,y2,z2);
// p3.SetCoord(x3,y3,z3);
//
// if ((!(p1.IsEqual(p2,0.0))) && (!(p1.IsEqual(p3,0.0))))
// {
// Vertex1 = BRepBuilderAPI_MakeVertex(p1);
// Vertex2 = BRepBuilderAPI_MakeVertex(p2);
// Vertex3 = BRepBuilderAPI_MakeVertex(p3);
//
// AktWire = BRepBuilderAPI_MakePolygon( Vertex1, Vertex2, Vertex3, Standard_True);
//
// if( !AktWire.IsNull())
// {
// AktFace = BRepBuilderAPI_MakeFace( AktWire);
// if(!AktFace.IsNull())
// BuildTool.Add( aComp, AktFace );
// }
// }
// }
// }
// aSTLMesh->Clear();
//
// aSewingTool.Init();
// aSewingTool.Load( aComp );
// aSewingTool.Perform();
// aShape = aSewingTool.SewedShape();
// if ( aShape.IsNull() )
// aShape = aComp;
//
// ShapeUpgrade_UnifySameDomain anUSD(aShape);
// anUSD.SetLinearTolerance(1e-5);
// anUSD.Build();
// aShape = anUSD.Shape();
//
// if (aShape.ShapeType() == TopAbs_SHELL && TopoDS::Shell(aShape).Closed())
// {
// TopoDS_Solid aSolid;
// TopoDS_Shell aShell = TopoDS::Shell (aShape);
// if (!aShell.Free ()) {
// aShell.Free(Standard_True);
// }
// BRep_Builder aBuilder;
// aBuilder.MakeSolid (aSolid);
// aBuilder.Add (aSolid, aShell);
//
// Standard_Boolean isOk = Standard_True;
// try {
// OCC_CATCH_SIGNALS
// BRepClass3d_SolidClassifier bsc3d (aSolid);
// Standard_Real t = Precision::Confusion();
// bsc3d.PerformInfinitePoint(t);
//
// if (bsc3d.State() == TopAbs_IN) {
// TopoDS_Solid aSolid2;
// aBuilder.MakeSolid (aSolid2);
// aShell.Reverse();
// aBuilder.Add (aSolid2, aShell);
// aSolid = aSolid2;
// }
// }
// catch (Standard_Failure) { isOk = Standard_False; }
// if (isOk) aShape = aSolid;
// }
//
// // Trying to apply "Combine to Cylinder"
//
// //ShapeUpgrade_CombineToCylinder cmb2Cyl;
// //Standard_Boolean isOk = Standard_True;
// //try {
// // OCC_CATCH_SIGNALS
// // cmb2Cyl.SetShape(aShape);
// // cmb2Cyl.SetAngularTolerance(20);
// // cmb2Cyl.SetLinearTolerance(3);
// // cmb2Cyl.Build();
// //}
// //catch (Standard_Failure) { isOk = Standard_False; }
// //if (isOk && cmb2Cyl.IsDone())
// // aShape = cmb2Cyl.Shape();
//
// theShapeWithMesh = aShape.TShape();
// }
//}
//
//=======================================================================
//function : readData
//purpose :
@@ -210,6 +461,7 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape ()
myIsModified = Standard_False;
}
//createFromMesh(myTShape);
return myTShape;
}

View File

@@ -33,6 +33,10 @@ IMPLEMENT_STANDARD_RTTIEXT(VrmlData_IndexedLineSet,VrmlData_Geometry)
#pragma warning (disable:4996)
#endif
namespace
{
static Handle(TopoDS_TShape) THE_NULL_SHAPE;
}
//=======================================================================
//function : GetColor
@@ -55,34 +59,34 @@ Quantity_Color VrmlData_IndexedLineSet::GetColor
const Handle(TopoDS_TShape)& VrmlData_IndexedLineSet::TShape ()
{
if (myNbPolygons == 0)
myTShape.Nullify();
else if (myIsModified) {
Standard_Integer i;
BRep_Builder aBuilder;
const gp_XYZ * arrNodes = myCoords->Values();
//if (myNbPolygons == 0)
// myTShape.Nullify();
//else if (myIsModified) {
// Standard_Integer i;
// BRep_Builder aBuilder;
// const gp_XYZ * arrNodes = myCoords->Values();
// Create the Wire
TopoDS_Wire aWire;
aBuilder.MakeWire(aWire);
for (i = 0; i < (int)myNbPolygons; i++) {
const Standard_Integer * arrIndice;
const Standard_Integer nNodes = Polygon(i, arrIndice);
TColgp_Array1OfPnt arrPoint (1, nNodes);
TColStd_Array1OfReal arrParam (1, nNodes);
for (Standard_Integer j = 0; j < nNodes; j++) {
arrPoint(j+1).SetXYZ (arrNodes[arrIndice[j]]);
arrParam(j+1) = j;
}
const Handle(Poly_Polygon3D) aPolyPolygon =
new Poly_Polygon3D (arrPoint, arrParam);
TopoDS_Edge anEdge;
aBuilder.MakeEdge (anEdge, aPolyPolygon);
aBuilder.Add (aWire, anEdge);
}
myTShape = aWire.TShape();
}
return myTShape;
// // Create the Wire
// TopoDS_Wire aWire;
// aBuilder.MakeWire(aWire);
// for (i = 0; i < (int)myNbPolygons; i++) {
// const Standard_Integer * arrIndice;
// const Standard_Integer nNodes = Polygon(i, arrIndice);
// TColgp_Array1OfPnt arrPoint (1, nNodes);
// TColStd_Array1OfReal arrParam (1, nNodes);
// for (Standard_Integer j = 0; j < nNodes; j++) {
// arrPoint(j+1).SetXYZ (arrNodes[arrIndice[j]]);
// arrParam(j+1) = j;
// }
// const Handle(Poly_Polygon3D) aPolyPolygon =
// new Poly_Polygon3D (arrPoint, arrParam);
// TopoDS_Edge anEdge;
// aBuilder.MakeEdge (anEdge, aPolyPolygon);
// aBuilder.Add (aWire, anEdge);
// }
// myTShape = aWire.TShape();
//}
return THE_NULL_SHAPE;
}
//=======================================================================

View File

@@ -65,3 +65,8 @@ XCAFDoc_ViewTool.cxx
XCAFDoc_ViewTool.hxx
XCAFDoc_Volume.cxx
XCAFDoc_Volume.hxx
XCAFDoc_Animation.cxx
XCAFDoc_Animation.hxx
XCAFDoc_AnimationTool.cxx
XCAFDoc_AnimationTool.hxx

View File

@@ -263,13 +263,24 @@ Standard_GUID XCAFDoc::ViewRefPlaneGUID()
}
//=======================================================================
//function : ViewRefPlaneGUID
//function : ViewRefNoteGUID
//purpose :
//=======================================================================
Standard_GUID XCAFDoc::ViewRefNoteGUID()
{
static Standard_GUID ID("C814ACC6-43AC-4812-9B2A-4E9A2A549354");
static Standard_GUID ID("efd213e2-6dfd-11d4-b9c8-0060b0ee281b");
return ID;
}
//=======================================================================
//function : ViewRefEnabledShapesGUID
//purpose :
//=======================================================================
Standard_GUID XCAFDoc::ViewRefEnabledShapesGUID()
{
static Standard_GUID ID("efd213e4-6dfd-11d4-b9c8-0060b0ee281b");
return ID;
}
@@ -294,3 +305,23 @@ Standard_GUID XCAFDoc::LockGUID()
static Standard_GUID ID("efd213eb-6dfd-11d4-b9c8-0060b0ee281b");
return ID;
}
//=======================================================================
//function : ViewRefEnabledShapesGUID
//purpose :
//=======================================================================
Standard_GUID XCAFDoc::ClipPlaneCappingRefGUID()
{
static Standard_GUID ID("50976BC9-A2B0-497C-9A66-443FB8703DAD");
return ID;
}
//=======================================================================
//function : LockGUID
//purpose :
//=======================================================================
Standard_GUID XCAFDoc::ClipPlaneVisibleRefGUID()
{
static Standard_GUID ID("279E76D5-4EFF-4F48-81D5-01CA307A5634");
return ID;
}

View File

@@ -123,8 +123,19 @@ public:
//! Return GUIDs for TreeNode representing specified types of View
Standard_EXPORT static Standard_GUID ViewRefPlaneGUID();
//! Return GUIDs for GraphNode representing specified types of View
//! Return GUIDs for TreeNode representing specified types of View
Standard_EXPORT static Standard_GUID ViewRefNoteGUID();
//! Return GUIDs for TreeNode representing specified types of View
Standard_EXPORT static Standard_GUID ViewRefEnabledShapesGUID();
//! Return GUIDs for clipping plane capping
Standard_EXPORT static Standard_GUID ClipPlaneCappingRefGUID();
//! Return GUIDs for clipping plane visibility
Standard_EXPORT static Standard_GUID ClipPlaneVisibleRefGUID();
//! Return GUIDs for GraphNode representing specified types of View
Standard_EXPORT static Standard_GUID ViewRefAnnotationGUID();
//! Returns GUID for UAttribute identifying lock flag

View File

@@ -0,0 +1,214 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 <Standard_GUID.hxx>
#include <Standard_Type.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_Label.hxx>
#include <TDF_RelocationTable.hxx>
#include <XCAFDoc_Animation.hxx>
#include <TColStd_HArray1OfByte.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_Animation, TDF_Attribute)
//=======================================================================
//function : XCAFDoc_Animation
//purpose :
//=======================================================================
XCAFDoc_Animation::XCAFDoc_Animation()
{
}
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& XCAFDoc_Animation::GetID()
{
static Standard_GUID MatID("431A3BB7-7113-45C4-8653-AED7CC0012E1");
return MatID;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Handle(XCAFDoc_Animation) XCAFDoc_Animation::Set(const TDF_Label& theLabel,
const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfByte)& theImage,
const Handle(TColStd_HArray1OfByte)& theAnimation)
{
Handle(XCAFDoc_Animation) A;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), A))
{
A = new XCAFDoc_Animation();
theLabel.AddAttribute(A);
}
A->Set(theName, theImage, theAnimation);
return A;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Handle(XCAFDoc_Animation) XCAFDoc_Animation::Set(const TDF_Label& theLabel,
const Handle(TCollection_HAsciiString)& theName,
OSD_File& theImageFile, OSD_File& theAnimationFile)
{
Handle(XCAFDoc_Animation) anAnimation;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimation))
{
anAnimation = new XCAFDoc_Animation();
if (anAnimation->Set(theName, theImageFile, theAnimationFile))
theLabel.AddAttribute(anAnimation);
else
anAnimation.Nullify();
}
else
anAnimation->Set(theName, theImageFile, theAnimationFile);
return anAnimation;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_Animation::Set(const Handle(TCollection_HAsciiString)& theName, OSD_File& theImageFile, OSD_File& theAnimationFile)
{
if (!theImageFile.IsOpen() || !theImageFile.IsReadable() || !theAnimationFile.IsOpen() || !theAnimationFile.IsReadable())
return Standard_False;
if (theImageFile.Size() > (Standard_Size)IntegerLast() || theAnimationFile.Size() > (Standard_Size)IntegerLast())
return Standard_False;
myImage.reset(new TColStd_HArray1OfByte(1, static_cast<Standard_Integer>(theImageFile.Size())));
Standard_Integer nbReadBytes = 0;
theImageFile.Read((Standard_Address)&myImage->First(), myImage->Length(), nbReadBytes);
if (nbReadBytes < myImage->Length())
return Standard_False;
myAnimation.reset(new TColStd_HArray1OfByte(1, static_cast<Standard_Integer>(theAnimationFile.Size())));
nbReadBytes = 0;
theAnimationFile.Read((Standard_Address)&myAnimation->First(), myAnimation->Length(), nbReadBytes);
if (nbReadBytes < myAnimation->Length())
return Standard_False;
myName = theName;
return Standard_True;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void XCAFDoc_Animation::Set(const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfByte)& theImage,
const Handle(TColStd_HArray1OfByte)& theAnimation)
{
myName = theName;
myImage = theImage;
myAnimation = theAnimation;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void XCAFDoc_Animation::Set(const Handle(TCollection_HAsciiString)& theName)
{
myName = theName;
}
//=======================================================================
//function : GetName
//purpose :
//=======================================================================
Handle(TCollection_HAsciiString) XCAFDoc_Animation::GetName() const
{
return myName;
}
//=======================================================================
//function : GetImage
//purpose :
//=======================================================================
Handle(TColStd_HArray1OfByte) XCAFDoc_Animation::GetImage() const
{
return myImage;
}
//=======================================================================
//function : GetAnimation
//purpose :
//=======================================================================
Handle(TColStd_HArray1OfByte) XCAFDoc_Animation::GetAnimation() const
{
return myAnimation;
}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& XCAFDoc_Animation::ID() const
{
return GetID();
}
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void XCAFDoc_Animation::Restore(const Handle(TDF_Attribute)& With)
{
myName = Handle(XCAFDoc_Animation)::DownCast(With)->GetName();
myImage = Handle(XCAFDoc_Animation)::DownCast(With)->GetImage();
myAnimation = Handle(XCAFDoc_Animation)::DownCast(With)->GetAnimation();
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) XCAFDoc_Animation::NewEmpty() const
{
return new XCAFDoc_Animation();
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void XCAFDoc_Animation::Paste(const Handle(TDF_Attribute)& Into,
const Handle(TDF_RelocationTable)& /*RT*/) const
{
Handle(XCAFDoc_Animation)::DownCast(Into)->Set(myName, myImage, myAnimation);
}

View File

@@ -0,0 +1,82 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 _XCAFDoc_Animation_HeaderFile
#define _XCAFDoc_Animation_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <OSD_File.hxx>
#include <TDF_Attribute.hxx>
class Standard_GUID;
class TDF_Label;
class TDF_Attribute;
class TDF_RelocationTable;
class XCAFView_Object;
class XCAFDoc_Animation;
class TCollection_HAsciiString;
class TColStd_HArray1OfByte;
DEFINE_STANDARD_HANDLE(XCAFDoc_Animation, TDF_Attribute)
//! attribute to store animation
class XCAFDoc_Animation : public TDF_Attribute
{
public:
Standard_EXPORT XCAFDoc_Animation();
Standard_EXPORT static const Standard_GUID& GetID();
Standard_EXPORT static Handle(XCAFDoc_Animation) Set(const TDF_Label& label, const Handle(TCollection_HAsciiString)& theName, const Handle(TColStd_HArray1OfByte)& theImage, const Handle(TColStd_HArray1OfByte)& theAnimation);
Standard_EXPORT static Handle(XCAFDoc_Animation) Set(const TDF_Label& theLabel, const Handle(TCollection_HAsciiString)& theName, OSD_File& theImageFile, OSD_File& theAnimationFile);
Standard_EXPORT void Set(const Handle(TCollection_HAsciiString)& theName, const Handle(TColStd_HArray1OfByte)& theImage, const Handle(TColStd_HArray1OfByte)& theAnimation);
Standard_EXPORT Standard_Boolean Set(const Handle(TCollection_HAsciiString)& aName, OSD_File& theImageFile, OSD_File& theAnimationFile);
Standard_EXPORT void Set(const Handle(TCollection_HAsciiString)& theName);
Standard_EXPORT Handle(TCollection_HAsciiString) GetName() const;
Standard_EXPORT Handle(TColStd_HArray1OfByte) GetImage() const;
Standard_EXPORT Handle(TColStd_HArray1OfByte) GetAnimation() const;
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
Standard_EXPORT void Restore(const Handle(TDF_Attribute)& With) Standard_OVERRIDE;
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT void Paste(const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XCAFDoc_Animation, TDF_Attribute)
private:
Handle(TCollection_HAsciiString) myName;
Handle(TColStd_HArray1OfByte) myImage;
Handle(TColStd_HArray1OfByte) myAnimation;
};
#endif

View File

@@ -0,0 +1,236 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 <TCollection_HAsciiString.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_Name.hxx>
#include <TDataStd_TreeNode.hxx>
#include <TDataXtd_Geometry.hxx>
#include <TDataXtd_Plane.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_ChildIDIterator.hxx>
#include <XCAFDoc.hxx>
#include <XCAFDoc_Animation.hxx>
#include <XCAFDoc_AnimationTool.hxx>
#include <TDF_AttributeIterator.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_AnimationTool, TDF_Attribute)
//=======================================================================
//function : BaseLabel
//purpose :
//=======================================================================
TDF_Label XCAFDoc_AnimationTool::BaseLabel() const
{
return Label();
}
//=======================================================================
//function : IsAnimation
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_AnimationTool::IsAnimation(const TDF_Label& theLabel) const
{
if (theLabel.Father() != Label())
return Standard_False;
Handle(XCAFDoc_Animation) anAnimAttribute;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimAttribute))
return Standard_False;
return Standard_True;
}
//=======================================================================
//function : GetAnimation
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_AnimationTool::GetAnimation(const TDF_Label& theLabel,
Handle(TCollection_HAsciiString)& theName,
Handle(TColStd_HArray1OfByte)& theImage,
Handle(TColStd_HArray1OfByte)& theAnimation) const
{
if (theLabel.Father() != Label())
return Standard_False;
Handle(XCAFDoc_Animation) animAttr;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), animAttr)) {
return Standard_False;
}
theName = animAttr->GetName();
theImage = animAttr->GetImage();
theAnimation = animAttr->GetAnimation();
return Standard_True;
}
//=======================================================================
//function : AddAnimation
//purpose :
//=======================================================================
TDF_Label XCAFDoc_AnimationTool::AddAnimation(const Handle(TCollection_HAsciiString)& theName,
const Handle(TColStd_HArray1OfByte)& theImage,
const Handle(TColStd_HArray1OfByte)& theAnimation )
{
TDF_Label animL;
TDF_TagSource aTag;
animL = aTag.NewChild(Label());
XCAFDoc_Animation::Set(animL, theName, theImage, theAnimation);
TDataStd_Name::Set(animL, TCollection_AsciiString(theName->ToCString()));
return animL;
}
//=======================================================================
//function : AddAnimation
//purpose :
//=======================================================================
TDF_Label XCAFDoc_AnimationTool::AddAnimation(const Handle(TCollection_HAsciiString)& theName,
OSD_File& theImageFile, OSD_File& theAnimationFile)
{
TDF_Label animL;
TDF_TagSource aTag;
animL = aTag.NewChild(Label());
TDataStd_Name::Set(animL, TCollection_AsciiString(theName->ToCString()));
XCAFDoc_Animation::Set(animL, theName, theImageFile, theAnimationFile);
return animL;
}
//=======================================================================
//function : RemoveAnimation
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_AnimationTool::RemoveAnimation(const TDF_Label& theLabel) const
{
Handle(XCAFDoc_Animation)anAnimAttr;
if (!IsAnimation(theLabel) || !theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimAttr))
return Standard_False;
theLabel.ForgetAllAttributes(Standard_True);
return Standard_True;
}
//=======================================================================
//function : GetAnimationLabels
//purpose :
//=======================================================================
void XCAFDoc_AnimationTool::GetAnimationLabels(TDF_LabelSequence& theLabels) const
{
theLabels.Clear();
TDF_ChildIterator aChildIterator(Label());
for (; aChildIterator.More(); aChildIterator.Next()) {
TDF_Label aLabel = aChildIterator.Value();
if (IsAnimation(aLabel)) theLabels.Append(aLabel);
}
}
//=======================================================================
//function : SetName
//purpose :
//=======================================================================
void XCAFDoc_AnimationTool::SetName(const TDF_Label& theLabel,
const Handle(TCollection_HAsciiString)& theName) const
{
if (theLabel.Father() != Label())
return;
Handle(XCAFDoc_Animation)anAnimAttr;
if (!theLabel.FindAttribute(XCAFDoc_Animation::GetID(), anAnimAttr))
return;
anAnimAttr->Set(theName);
}
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& XCAFDoc_AnimationTool::GetID()
{
static Standard_GUID AnimationID("7261F539-43AD-4544-8419-AE63C6ED4A41");
return AnimationID;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Handle(XCAFDoc_AnimationTool) XCAFDoc_AnimationTool::Set(const TDF_Label& L)
{
Handle(XCAFDoc_AnimationTool) A;
if (!L.FindAttribute(XCAFDoc_AnimationTool::GetID(), A)) {
A = new XCAFDoc_AnimationTool();
L.AddAttribute(A);
}
return A;
}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& XCAFDoc_AnimationTool::ID() const
{
return GetID();
}
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void XCAFDoc_AnimationTool::Restore(const Handle(TDF_Attribute)& /*with*/)
{
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) XCAFDoc_AnimationTool::NewEmpty() const
{
return new XCAFDoc_AnimationTool;
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void XCAFDoc_AnimationTool::Paste(const Handle(TDF_Attribute)& /*into*/,
const Handle(TDF_RelocationTable)& /*RT*/) const
{
}
//=======================================================================
//function : XCAFDoc_AnimationTool
//purpose :
//=======================================================================
XCAFDoc_AnimationTool::XCAFDoc_AnimationTool()
{
}

View File

@@ -0,0 +1,85 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 _XCAFDoc_AnimationTool_HeaderFile
#define _XCAFDoc_AnimationTool_HeaderFile
#include <TDF_LabelSequence.hxx>
#include <TColStd_HArray1OfByte.hxx>
#include <OSD_File.hxx>
class XCAFDoc_AnimationTool;
DEFINE_STANDARD_HANDLE(XCAFDoc_AnimationToolTool, TDF_Attribute)
//! Provide tool for management of Animations section of document.
//! Provide tool to store, retrieve, remove and modify animations.
//! Each animation has a name and binary data of screenshot and animation.
class XCAFDoc_AnimationTool : public TDF_Attribute
{
public:
Standard_EXPORT XCAFDoc_AnimationTool();
//! Creates (if not exist) Animation tool.
Standard_EXPORT static Handle(XCAFDoc_AnimationTool) Set(const TDF_Label& theLabel);
Standard_EXPORT static const Standard_GUID& GetID();
//! returns the label under which Animations are stored
Standard_EXPORT TDF_Label BaseLabel() const;
//! Returns True if label belongs to a Animations table and
//! is a animation definition
Standard_EXPORT Standard_Boolean IsAnimation (const TDF_Label& theLabel) const;
//! Returns animation defined by label theLabel
//! Returns False if the label is not in Animations table
Standard_EXPORT Standard_Boolean GetAnimation(const TDF_Label& theLabel, Handle(TCollection_HAsciiString)& theName, Handle(TColStd_HArray1OfByte)& theImage, Handle(TColStd_HArray1OfByte)& theAnimation) const;
//! Adds an animation definition to a Animations table
//! Returns created label
Standard_EXPORT TDF_Label AddAnimation(const Handle(TCollection_HAsciiString)& theName, const Handle(TColStd_HArray1OfByte)& theImage, const Handle(TColStd_HArray1OfByte)& theAnimation);
//! Adds an animation definition to a Animations table
//! Returns created label
Standard_EXPORT TDF_Label AddAnimation(const Handle(TCollection_HAsciiString)& theName, OSD_File& theImageFile, OSD_File& theAnimationFile);
//! Removes animation from the Animations table
Standard_EXPORT Standard_Boolean RemoveAnimation(const TDF_Label& theLabel) const;
//! Returns a sequence of animations currently stored
//! in the Animations table
Standard_EXPORT void GetAnimationLabels(TDF_LabelSequence& Labels) const;
//! Rename animation
Standard_EXPORT void SetName(const TDF_Label& theLabelL, const Handle(TCollection_HAsciiString)& theName) const;
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XCAFDoc_AnimationTool, TDF_Attribute)
};
#endif // _XCAFDoc_ClippingPlaneTool_HeaderFile

View File

@@ -0,0 +1,65 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 _XCAFDoc_View_HeaderFile
#define _XCAFDoc_View_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <TDF_Attribute.hxx>
class Standard_GUID;
class TDF_Label;
class TDF_Attribute;
class TDF_RelocationTable;
class XCAFView_Object;
// resolve name collisions with WinAPI headers
#ifdef GetObject
#undef GetObject
#endif
class XCAFDoc_View;
DEFINE_STANDARD_HANDLE(XCAFDoc_View, TDF_Attribute)
//! attribute to store view
class XCAFDoc_View : public TDF_Attribute
{
public:
Standard_EXPORT XCAFDoc_View();
Standard_EXPORT static const Standard_GUID& GetID();
Standard_EXPORT static Handle(XCAFDoc_View) Set (const TDF_Label& theLabel);
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
Standard_EXPORT void Restore (const Handle(TDF_Attribute)& With) Standard_OVERRIDE;
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
Standard_EXPORT void SetObject (const Handle(XCAFView_Object)& theViewObject);
Standard_EXPORT Handle(XCAFView_Object) GetObject() const;
DEFINE_STANDARD_RTTIEXT(XCAFDoc_View, TDF_Attribute)
};
#endif

View File

@@ -51,7 +51,7 @@ XCAFDoc_AssemblyItemRef::Get(const TDF_Label& theLabel)
Handle(XCAFDoc_AssemblyItemRef)
XCAFDoc_AssemblyItemRef::Set(const TDF_Label& theLabel,
const XCAFDoc_AssemblyItemId& theItemId)
const XCAFDoc_AssemblyItemId& theItemId)
{
Handle(XCAFDoc_AssemblyItemRef) aThis;
if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_AssemblyItemRef::GetID(), aThis))
@@ -65,8 +65,8 @@ XCAFDoc_AssemblyItemRef::Set(const TDF_Label& theLabel,
Handle(XCAFDoc_AssemblyItemRef)
XCAFDoc_AssemblyItemRef::Set(const TDF_Label& theLabel,
const XCAFDoc_AssemblyItemId& theItemId,
const Standard_GUID& theAttrGUID)
const XCAFDoc_AssemblyItemId& theItemId,
const Standard_GUID& theAttrGUID)
{
Handle(XCAFDoc_AssemblyItemRef) aThis;
if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_AssemblyItemRef::GetID(), aThis))
@@ -81,8 +81,8 @@ XCAFDoc_AssemblyItemRef::Set(const TDF_Label& theLabel,
Handle(XCAFDoc_AssemblyItemRef)
XCAFDoc_AssemblyItemRef::Set(const TDF_Label& theLabel,
const XCAFDoc_AssemblyItemId& theItemId,
const Standard_Integer theShapeIndex)
const XCAFDoc_AssemblyItemId& theItemId,
const Standard_Integer theShapeIndex)
{
Handle(XCAFDoc_AssemblyItemRef) aThis;
if (!theLabel.IsNull() && !theLabel.FindAttribute(XCAFDoc_AssemblyItemRef::GetID(), aThis))
@@ -272,7 +272,7 @@ XCAFDoc_AssemblyItemRef::Restore(const Handle(TDF_Attribute)& theAttrFrom)
void
XCAFDoc_AssemblyItemRef::Paste(const Handle(TDF_Attribute)& theAttrInto,
const Handle(TDF_RelocationTable)& /*theRT*/) const
const Handle(TDF_RelocationTable)& /*theRT*/) const
{
Handle(XCAFDoc_AssemblyItemRef) anOther = Handle(XCAFDoc_AssemblyItemRef)::DownCast(theAttrInto);
if (!anOther.IsNull())

View File

@@ -59,7 +59,7 @@ Standard_Boolean XCAFDoc_ClippingPlaneTool::IsClippingPlane(const TDF_Label& the
//=======================================================================
Standard_Boolean XCAFDoc_ClippingPlaneTool::GetClippingPlane(const TDF_Label& theLabel,
gp_Pln& thePlane, TCollection_ExtendedString& theName, Standard_Boolean &theCapping) const
gp_Pln& thePlane, TCollection_ExtendedString& theName, Standard_Boolean &theCapping, Standard_Boolean &theVisible) const
{
if (theLabel.Father() != Label())
return Standard_False;
@@ -74,9 +74,13 @@ Standard_Boolean XCAFDoc_ClippingPlaneTool::GetClippingPlane(const TDF_Label& th
theName = aNameAttribute->Get();
Handle(TDataStd_Integer) aCappingAttribute;
if (theLabel.FindAttribute(TDataStd_Integer::GetID(), aCappingAttribute))
if (theLabel.FindAttribute(XCAFDoc::ClipPlaneCappingRefGUID(), aCappingAttribute))
theCapping = (aCappingAttribute->Get() == 1);
Handle(TDataStd_Integer) aVisibleAttribute;
if (theLabel.FindAttribute(XCAFDoc::ClipPlaneVisibleRefGUID(), aVisibleAttribute))
theVisible = (aVisibleAttribute->Get() == 1);
return Standard_True;
}
@@ -86,10 +90,10 @@ Standard_Boolean XCAFDoc_ClippingPlaneTool::GetClippingPlane(const TDF_Label& th
//=======================================================================
Standard_Boolean XCAFDoc_ClippingPlaneTool::GetClippingPlane(const TDF_Label& theLabel,
gp_Pln& thePlane, Handle(TCollection_HAsciiString)& theName, Standard_Boolean &theCapping) const
gp_Pln& thePlane, Handle(TCollection_HAsciiString)& theName, Standard_Boolean &theCapping, Standard_Boolean &theVisible) const
{
TCollection_ExtendedString anExtName;
if (!GetClippingPlane(theLabel, thePlane, anExtName, theCapping))
if (!GetClippingPlane(theLabel, thePlane, anExtName, theCapping, theVisible))
return Standard_False;
theName = new TCollection_HAsciiString(anExtName);
return Standard_True;
@@ -108,8 +112,8 @@ TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, con
for (Standard_Integer i = 1; i <= aClippingPlanes.Length(); i++) {
gp_Pln aPlane;
TCollection_ExtendedString aName;
Standard_Boolean aCapping;
GetClippingPlane(aClippingPlanes.Value(i), aPlane, aName, aCapping);
Standard_Boolean aCapping, aVisible;
GetClippingPlane(aClippingPlanes.Value(i), aPlane, aName, aCapping, aVisible);
if (!aName.IsEqual(theName))
continue;
if (aPlane.Axis().Angle(thePlane.Axis()) > Precision::Angular())
@@ -149,12 +153,14 @@ TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, con
//purpose :
//=======================================================================
TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, const TCollection_ExtendedString theName, const Standard_Boolean theCapping) const
TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, const TCollection_ExtendedString theName, const Standard_Boolean theCapping, const Standard_Boolean theVisible) const
{
TDF_Label aLabel = AddClippingPlane(thePlane, theName);
Standard_Integer aCappingVal = (theCapping) ? 1 : 0;
TDataStd_Integer::Set(aLabel, aCappingVal);
Standard_Integer aVisibleVal = (theVisible) ? 1 : 0;
TDataStd_Integer::Set(aLabel, aVisibleVal);
return aLabel;
}
@@ -163,10 +169,10 @@ TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, con
//purpose :
//=======================================================================
TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, const Handle(TCollection_HAsciiString)& theName, const Standard_Boolean theCapping) const
TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, const Handle(TCollection_HAsciiString)& theName, const Standard_Boolean theCapping, const Standard_Boolean theVisible) const
{
TCollection_ExtendedString anExtName = TCollection_ExtendedString(theName->String());
return AddClippingPlane(thePlane, anExtName, theCapping);
return AddClippingPlane(thePlane, anExtName, theCapping, theVisible);
}
//=======================================================================
@@ -230,9 +236,9 @@ void XCAFDoc_ClippingPlaneTool::SetCapping(const TDF_Label& theClippingPlaneL, c
if (theClippingPlaneL.Father() != Label())
return;
theClippingPlaneL.ForgetAttribute(TDataStd_Integer::GetID());
theClippingPlaneL.ForgetAttribute(XCAFDoc::ClipPlaneCappingRefGUID());
Standard_Integer aCappingVal = (theCapping) ? 1 : 0;
TDataStd_Integer::Set(theClippingPlaneL, aCappingVal);
TDataStd_Integer::Set(theClippingPlaneL, XCAFDoc::ClipPlaneCappingRefGUID(), aCappingVal);
}
//=======================================================================
@@ -246,7 +252,7 @@ Standard_Boolean XCAFDoc_ClippingPlaneTool::GetCapping(const TDF_Label& theClipp
return Standard_False;
Handle(TDataStd_Integer) aCappingAttribute;
if (theClippingPlaneL.FindAttribute(TDataStd_Integer::GetID(), aCappingAttribute))
if (theClippingPlaneL.FindAttribute(XCAFDoc::ClipPlaneCappingRefGUID(), aCappingAttribute))
return (aCappingAttribute->Get() == 1);
return Standard_False;
@@ -263,13 +269,63 @@ Standard_Boolean XCAFDoc_ClippingPlaneTool::GetCapping(const TDF_Label& theClipp
return Standard_False;
Handle(TDataStd_Integer) aCappingAttribute;
if (theClippingPlaneL.FindAttribute(TDataStd_Integer::GetID(), aCappingAttribute)) {
if (theClippingPlaneL.FindAttribute(XCAFDoc::ClipPlaneCappingRefGUID(), aCappingAttribute)) {
theCapping = (aCappingAttribute->Get() == 1);
return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : SetVisible
//purpose :
//=======================================================================
void XCAFDoc_ClippingPlaneTool::SetVisible(const TDF_Label& theClippingPlaneL, const Standard_Boolean theVisible)
{
if (theClippingPlaneL.Father() != Label())
return;
theClippingPlaneL.ForgetAttribute(XCAFDoc::ClipPlaneVisibleRefGUID());
Standard_Integer aVisibleVal = (theVisible) ? 1 : 0;
TDataStd_Integer::Set(theClippingPlaneL, XCAFDoc::ClipPlaneVisibleRefGUID(), aVisibleVal);
}
//=======================================================================
//function : GetVisible
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_ClippingPlaneTool::GetVisible(const TDF_Label& theClippingPlaneL) const
{
if (theClippingPlaneL.Father() != Label())
return Standard_False;
Handle(TDataStd_Integer) aVisibleAttribute;
if (theClippingPlaneL.FindAttribute(XCAFDoc::ClipPlaneVisibleRefGUID(), aVisibleAttribute))
return (aVisibleAttribute->Get() == 1);
return Standard_False;
}
//=======================================================================
//function : GetVisible
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_ClippingPlaneTool::GetVisible(const TDF_Label& theClippingPlaneL, Standard_Boolean &theVisible) const
{
if (theClippingPlaneL.Father() != Label())
return Standard_False;
Handle(TDataStd_Integer) aVisibleAttribute;
if (theClippingPlaneL.FindAttribute(XCAFDoc::ClipPlaneVisibleRefGUID(), aVisibleAttribute)) {
theVisible = (aVisibleAttribute->Get() == 1);
return Standard_True;
}
return Standard_False;
}
//=======================================================================
//function : GetID

View File

@@ -48,22 +48,22 @@ public:
//! Returns ClippingPlane defined by label lab
//! Returns False if the label is not in ClippingPlane table
//! or does not define a ClippingPlane
Standard_EXPORT Standard_Boolean GetClippingPlane(const TDF_Label& theLabel, gp_Pln& thePlane, TCollection_ExtendedString& theName, Standard_Boolean &theCapping) const;
Standard_EXPORT Standard_Boolean GetClippingPlane(const TDF_Label& theLabel, gp_Pln& thePlane, TCollection_ExtendedString& theName, Standard_Boolean &theCapping, Standard_Boolean &theVisible) const;
//! Returns ClippingPlane defined by label lab
//! Returns False if the label is not in ClippingPlane table
//! or does not define a ClippingPlane
Standard_EXPORT Standard_Boolean GetClippingPlane(const TDF_Label& theLabel, gp_Pln& thePlane, Handle(TCollection_HAsciiString)& theName, Standard_Boolean &theCapping) const;
Standard_EXPORT Standard_Boolean GetClippingPlane(const TDF_Label& theLabel, gp_Pln& thePlane, Handle(TCollection_HAsciiString)& theName, Standard_Boolean &theCapping, Standard_Boolean &theVisible) const;
//! Adds a clipping plane definition to a ClippingPlane table and returns
//! its label (returns existing label if the same clipping plane
//! is already defined)
Standard_EXPORT TDF_Label AddClippingPlane(const gp_Pln thePlane, const TCollection_ExtendedString theName, const Standard_Boolean theCapping) const;
Standard_EXPORT TDF_Label AddClippingPlane(const gp_Pln thePlane, const TCollection_ExtendedString theName, const Standard_Boolean theCapping, const Standard_Boolean theVisible) const;
//! Adds a clipping plane definition to a ClippingPlane table and returns
//! its label (returns existing label if the same clipping plane
//! is already defined)
Standard_EXPORT TDF_Label AddClippingPlane(const gp_Pln thePlane, const Handle(TCollection_HAsciiString)& theName, const Standard_Boolean theCapping) const;
Standard_EXPORT TDF_Label AddClippingPlane(const gp_Pln thePlane, const Handle(TCollection_HAsciiString)& theName, const Standard_Boolean theCapping, const Standard_Boolean theVisible) const;
//! Adds a clipping plane definition to a ClippingPlane table and returns
//! its label (returns existing label if the same clipping plane
@@ -98,6 +98,17 @@ public:
//! Return true if Label is valid abd capping is exist.
Standard_EXPORT Standard_Boolean GetCapping(const TDF_Label& theClippingPlaneL, Standard_Boolean &theCapping) const;
//! Set new value of visible for given clipping plane label
Standard_EXPORT void SetVisible(const TDF_Label& theClippingPlaneL, const Standard_Boolean theCapping);
//! Get visible value for given clipping plane label
//! Return capping value
Standard_EXPORT Standard_Boolean GetVisible(const TDF_Label& theClippingPlaneL) const;
//! Get visible value for given clipping plane label
//! Return true if Label is valid abd capping is exist.
Standard_EXPORT Standard_Boolean GetVisible(const TDF_Label& theClippingPlaneL, Standard_Boolean &theCapping) const;
Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;

View File

@@ -33,6 +33,7 @@
#include <XCAFDoc_NotesTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_ViewTool.hxx>
#include <XCAFDoc_AnimationTool.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_DocumentTool,TDF_Attribute)
@@ -87,6 +88,7 @@ Handle(XCAFDoc_DocumentTool) XCAFDoc_DocumentTool::Set(const TDF_Label& L,
XCAFDoc_NotesTool::Set(NotesLabel(L));
XCAFDoc_ViewTool::Set(ViewsLabel(L));
XCAFDoc_ClippingPlaneTool::Set(ClippingPlanesLabel(L));
XCAFDoc_AnimationTool::Set(AnimationsLabel(L));
}
return A;
}
@@ -224,7 +226,17 @@ TDF_Label XCAFDoc_DocumentTool::NotesLabel(const TDF_Label& acces)
TDataStd_Name::Set(L, "Notes");
return L;
}
//=======================================================================
//function : AnimationsLabel
//purpose :
//=======================================================================
TDF_Label XCAFDoc_DocumentTool::AnimationsLabel(const TDF_Label& acces)
{
TDF_Label L = DocLabel(acces).FindChild(10, Standard_True);
TDataStd_Name::Set(L, "Animations");
return L;
}
//=======================================================================
//function : ShapeTool
//purpose :
@@ -308,7 +320,15 @@ Handle(XCAFDoc_NotesTool) XCAFDoc_DocumentTool::NotesTool(const TDF_Label& acces
{
return XCAFDoc_NotesTool::Set(NotesLabel(acces));
}
//=======================================================================
//function : AnimationTool
//purpose :
//=======================================================================
Handle(XCAFDoc_AnimationTool) XCAFDoc_DocumentTool::AnimationTool(const TDF_Label& acces)
{
return XCAFDoc_AnimationTool::Set(AnimationsLabel(acces));
}
//=======================================================================
//function : ID
//purpose :

View File

@@ -34,6 +34,7 @@ class XCAFDoc_NotesTool;
class XCAFDoc_ViewTool;
class TDF_Attribute;
class TDF_RelocationTable;
class XCAFDoc_AnimationTool;
class XCAFDoc_DocumentTool;
@@ -89,6 +90,9 @@ public:
//! Returns sub-label of DocLabel() with tag 9.
Standard_EXPORT static TDF_Label NotesLabel(const TDF_Label& acces);
//! Returns sub-label of DocLabel() with tag 10.
Standard_EXPORT static TDF_Label AnimationsLabel(const TDF_Label& acces);
//! Creates (if it does not exist) ShapeTool attribute on ShapesLabel().
Standard_EXPORT static Handle(XCAFDoc_ShapeTool) ShapeTool (const TDF_Label& acces);
@@ -113,6 +117,9 @@ public:
//! Creates (if it does not exist) NotesTool attribute on NotesLabel().
Standard_EXPORT static Handle(XCAFDoc_NotesTool) NotesTool(const TDF_Label& acces);
//! Creates (if it does not exist) AnimationTool attribute on NotesLabel().
Standard_EXPORT static Handle(XCAFDoc_AnimationTool) AnimationTool(const TDF_Label& acces);
Standard_EXPORT XCAFDoc_DocumentTool();
//! to be called when reading this attribute from file

View File

@@ -114,7 +114,7 @@ XCAFDoc_NoteBinData::Set(const TCollection_ExtendedString& theTitle,
if (theFile.Size() > (Standard_Size)IntegerLast())
return Standard_False;
myData.reset(new TColStd_HArray1OfByte(1, (Standard_Integer)theFile.Size()));
myData.reset(new TColStd_HArray1OfByte(1, static_cast<Standard_Integer>(theFile.Size())));
Standard_Integer nbReadBytes = 0;
theFile.Read((Standard_Address)&myData->First(), myData->Length(), nbReadBytes);
if (nbReadBytes < myData->Length())

View File

@@ -20,6 +20,7 @@
#include <TDataStd_Integer.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_RealArray.hxx>
#include <TDataStd_ByteArray.hxx>
#include <TDataXtd_Axis.hxx>
#include <TDataXtd_Geometry.hxx>
#include <TDataXtd_Plane.hxx>
@@ -45,7 +46,10 @@ enum ChildLab
ChildLab_BackPlaneDistance,
ChildLab_ViewVolumeSidesClipping,
ChildLab_ClippingExpression,
ChildLab_GDTPoints
ChildLab_GDTPoints,
ChildLab_Image,
ChildLab_EnabledShapes,
ChildLab_NotePoints
};
//=======================================================================
@@ -149,6 +153,32 @@ void XCAFDoc_View::SetObject (const Handle(XCAFView_Object)& theObject)
TDataXtd_Point::Set(aPointsLabel.FindChild(i), theObject->GDTPoint(i));
}
}
//Image
if (theObject->HasImage())
{
Handle(TColStd_HArray1OfByte) image = theObject->Image();
Handle(TDataStd_ByteArray) arr = TDataStd_ByteArray::Set(Label().FindChild(ChildLab_Image), image->Lower(), image->Upper());
for (Standard_Integer i = image->Lower(); i <= image->Upper(); i++) {
arr->SetValue(i, image->Value(i));
}
}
//shapes transparency
if (theObject->HasEnabledShapes())
{
TDF_Label aShapeTranspLabel = Label().FindChild(ChildLab_EnabledShapes);
for (Standard_Integer i = 1; i <= theObject->NbEnabledShapes(); i++) {
Standard_Integer aValue = theObject->EnabledShape(i) ? 1 : 0;
TDataStd_Integer::Set(aShapeTranspLabel.FindChild(i), aValue);
}
}
//note points
if (theObject->HasNotePoints())
{
TDF_Label aPointsLabel = Label().FindChild(ChildLab_NotePoints);
for (Standard_Integer i = 1; i <= theObject->NbNotePoints(); i++) {
TDataXtd_Point::Set(aPointsLabel.FindChild(i), theObject->NotePoint(i));
}
}
}
//=======================================================================
@@ -259,7 +289,37 @@ Handle(XCAFView_Object) XCAFDoc_View::GetObject() const
anObj->SetGDTPoint(i, aPoint);
}
}
//Image
Handle(TDataStd_ByteArray) anArr;
if (Label().FindChild(ChildLab_Image).FindAttribute(TDataStd_ByteArray::GetID(), anArr)) {
anObj->SetImage(anArr->InternalArray());
}
// Shapes transparency
if (!Label().FindChild(ChildLab_EnabledShapes, Standard_False).IsNull()) {
TDF_Label aShapesTranspLabel = Label().FindChild(ChildLab_EnabledShapes);
anObj->CreateEnabledShapes(aShapesTranspLabel.NbChildren());
for (Standard_Integer i = 1; i <= aShapesTranspLabel.NbChildren(); i++) {
gp_Pnt aPoint;
Handle(TDataStd_Integer) aTranspAttr;
aShapesTranspLabel.FindChild(i).FindAttribute(TDataStd_Integer::GetID(), aTranspAttr);
Standard_Boolean aValue = (aTranspAttr->Get() == 1);
anObj->SetEnabledShape(i, aValue);
}
}
// Note Points
if (!Label().FindChild(ChildLab_NotePoints, Standard_False).IsNull()) {
TDF_Label aPointsLabel = Label().FindChild(ChildLab_NotePoints);
anObj->CreateNotePoints(aPointsLabel.NbChildren());
for (Standard_Integer i = 1; i <= aPointsLabel.NbChildren(); i++) {
gp_Pnt aPoint;
Handle(TDataXtd_Point) aPointAttr;
aPointsLabel.FindChild(i).FindAttribute(TDataXtd_Point::GetID(), aPointAttr);
TDataXtd_Geometry::Point(aPointAttr->Label(), aPoint);
anObj->SetNotePoint(i, aPoint);
}
}
return anObj;
}

View File

@@ -305,11 +305,10 @@ void XCAFDoc_ViewTool::SetView(const TDF_LabelSequence& theShapeLabels,
aPlaneGNode = aChGNode->GetFather(1);
aPlaneGNode->UnSetChild(aChGNode);
if (aPlaneGNode->NbChildren() == 0)
aPlaneGNode->ForgetAttribute(XCAFDoc::ViewRefGDTGUID());
aPlaneGNode->ForgetAttribute(XCAFDoc::ViewRefPlaneGUID());
}
theViewL.ForgetAttribute(XCAFDoc::ViewRefPlaneGUID());
}
if (!theViewL.FindAttribute(XCAFDoc::ViewRefShapeGUID(), aChGNode) && theShapeLabels.Length() > 0) {
aChGNode = new XCAFDoc_GraphNode;
aChGNode = XCAFDoc_GraphNode::Set(theViewL);
@@ -444,7 +443,7 @@ void XCAFDoc_ViewTool::SetClippingPlanes(const TDF_LabelSequence& theClippingPla
aPlaneGNode = aChGNode->GetFather(1);
aPlaneGNode->UnSetChild(aChGNode);
if (aPlaneGNode->NbChildren() == 0)
aPlaneGNode->ForgetAttribute(XCAFDoc::ViewRefGDTGUID());
aPlaneGNode->ForgetAttribute(XCAFDoc::ViewRefPlaneGUID());
}
theViewL.ForgetAttribute(XCAFDoc::ViewRefPlaneGUID());
}
@@ -465,7 +464,86 @@ void XCAFDoc_ViewTool::SetClippingPlanes(const TDF_LabelSequence& theClippingPla
aChGNode->SetFather(aPlaneGNode);
}
}
//=======================================================================
//function : SetEnabledShapes
//purpose :
//=======================================================================
void XCAFDoc_ViewTool::SetEnabledShapes(const TDF_LabelSequence& theShapesTransparencyLabels,
const TDF_Label& theViewL) const
{
if (!IsView(theViewL))
return;
Handle(XCAFDoc_GraphNode) aChGNode;
Handle(XCAFDoc_GraphNode) aShapeGNode;
if (theViewL.FindAttribute(XCAFDoc::ViewRefEnabledShapesGUID(), aChGNode)) {
while (aChGNode->NbFathers() > 0) {
aShapeGNode = aChGNode->GetFather(1);
aShapeGNode->UnSetChild(aChGNode);
if (aShapeGNode->NbChildren() == 0)
aShapeGNode->ForgetAttribute(XCAFDoc::ViewRefEnabledShapesGUID());
}
theViewL.ForgetAttribute(XCAFDoc::ViewRefEnabledShapesGUID());
}
if (!theViewL.FindAttribute(XCAFDoc::ViewRefEnabledShapesGUID(), aChGNode) && theShapesTransparencyLabels.Length() > 0) {
aChGNode = new XCAFDoc_GraphNode;
aChGNode = XCAFDoc_GraphNode::Set(theViewL);
aChGNode->SetGraphID(XCAFDoc::ViewRefEnabledShapesGUID());
}
for (Standard_Integer i = theShapesTransparencyLabels.Lower(); i <= theShapesTransparencyLabels.Upper(); i++)
{
if (!theShapesTransparencyLabels.Value(i).FindAttribute(XCAFDoc::ViewRefEnabledShapesGUID(), aShapeGNode)) {
aShapeGNode = new XCAFDoc_GraphNode;
aShapeGNode = XCAFDoc_GraphNode::Set(theShapesTransparencyLabels.Value(i));
}
aShapeGNode->SetGraphID(XCAFDoc::ViewRefEnabledShapesGUID());
aShapeGNode->SetChild(aChGNode);
aChGNode->SetFather(aShapeGNode);
}
}
//=======================================================================
//function : SetNotes
//purpose :
//=======================================================================
void XCAFDoc_ViewTool::SetNotes(const TDF_LabelSequence& theNoteLabels,
const TDF_Label& theViewL) const
{
if (!IsView(theViewL))
return;
Handle(XCAFDoc_GraphNode) aChGNode;
Handle(XCAFDoc_GraphNode) aNoteGNode;
if (theViewL.FindAttribute(XCAFDoc::ViewRefNoteGUID(), aChGNode)) {
while (aChGNode->NbFathers() > 0) {
aNoteGNode = aChGNode->GetFather(1);
aNoteGNode->UnSetChild(aChGNode);
if (aNoteGNode->NbChildren() == 0)
aNoteGNode->ForgetAttribute(XCAFDoc::ViewRefNoteGUID());
}
theViewL.ForgetAttribute(XCAFDoc::ViewRefNoteGUID());
}
if (!theViewL.FindAttribute(XCAFDoc::ViewRefNoteGUID(), aChGNode) && theNoteLabels.Length() > 0) {
aChGNode = new XCAFDoc_GraphNode;
aChGNode = XCAFDoc_GraphNode::Set(theViewL);
aChGNode->SetGraphID(XCAFDoc::ViewRefNoteGUID());
}
for (Standard_Integer i = theNoteLabels.Lower(); i <= theNoteLabels.Upper(); i++)
{
if (!theNoteLabels.Value(i).FindAttribute(XCAFDoc::ViewRefNoteGUID(), aNoteGNode)) {
aNoteGNode = new XCAFDoc_GraphNode;
aNoteGNode = XCAFDoc_GraphNode::Set(theNoteLabels.Value(i));
}
aNoteGNode->SetGraphID(XCAFDoc::ViewRefNoteGUID());
aNoteGNode->SetChild(aChGNode);
aChGNode->SetFather(aNoteGNode);
}
}
//=======================================================================
//function : RemoveView
//purpose :
@@ -579,6 +657,30 @@ Standard_Boolean XCAFDoc_ViewTool::GetRefClippingPlaneLabel(const TDF_Label& the
return Standard_True;
}
//=======================================================================
//function : GetRefEnabledShapesLabel
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_ViewTool::GetRefEnabledShapesLabel(const TDF_Label& theViewL,
TDF_LabelSequence& theShapesTranspanencyLabels) const
{
theShapesTranspanencyLabels.Clear();
Handle(TDataStd_TreeNode) aNode;
if (!theViewL.FindAttribute(XCAFDoc::ViewRefGUID(), aNode) || !aNode->HasFather()) {
Handle(XCAFDoc_GraphNode) aGNode;
if (theViewL.FindAttribute(XCAFDoc::ViewRefEnabledShapesGUID(), aGNode) && aGNode->NbFathers() > 0) {
for (Standard_Integer i = 1; i <= aGNode->NbFathers(); i++)
theShapesTranspanencyLabels.Append(aGNode->GetFather(i)->Label());
return Standard_True;
}
else
return Standard_False;
}
theShapesTranspanencyLabels.Append(aNode->Father()->Label());
return Standard_True;
}
//=======================================================================
//function : GetRefNoteLabel
//purpose :
@@ -684,6 +786,25 @@ Standard_Boolean XCAFDoc_ViewTool::GetViewLabelsForClippingPlane(const TDF_Label
return aResult;
}
//=======================================================================
//function :GetViewLabelsForEnabledShapesLabel
//purpose :
//=======================================================================
Standard_Boolean XCAFDoc_ViewTool::GetViewLabelsForEnabledShapesLabel(const TDF_Label& theShapesTransparencyL,
TDF_LabelSequence& theViews) const
{
Handle(XCAFDoc_GraphNode) aGNode;
Standard_Boolean aResult = Standard_False;
if (theShapesTransparencyL.FindAttribute(XCAFDoc::ViewRefPlaneGUID(), aGNode) && aGNode->NbChildren() > 0) {
for (Standard_Integer i = 1; i <= aGNode->NbChildren(); i++)
{
theViews.Append(aGNode->GetChild(i)->Label());
}
aResult = Standard_True;
}
return aResult;
}
//=======================================================================
//function : GetViewLabelsForNote
//purpose :

View File

@@ -86,6 +86,12 @@ public:
//! Set Clipping planes to given View
Standard_EXPORT void SetClippingPlanes(const TDF_LabelSequence& theClippingPlaneLabels,
const TDF_Label& theViewL) const;
Standard_EXPORT void SetEnabledShapes(const TDF_LabelSequence& theShapesTransparencyLabels,
const TDF_Label& theViewL) const;
//! Set Notes to given View
Standard_EXPORT void SetNotes(const TDF_LabelSequence& theNoteLabels,
const TDF_Label& theViewL) const;
//! Remove View
Standard_EXPORT void RemoveView(const TDF_Label& theViewL);
@@ -105,6 +111,9 @@ public:
//! Returns all View labels defined for label AnnotationL
Standard_EXPORT Standard_Boolean GetViewLabelsForAnnotation(const TDF_Label& theAnnotationL, TDF_LabelSequence& theViews) const;
//! Returns all View labels defined for label Shapes transparency
Standard_EXPORT Standard_Boolean GetViewLabelsForEnabledShapesLabel(const TDF_Label& theShapesTransparencyL, TDF_LabelSequence& theViews) const;
//! Adds a view definition to a View table and returns its label
Standard_EXPORT TDF_Label AddView() ;
@@ -120,6 +129,9 @@ public:
//! Returns False if the theViewL is not in View table
Standard_EXPORT Standard_Boolean GetRefClippingPlaneLabel(const TDF_Label& theViewL, TDF_LabelSequence& theClippingPlaneLabels) const;
//! Returns shapes transparency labels defined for label theViewL
//! Returns False if the theViewL is not in View table
Standard_EXPORT Standard_Boolean GetRefEnabledShapesLabel(const TDF_Label& theViewL, TDF_LabelSequence& theShapesTranspanencyLabels) const;
//! Returns Notes labels defined for label theViewL
//! Returns False if the theViewL is not in View table
Standard_EXPORT Standard_Boolean GetRefNoteLabel(const TDF_Label& theViewL, TDF_LabelSequence& theNoteLabels) const;

View File

@@ -28,6 +28,9 @@ XCAFView_Object::XCAFView_Object()
myBackPlaneClipping = Standard_False;
myViewVolumeSidesClipping = Standard_False;
myGDTPoints = NULL;
myImage = NULL;
myEnabledShapes = NULL;
myNotePoints = NULL;
}
//=======================================================================
@@ -50,5 +53,8 @@ XCAFView_Object::XCAFView_Object(const Handle(XCAFView_Object)& theObj)
myBackPlaneDistance = theObj->myBackPlaneDistance;
myViewVolumeSidesClipping = theObj->myViewVolumeSidesClipping;
myGDTPoints = NULL;
myImage = theObj->myImage;
myEnabledShapes = NULL;
myGDTPoints = NULL;
}

View File

@@ -26,6 +26,8 @@
#include <TColgp_HArray1OfPnt.hxx>
#include <TCollection_HAsciiString.hxx>
#include <XCAFView_ProjectionType.hxx>
#include <TColStd_HArray1OfByte.hxx>
#include <TColStd_HArray1OfBoolean.hxx>
class XCAFView_Object;
DEFINE_STANDARD_HANDLE(XCAFView_Object, Standard_Transient)
@@ -218,6 +220,92 @@ public:
return gp_Pnt();
}
Standard_EXPORT void SetImage(Handle(TColStd_HArray1OfByte) theImage)
{
myImage = theImage;
}
Standard_EXPORT Handle(TColStd_HArray1OfByte) Image()
{
return myImage;
}
Standard_EXPORT Standard_Boolean HasImage()
{
return (!myImage.IsNull());
}
Standard_EXPORT void CreateEnabledShapes(const Standard_Integer theLenght)
{
if (theLenght > 0)
myEnabledShapes = new TColStd_HArray1OfBoolean(1, theLenght);
}
Standard_EXPORT Standard_Boolean HasEnabledShapes()
{
return (!myEnabledShapes.IsNull());
}
Standard_EXPORT Standard_Integer NbEnabledShapes()
{
if (myEnabledShapes.IsNull())
return 0;
return myEnabledShapes->Length();
}
Standard_EXPORT void SetEnabledShape(const Standard_Integer theIndex, const bool theVal)
{
if (myEnabledShapes.IsNull())
return;
if (theIndex > 0 && theIndex <= myEnabledShapes->Length())
myEnabledShapes->SetValue(theIndex, theVal);
}
Standard_EXPORT bool EnabledShape(const Standard_Integer theIndex)
{
if (myEnabledShapes.IsNull())
return Standard_False;
if (theIndex > 0 && theIndex <= myEnabledShapes->Length())
return myEnabledShapes->Value(theIndex);
else
return Standard_False;
}
Standard_EXPORT void CreateNotePoints(const Standard_Integer theLenght)
{
if (theLenght > 0)
myNotePoints = new TColgp_HArray1OfPnt(1, theLenght);
}
Standard_EXPORT Standard_Boolean HasNotePoints()
{
return (!myNotePoints.IsNull());
}
Standard_EXPORT Standard_Integer NbNotePoints()
{
if (myNotePoints.IsNull())
return 0;
return myNotePoints->Length();
}
Standard_EXPORT void SetNotePoint(const Standard_Integer theIndex, const gp_Pnt thePoint)
{
if (myNotePoints.IsNull())
return;
if (theIndex > 0 && theIndex <= myNotePoints->Length())
myNotePoints->SetValue(theIndex, thePoint);
}
Standard_EXPORT gp_Pnt NotePoint(const Standard_Integer theIndex)
{
if (myNotePoints.IsNull())
return gp_Pnt();
if (theIndex > 0 && theIndex <= myNotePoints->Length())
return myNotePoints->Value(theIndex);
else
return gp_Pnt();
}
DEFINE_STANDARD_RTTIEXT(XCAFView_Object,Standard_Transient)
private:
@@ -237,6 +325,9 @@ private:
Standard_Real myBackPlaneDistance;
Standard_Boolean myViewVolumeSidesClipping;
Handle(TColgp_HArray1OfPnt) myGDTPoints; // Point for each GDT to describe position of GDT frame in View.
Handle(TColStd_HArray1OfByte) myImage;
Handle(TColStd_HArray1OfBoolean) myEnabledShapes;
Handle(TColgp_HArray1OfPnt) myNotePoints;
};
#endif // _XCAFView_Object_HeaderFile

View File

@@ -16,3 +16,6 @@ XDEDRAW_Views.cxx
XDEDRAW_Views.hxx
XDEDRAW_Notes.cxx
XDEDRAW_Notes.hxx
XDEDRAW_Animations.cxx
XDEDRAW_Animations.hxx

View File

@@ -88,6 +88,7 @@
#include <XDEDRAW_GDTs.hxx>
#include <XDEDRAW_Views.hxx>
#include <XDEDRAW_Notes.hxx>
#include <XDEDRAW_Animations.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWIGES.hxx>
#include <XSDRAWSTEP.hxx>
@@ -1201,6 +1202,7 @@ void XDEDRAW::Init(Draw_Interpretor& di)
XDEDRAW_GDTs::InitCommands ( di );
XDEDRAW_Views::InitCommands(di);
XDEDRAW_Notes::InitCommands(di);
XDEDRAW_Animations::InitCommands( di );
XDEDRAW_Common::InitCommands ( di );//moved from EXE
}

View File

@@ -0,0 +1,376 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 <DDocStd.hxx>
#include <OSD_File.hxx>
#include <OSD_Protection.hxx>
#include <TDocStd_Document.hxx>
#include <TDF_Tool.hxx>
#include <TCollection_HAsciiString.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_AnimationTool.hxx>
#include <XDEDRAW_Animations.hxx>
#include <XCAFDoc_Animation.hxx>
struct cmd
{
const char* name;
Standard_Integer nargsreq;
const char* use;
};
//=======================================================================
//function : animations
//purpose : returns list of all animations
//=======================================================================
static const cmd XAnimations = {
"XAnimations", 2, "XAnimations Doc"
};
static Standard_Integer
animations(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimations;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[1], aDoc);
if (aDoc.IsNull())
{
return 1;
}
Handle(XCAFDoc_AnimationTool) anAnimTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
TDF_LabelSequence anAnimations;
anAnimTool->GetAnimationLabels(anAnimations);
for (TDF_LabelSequence::Iterator anIt(anAnimations); anIt.More(); anIt.Next())
{
TCollection_AsciiString anEntry;
TDF_Tool::Entry(anIt.Value(), anEntry);
di << anEntry << " ";
}
return 0;
}
//=======================================================================
//function : addAnimation
//purpose : add animation
//=======================================================================
static const cmd XAnimationAdd = {
"XAnimationAdd", 6, "XAnimationAdd Doc name --file image_path animation_path | --data image_data animation_data"
};
static Standard_Integer
addAnimation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimationAdd;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Standard_Integer iarg = 0;
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[++iarg], aDoc);
if (aDoc.IsNull())
{
return 1;
}
TCollection_ExtendedString aName = argv[++iarg];
Standard_Boolean aFromFile = Standard_False;
Standard_Boolean aFromData = Standard_False;
TCollection_ExtendedString anImageFileStr;
TCollection_ExtendedString anAnimationFileStr;
Handle(TColStd_HArray1OfByte) anImage;
Handle(TColStd_HArray1OfByte) anAnimation;
for (++iarg; iarg < argc; ++iarg)
{
TCollection_AsciiString opt = argv[iarg];
if (opt == "--file")
{
if (aFromData)
{
di << "Error: data can be taken either from a file or a data array.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
if (++iarg >= argc)
{
di << "Error: file image path is expected.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
anImageFileStr = argv[iarg];
if (++iarg >= argc)
{
di << "Error: file animation path is expected.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
anAnimationFileStr = argv[iarg];
aFromFile = Standard_True;
}
else if (opt == "--data")
{
if (aFromFile)
{
di << "Error: data can be taken either from a file or a data array.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
if (++iarg >= argc)
{
di << "Error: image data array is expected.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
Standard_SStream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
ss << argv[iarg];
Standard_Integer len = static_cast<Standard_Integer>(ss.tellp());
anImage = new TColStd_HArray1OfByte(1, len);
for (Standard_Integer i = 1; i <= len && !ss.eof(); ++i)
{
ss >> anImage->ChangeValue(i);
}
if (++iarg >= argc)
{
di << "Error: animation data array is expected.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
Standard_SStream ssAn(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
ssAn << argv[iarg];
len = static_cast<Standard_Integer>(ss.tellp());
anAnimation = new TColStd_HArray1OfByte(1, len);
for (Standard_Integer i = 1; i <= len && !ss.eof(); ++i)
{
ssAn >> anAnimation->ChangeValue(i);
}
aFromData = Standard_True;
}
}
Handle(XCAFDoc_AnimationTool) anAnimationTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
TDF_Label aLabel;
if (aFromFile)
{
OSD_Path anImagePath(anImageFileStr);
OSD_File anImageFile(anImagePath);
anImageFile.Open(OSD_ReadOnly, OSD_Protection());
OSD_Path anAnimPath(anAnimationFileStr);
OSD_File anAnimFile(anAnimPath);
anAnimFile.Open(OSD_ReadOnly, OSD_Protection());
aLabel = anAnimationTool->AddAnimation(new TCollection_HAsciiString(aName), anImageFile, anAnimFile);
}
else if (aFromData)
{
aLabel = anAnimationTool->AddAnimation(new TCollection_HAsciiString(aName), anImage, anAnimation);
}
else
{
di << "Error: data can be taken either from a file or a data array.\n";
di << "Use: " << myCommand.use << "\n";
return 1;
}
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aLabel, anEntry);
di << anEntry;
return 0;
}
//=======================================================================
//function : removeAnimation
//purpose : deletes an animation
//=======================================================================
static const cmd XAnimationRemove = {
"XAnimationRemove", 3, "XAnimationRemove Doc animation"
};
static Standard_Integer
removeAnimation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimationRemove;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[1], aDoc);
if (aDoc.IsNull())
{
return 1;
}
TCollection_ExtendedString anEntry = argv[2];
TDF_Label aLabel;
TDF_Tool::Label(aDoc->GetData(), anEntry, aLabel);
if (aLabel.IsNull())
{
di << anEntry << ": invalid animation entry.\n";
return 1;
}
Handle(XCAFDoc_AnimationTool) anAnimationTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
if (!anAnimationTool->RemoveAnimation(aLabel))
{
di << "Error: couldn't remove animation.\n";
return 1;
}
return 0;
}
//=======================================================================
//function : animationDump
//purpose : dump an animation
//=======================================================================
static const cmd XAnimationDump = {
"XAnimationDump", 3, "XAnimationDump Doc animation"
};
static Standard_Integer
animationDump(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimationDump;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Standard_Integer iarg = 0;
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[++iarg], aDoc);
if (aDoc.IsNull())
{
return 1;
}
TCollection_AsciiString anEntry = argv[++iarg];
TDF_Label aLabel;
TDF_Tool::Label(aDoc->GetData(), anEntry, aLabel);
if (aLabel.IsNull())
{
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aLabel, anEntry);
di << anEntry << ": invalid animation entry.\n";
return 1;
}
Handle(XCAFDoc_AnimationTool) anAnimTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
Handle(TCollection_HAsciiString) aName;
Handle(TColStd_HArray1OfByte) anImage, anAnimation;
anAnimTool->GetAnimation(aLabel, aName, anImage, anAnimation);
if (!aName.IsNull())
{
di <<"Name : " << aName->ToCString() << "\n";
}
static Standard_Integer theMaxLen = 64;
if (!anImage.IsNull())
{
di << "Image size : " << anImage->Length()<<"\n";
}
else
{
di << "Image is NULL \n ";
}
if (!anAnimation.IsNull())
{
di << "Animation size : " << anAnimation->Length()<<"\n";
}
else
{
di << "Animation is NULL \n ";
}
return 0;
}
//=======================================================================
//function : setName
//purpose : rename animation
//=======================================================================
static const cmd XAnimationSetName = {
"XAnimationSetName", 4, "XAnimationSetName Doc animation new_name"
};
static Standard_Integer
setName(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
static const cmd& myCommand = XAnimationSetName;
if (argc < myCommand.nargsreq)
{
di << "Use: " << myCommand.use << "\n";
return 1;
}
Handle(TDocStd_Document) aDoc;
DDocStd::GetDocument(argv[1], aDoc);
if (aDoc.IsNull())
{
return 1;
}
TCollection_ExtendedString anEntry = argv[2];
TDF_Label aLabel;
TDF_Tool::Label(aDoc->GetData(), anEntry, aLabel);
if (aLabel.IsNull())
{
di << anEntry << ": invalid animation entry.\n";
return 1;
}
Handle(XCAFDoc_AnimationTool) anAnimTool = XCAFDoc_DocumentTool::AnimationTool(aDoc->Main());
anAnimTool->SetName(aLabel, new TCollection_HAsciiString(argv[3]));
return 0;
}
//=======================================================================
//function : InitCommands
//purpose :
//=======================================================================
void XDEDRAW_Animations::InitCommands(Draw_Interpretor& di)
{
static Standard_Boolean initialized = Standard_False;
if (initialized)
{
return;
}
initialized = Standard_True;
Standard_CString g = "XDE Animations commands";
di.Add(XAnimations.name, XAnimations.use, __FILE__, animations, g);
di.Add(XAnimationAdd.name, XAnimationAdd.use, __FILE__, addAnimation, g);
di.Add(XAnimationRemove.name, XAnimationRemove.use, __FILE__, removeAnimation, g);
di.Add(XAnimationDump.name, XAnimationDump.use, __FILE__, animationDump, g);
di.Add(XAnimationSetName.name, XAnimationSetName.use, __FILE__, setName, g);
}

View File

@@ -0,0 +1,35 @@
// Created on: 2017-10-02
// Created by: Elena Mozokhina
// Copyright (c) 2016 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 _XDEDRAW_Animations_HeaderFile
#define _XDEDRAW_Animations_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
#include <Draw_Interpretor.hxx>
//! Contains commands to work with notes
class XDEDRAW_Animations
{
public:
DEFINE_STANDARD_ALLOC
Standard_EXPORT static void InitCommands (Draw_Interpretor& theCommands);
};
#endif // _XDEDRAW_Animations_HeaderFile

View File

@@ -49,6 +49,26 @@
#include <TopoDS_Shape.hxx>
#include <Interface_Static.hxx>
#include <BRep_Builder.hxx>
#include <OSD_Path.hxx>
#include <OSD_DirectoryIterator.hxx>
#include <OSD_FileIterator.hxx>
#include <TopoDS_Compound.hxx>
#include <VrmlData_Scene.hxx>
#include <ShapeUpgrade_UnifySameDomain.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <XCAFDoc_ColorTool.hxx>
#include <BRepClass3d_SolidClassifier.hxx>
#include <Poly_Triangulation.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <VrmlData_ShapeNode.hxx>
#include <VrmlData_Group.hxx>
#include <StlAPI.hxx>
#include <stdio.h>
//============================================================
// Support for several models in DRAW
@@ -517,6 +537,591 @@ static Standard_Integer Expand (Draw_Interpretor& di, Standard_Integer argc, con
return 0;
}
//=======================================================================
//function : ReadVrml
//purpose : Read VRML file to DECAF document
//=======================================================================
TDF_Label ReadVrmlRec(const OSD_Path& thePath, const Handle(TDocStd_Document)& theDoc, const TDF_Label& theLabel)
{
TDF_Label aNewLabel;
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool( theDoc->Main() );
// Get path of the VRML file.
TCollection_AsciiString aVrmlDir(".");
TCollection_AsciiString aDisk = thePath.Disk();
TCollection_AsciiString aTrek = thePath.Trek();
TCollection_AsciiString aName = thePath.Name();
TCollection_AsciiString anExt = thePath.Extension();
cout << "==============================================================" << endl;
if (!aTrek.IsEmpty())
{
if (!aDisk.IsEmpty())
aVrmlDir = aDisk;
else
aVrmlDir.Clear();
aTrek.ChangeAll('|', '/');
aTrek.ChangeAll('\\', '/');
aVrmlDir += aTrek;
if (!aName.IsEmpty())
aVrmlDir += aName;
if (!anExt.IsEmpty())
aVrmlDir += anExt;
}
// Analize the passed Path
if (thePath.Extension() == ".wrl")
{
// Read shape from vrml and add to parent as component
TopoDS_Shape aShape ;
VrmlData_DataMapOfShapeAppearance aShapeAppMap;
filebuf aFic;
istream aStream (&aFic);
if (aFic.open(aVrmlDir.ToCString(), ios::in))
{
cout << "Reading file " << aVrmlDir.ToCString() << "..." << endl;
VrmlData_Scene aScene;
aScene.SetVrmlDir(aVrmlDir);
aScene << aStream;
aFic.close();
if (aScene.Status() == VrmlData_StatusOK)
{
aShape = aScene.GetShape(aShapeAppMap);
if (aShape.IsNull())
{
cout << "Shape was not extracted from file " << aVrmlDir.ToCString() << "..." << endl;
return aNewLabel;
}
TopExp_Explorer anExp;
Quantity_Color aFaceColor;
Quantity_Color anEdgeColor(Quantity_NOC_BLACK);
for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next())
{
if (aShapeAppMap.IsBound(anExp.Current().TShape()))
{
Handle(VrmlData_Appearance) anAppearance = aShapeAppMap.Find(anExp.Current().TShape());
if (!anAppearance.IsNull() && !anAppearance->Material().IsNull())
{
aFaceColor = anAppearance->Material()->DiffuseColor();
break;
}
}
}
//Standard_Boolean isSingleShell = Standard_False;
//TopoDS_Shell aShell;
//for (anExp.Init(aShape, TopAbs_SHELL); anExp.More(); anExp.Next())
//{
// if (!anExp.Current().IsNull() && anExp.Current().ShapeType() == TopAbs_SHELL)
// {
// if (!isSingleShell)
// {
// aShell = TopoDS::Shell(anExp.Current());
// isSingleShell = Standard_True;
// }
// else
// {
// isSingleShell = Standard_False;
// break;
// }
// }
//}
//Standard_Boolean hasCylindrical = Standard_False;
//if (!aShell.IsNull() && isSingleShell)
//{
// for (anExp.Init(aShell, TopAbs_FACE); anExp.More(); anExp.Next())
// {
// if (!anExp.Current().IsNull())
// {
// const TopoDS_Face& aFace = TopoDS::Face(anExp.Current());
// Handle(Geom_CylindricalSurface) aSurf = Handle(Geom_CylindricalSurface)::DownCast(BRep_Tool::Surface(aFace));
// if (!aSurf.IsNull())
// hasCylindrical = Standard_True;
// }
// }
//}
//if (hasCylindrical)
// aShape = aShell;
//else
// isSingleShell = Standard_False;
//if (!isSingleShell)
//{
// Standard_Boolean doTriangulation = Standard_False;
// for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next())
// {
// TopLoc_Location aDummy;
// if (BRep_Tool::Triangulation(TopoDS::Face(anExp.Current()), aDummy).IsNull())
// {
// doTriangulation = Standard_True;
// break;
// }
// }
// if (doTriangulation)
// {
// BRepMesh_IncrementalMesh aMesh(aShape, 1);
// aMesh.Perform();
// if (aMesh.IsDone())
// aShape = aMesh.Shape();
// }
// // Write to STL and then read again to get BRep model (vrml fills only triangulation)
// StlAPI::Write(aShape, vrmlTempFile);
// StlAPI::Read(aShape, vrmlTempFile);
//}
/*if (aShape.IsNull())
return aNewLabel;*/
/*ShapeUpgrade_UnifySameDomain anUSD(aShape);
anUSD.SetLinearTolerance(1e-5);
anUSD.Build();
aShape = anUSD.Shape();
if (aShape.ShapeType() == TopAbs_SHELL && TopoDS::Shell(aShape).Closed())
{
TopoDS_Solid aSolid;
TopoDS_Shell aShell = TopoDS::Shell (aShape);
if (!aShell.Free ()) {
aShell.Free(Standard_True);
}
BRep_Builder aBuilder;
aBuilder.MakeSolid (aSolid);
aBuilder.Add (aSolid, aShell);
Standard_Boolean isOk = Standard_True;
try {
OCC_CATCH_SIGNALS
BRepClass3d_SolidClassifier bsc3d (aSolid);
Standard_Real t = Precision::Confusion();
bsc3d.PerformInfinitePoint(t);
if (bsc3d.State() == TopAbs_IN) {
TopoDS_Solid aSolid2;
aBuilder.MakeSolid (aSolid2);
aShell.Reverse();
aBuilder.Add (aSolid2, aShell);
aSolid = aSolid2;
}
}
catch (Standard_Failure) { isOk = Standard_False; }
if (isOk) aShape = aSolid;
}*/
if (theLabel.IsNull() || !aShapeTool->IsAssembly(theLabel))
{
// Add new shape
aNewLabel = aShapeTool->AddShape(aShape, Standard_False);
cout << "Created new shape " << thePath.Name() << " (free)" << endl;
}
else if (!theLabel.IsNull() && aShapeTool->IsAssembly(theLabel))
{
// Add shape as component
aNewLabel = aShapeTool->AddComponent(theLabel, aShape);
Handle(TDataStd_Name) anAttrName;
theLabel.FindAttribute(TDataStd_Name::GetID(), anAttrName);
cout << "Created new shape " << thePath.Name() << " as part of " << (anAttrName.IsNull()? "(noname)" : TCollection_AsciiString(anAttrName->Get())) << endl;
if ( aShapeTool->IsReference(aNewLabel) )
{
TDF_Label RefLabel;
if ( aShapeTool->GetReferredShape(aNewLabel, RefLabel) )
aNewLabel = RefLabel;
}
}
if (!aNewLabel.IsNull())
TDataStd_Name::Set(aNewLabel, thePath.Name());
aColorTool->SetColor(aNewLabel, aFaceColor, XCAFDoc_ColorSurf);
aColorTool->SetColor(aNewLabel, anEdgeColor, XCAFDoc_ColorCurv);
return aNewLabel;
}
else
{
cout << "Error during reading of vrml file " << aVrmlDir.ToCString() << endl;
}
}
else
{
cout << "Cannot open file " << aVrmlDir.ToCString() << endl;
}
}
else if (thePath.Extension().IsEmpty())
{
cout << "Scaning root " << aVrmlDir.ToCString() << "..." << endl;
OSD_DirectoryIterator aDirIt(thePath, "*");
OSD_FileIterator aFileIt(thePath, "*.wrl");
// Check real dircetories
OSD_Path aSubDirPath;
TCollection_AsciiString aTempName;
Standard_Boolean isSubDirExist = Standard_False;
for (; aDirIt.More(); aDirIt.Next())
{
aDirIt.Values().Path(aSubDirPath);
aTempName = aSubDirPath.Name() + aSubDirPath.Extension();
if (aTempName != "." && aTempName != "..")
{
isSubDirExist = Standard_True;
break;
}
}
aDirIt.Initialize(thePath, "*"); // Re-initialize
if (!isSubDirExist && !aFileIt.More())
{
cout << "No files or directories detected in " << aVrmlDir.ToCString() << endl;
}
else
{
// Create assembly
TopoDS_Compound aComp;
BRep_Builder aBuilder;
aBuilder.MakeCompound(aComp);
if (theLabel.IsNull() || !aShapeTool->IsAssembly(theLabel))
{
// Add new shape
aNewLabel = aShapeTool->AddShape(aComp);
cout << "Created new assembly " << thePath.Name() << " (free)" << endl;
}
else if (!theLabel.IsNull() && aShapeTool->IsAssembly(theLabel))
{
// Add shape as component
aNewLabel = aShapeTool->AddComponent(theLabel, aComp, Standard_True);
Handle(TDataStd_Name) anAttrName;
theLabel.FindAttribute(TDataStd_Name::GetID(), anAttrName);
cout << "Created new assembly " << thePath.Name() << " as part of " << (anAttrName.IsNull()? "(noname)" : TCollection_AsciiString(anAttrName->Get())) << endl;
if ( aShapeTool->IsReference(aNewLabel) )
{
TDF_Label RefLabel;
if ( aShapeTool->GetReferredShape(aNewLabel, RefLabel) )
aNewLabel = RefLabel;
}
}
if (!aNewLabel.IsNull())
TDataStd_Name::Set(aNewLabel, thePath.Name());
// Add components
for (; aDirIt.More(); aDirIt.Next())
{
aDirIt.Values().Path(aSubDirPath);
aTempName = aSubDirPath.Name() + aSubDirPath.Extension();
if (aTempName == "." || aTempName == "..")
continue;
aSubDirPath.SetDisk(thePath.Disk());
aSubDirPath.SetTrek(thePath.Trek() + thePath.Name());
ReadVrmlRec(aSubDirPath, theDoc, aNewLabel);
}
for (; aFileIt.More(); aFileIt.Next())
{
aFileIt.Values().Path(aSubDirPath);
aSubDirPath.SetDisk(thePath.Disk());
aSubDirPath.SetTrek(thePath.Trek() + thePath.Name());
ReadVrmlRec(aSubDirPath, theDoc, aNewLabel);
}
aShapeTool->UpdateAssemblies();
}
// At the end of operation update assemblies
}
else
{
cout << "Unknown file format: " << thePath.Extension() << endl;
}
return aNewLabel;
}
//=======================================================================
//function : HaveShapeNode
//purpose : Check that VRML node have Shape
//=======================================================================
Standard_Boolean HaveShapeNode (const Handle (VrmlData_Node)& theNode)
{
// Try a Shape type of node.
const Handle (VrmlData_ShapeNode) aShapeNode = Handle (VrmlData_ShapeNode)::DownCast (theNode);
if (!aShapeNode.IsNull ())
{
const Handle (VrmlData_Geometry) aGeometry = aShapeNode->Geometry ();
if (!aGeometry.IsNull ())
{
const Handle (TopoDS_TShape) aTShape = aGeometry->TShape ();
if (!aTShape.IsNull ())
{
return Standard_True;
}
}
}
// Try a Group type of node.
const Handle (VrmlData_Group) aGroupNode = Handle (VrmlData_Group)::DownCast (theNode);
if (!aGroupNode.IsNull ())
{
for (VrmlData_Group::Iterator anIt = aGroupNode->NodeIterator (); anIt.More (); anIt.Next ())
{
if (HaveShapeNode (anIt.Value ()))
{
return Standard_True;
}
}
}
return Standard_False;
}
//=======================================================================
//function : ReadVrmlNode
//purpose : Read VRML node to DECAF document
//=======================================================================
TDF_Label ReadVrmlNode (const Handle(VrmlData_Node)& theNode,
const Handle(TDocStd_Document)& theDoc,
const TDF_Label& theLabel = TDF_Label())
{
TDF_Label aNewLabel;
Handle (XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (theDoc->Main ());
Handle (XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (theDoc->Main ());
// Try a Shape type of node.
const Handle (VrmlData_ShapeNode) aShapeNode = Handle (VrmlData_ShapeNode)::DownCast (theNode);
if (!aShapeNode.IsNull ())
{
const Handle (VrmlData_Geometry) aGeometry = aShapeNode->Geometry ();
if (!aGeometry.IsNull ())
{
const Handle (TopoDS_TShape) aTShape = aGeometry->TShape ();
if (!aTShape.IsNull ())
{
TopoDS_Shape aShape;
aShape.Orientation (TopAbs_FORWARD);
aShape.TShape (aTShape);
if (theLabel.IsNull () || !aShapeTool->IsAssembly (theLabel))
{
// Add new shape.
aNewLabel = aShapeTool->AddShape (aShape, Standard_False);
}
else if (!theLabel.IsNull() && aShapeTool->IsAssembly (theLabel))
{
// Add shape as component.
aNewLabel = aShapeTool->AddComponent (theLabel, aShape);
if (aShapeTool->IsReference (aNewLabel))
{
TDF_Label aRefLabel;
if (aShapeTool->GetReferredShape (aNewLabel, aRefLabel))
{
aNewLabel = aRefLabel;
}
}
}
if (!aNewLabel.IsNull ())
{
TDataStd_Name::Set (aNewLabel, aShapeNode->Name ());
Quantity_Color aFaceColor;
Quantity_Color anEdgeColor (Quantity_NOC_BLACK);
const Handle (VrmlData_Appearance) anAppearance = aShapeNode->Appearance ();
if (!anAppearance.IsNull ())
{
aFaceColor = anAppearance->Material ()->DiffuseColor ();
}
aColorTool->SetColor (aNewLabel, aFaceColor, XCAFDoc_ColorSurf);
aColorTool->SetColor (aNewLabel, anEdgeColor, XCAFDoc_ColorCurv);
}
}
}
}
// Try a Group type of node.
const Handle (VrmlData_Group) aGroupNode = Handle (VrmlData_Group)::DownCast (theNode);
if (!aGroupNode.IsNull ()/* && HaveShapeNode (aGroupNode)*/)
{
// Create assembly
TopoDS_Compound aCompound;
BRep_Builder aBuilder;
aBuilder.MakeCompound (aCompound);
aCompound.Location (aGroupNode->GetTransform ());
if (theLabel.IsNull () || !aShapeTool->IsAssembly (theLabel))
{
// Add new shape.
aNewLabel = aShapeTool->AddShape (aCompound);
}
else if (!theLabel.IsNull () && aShapeTool->IsAssembly (theLabel))
{
// Add shape as component.
aNewLabel = aShapeTool->AddComponent (theLabel, aCompound, Standard_True);
if (aShapeTool->IsReference (aNewLabel))
{
TDF_Label aRefLabel;
if (aShapeTool->GetReferredShape (aNewLabel, aRefLabel))
{
aNewLabel = aRefLabel;
}
}
}
if (!aNewLabel.IsNull ())
{
TDataStd_Name::Set (aNewLabel, aGroupNode->Name ());
}
// Add components.
for (VrmlData_Group::Iterator anIt = aGroupNode->NodeIterator (); anIt.More (); anIt.Next ())
{
ReadVrmlNode (anIt.Value (), theDoc, aNewLabel);
}
aShapeTool->UpdateAssemblies();
}
return aNewLabel;
}
//=======================================================================
//function : ReadSingleVrml
//purpose : Read VRML file to DECAF document
//=======================================================================
bool ReadSingleVrml (const OSD_Path& thePath, const Handle (TDocStd_Document)& theDoc)
{
// Get path of the VRML file.
TCollection_AsciiString aPath (".");
TCollection_AsciiString aDisk = thePath.Disk ();
TCollection_AsciiString aTrek = thePath.Trek ();
TCollection_AsciiString aName = thePath.Name ();
TCollection_AsciiString anExt = thePath.Extension ();
if (!aTrek.IsEmpty())
{
if (!aDisk.IsEmpty())
{
aPath = aDisk;
}
else
{
aPath.Clear ();
}
aTrek.ChangeAll ('|', '/');
aTrek.ChangeAll ('\\', '/');
aPath += aTrek;
if (!aName.IsEmpty())
{
aPath += aName;
}
if (!anExt.IsEmpty())
{
aPath += anExt;
}
}
// Analize the passed path.
if (anExt != ".wrl")
{
std::cerr << "Reading failed. Unknown file format: " << anExt << std::endl;
return false;
}
// Open file.
filebuf aFileBuf;
aFileBuf.open (aPath.ToCString (), ios::in);
if (aFileBuf.is_open () == Standard_False)
{
std::cerr << "Reading failed. Can not open file: " << aPath.ToCString () << std::endl;
return false;
}
// Read vrml file.
Standard_IStream aStream (&aFileBuf);
VrmlData_Scene aScene;
aScene.SetVrmlDir (aPath);
aScene << aStream;
aFileBuf.close();
if (aScene.Status () != VrmlData_StatusOK)
{
std::cerr << "Reading failed. Error: " << aScene.Status () << std::endl;
return false;
}
// Read shape.
//VrmlData_DataMapOfShapeAppearance aShapeAppearMap;
//TopoDS_Shape aShape = aScene.GetShape (aShapeAppearMap);
//if (aShape.IsNull ())
//{
// std::cerr << "Reading failed. Getting TopoDS_Shape failed." << std::endl;
// return false;
//}
// Create assembly.
TopoDS_Compound aCompound;
BRep_Builder aBuilder;
aBuilder.MakeCompound (aCompound);
Handle (XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (theDoc->Main ());
TDF_Label aNewLabel = aShapeTool->AddShape (aCompound);
if (!aNewLabel.IsNull ())
{
TDataStd_Name::Set (aNewLabel, aName);
}
// Read nodes one by one and add to document.
for (VrmlData_Scene::Iterator anIt = aScene.GetIterator (); anIt.More (); anIt.Next ())
{
ReadVrmlNode (anIt.Value (), theDoc, aNewLabel);
}
aShapeTool->UpdateAssemblies();
return true;
}
static Standard_Integer ReadVrml (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if ( argc != 3 ) {
di << "Use: " << argv[0] << " Doc Path: Read VRML assembly to DECAF document\n";
return 0;
}
Handle(TDocStd_Document) doc;
if (!DDocStd::GetDocument(argv[1],doc,Standard_False))
{
Handle(TDocStd_Application) A = DDocStd::GetApplication();
A->NewDocument("BinXCAF",doc);
TDataStd_Name::Set(doc->GetData()->Root(),argv[1]);
Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc);
Draw::Set(argv[1], DD);
}
OSD_Path aPath (argv[2]);
if (aPath.Extension () == ".wrl")
{
ReadSingleVrml (aPath, doc);
}
else if (aPath.Extension ().IsEmpty ())
{
ReadVrmlRec (aPath, doc, TDF_Label ());
}
return 0;
}
void XDEDRAW_Common::InitCommands(Draw_Interpretor& di)
{
static Standard_Boolean initactor = Standard_False;
@@ -541,4 +1146,5 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& di)
di.Add("XExpand", "XExpand Doc recursively(0/1) or XExpand Doc recursively(0/1) label1 label2 ..."
"or XExpand Doc recursively(0/1) shape1 shape2 ...",__FILE__, Expand, g);
di.Add("ReadVrml" , "Doc Path: Read VRML assembly to DECAF document" ,__FILE__, ReadVrml, g);
}

View File

@@ -273,14 +273,15 @@ static Standard_Integer nbComponents (Draw_Interpretor& di, Standard_Integer arg
static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc!=4) {
di<<"Use: "<<argv[0]<<" DocName Label Shape \n";
if (argc<4) {
di<<"Use: "<<argv[0]<<" DocName Label Shape [int makeAssembly (1/0)]\n";
return 1;
}
Handle(TDocStd_Document) Doc;
DDocStd::GetDocument(argv[1], Doc);
if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
Standard_Boolean makeAssembly = Standard_True;
if ( argc==5 && Draw::Atoi(argv[4]) == 0 ) makeAssembly = Standard_False;
TDF_Label aLabel;
TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
TopoDS_Shape aShape;
@@ -288,7 +289,7 @@ static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer arg
Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
// XCAFDoc_ShapeTool myAssembly->
// myAssembly->Init(Doc);
myAssembly->AddComponent(aLabel, aShape);
myAssembly->AddComponent(aLabel, aShape, makeAssembly);
TCollection_AsciiString Entry;
TDF_Tool::Entry(aLabel, Entry);
di << Entry.ToCString();

View File

@@ -1175,8 +1175,8 @@ static Standard_Integer dump(Draw_Interpretor& di, Standard_Integer argc, const
//=======================================================================
static Standard_Integer addClippingPlane(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc < 5) {
di << "Use: XAddClippingPlane Doc plane name capping[0/1]";
if (argc < 6) {
di << "Use: XAddClippingPlane Doc plane name capping[0/1] visible[0/1]";
return 1;
}
Handle(TDocStd_Document) aDoc;
@@ -1195,8 +1195,9 @@ static Standard_Integer addClippingPlane(Draw_Interpretor& di, Standard_Integer
aPlane = aSurf->Pln();
Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(argv[3]);
Standard_Boolean aCapping = (argv[4][0] == '1');
Standard_Boolean aVisible = (argv[5][0] == '1');
TDF_Label aCPlaneL = aCPlaneTool->AddClippingPlane(aPlane, aName, aCapping);
TDF_Label aCPlaneL = aCPlaneTool->AddClippingPlane(aPlane, aName, aCapping, aVisible);
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aCPlaneL, anEntry);
di << anEntry << "\n";
@@ -1230,8 +1231,8 @@ static Standard_Integer getClippingPlane(Draw_Interpretor& di, Standard_Integer
}
gp_Pln aPlane;
Handle(TCollection_HAsciiString) aName;
Standard_Boolean aCapping;
aClippingPlaneTool->GetClippingPlane(aLabel, aPlane, aName, aCapping);
Standard_Boolean aCapping, aVisible;
aClippingPlaneTool->GetClippingPlane(aLabel, aPlane, aName, aCapping, aVisible);
Handle(Geom_Plane) aCPlane = new Geom_Plane(aPlane);
DrawTrSurf::Set(aName->ToCString(), aCPlane);
di << aName->ToCString();

View File

@@ -47,3 +47,8 @@ XmlMXCAFDoc_ViewToolDriver.cxx
XmlMXCAFDoc_ViewToolDriver.hxx
XmlMXCAFDoc_VolumeDriver.cxx
XmlMXCAFDoc_VolumeDriver.hxx
XmlMXCAFDoc_AnimationDriver.cxx
XmlMXCAFDoc_AnimationDriver.hxx
XmlMXCAFDoc_AnimationToolDriver.cxx
XmlMXCAFDoc_AnimationToolDriver.hxx

View File

@@ -0,0 +1,150 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 <Message_Messenger.hxx>
#include <Standard_Type.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TColStd_HArray1OfByte.hxx>
#include <TDF_Attribute.hxx>
#include <XCAFDoc_Animation.hxx>
#include <XmlMXCAFDoc_AnimationDriver.hxx>
#include <XmlObjMgt.hxx>
#include <XmlObjMgt_Persistent.hxx>
#include <LDOM_OSStream.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_AnimationDriver,XmlMDF_ADriver)
IMPLEMENT_DOMSTRING (AnimationName, "name")
IMPLEMENT_DOMSTRING (ImageFirstIdx, "image_first_idx")
IMPLEMENT_DOMSTRING (ImageLastIdx, "image_last_idx")
IMPLEMENT_DOMSTRING(AnimationFirstIdx, "animation_first_idx")
IMPLEMENT_DOMSTRING(AnimationLastIdx, "animation_last_idx")
//=======================================================================
//function : XmlMXCAFDoc_AnimationDriver
//purpose : Constructor
//=======================================================================
XmlMXCAFDoc_AnimationDriver::XmlMXCAFDoc_AnimationDriver
(const Handle(Message_Messenger)& theMsgDriver)
: XmlMDF_ADriver (theMsgDriver, "xcaf", "Animation")
{}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) XmlMXCAFDoc_AnimationDriver::NewEmpty() const
{
return (new XCAFDoc_Animation());
}
//=======================================================================
//function : Paste
//purpose : persistent -> transient (retrieve)
//=======================================================================
Standard_Boolean XmlMXCAFDoc_AnimationDriver::Paste
(const XmlObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
XmlObjMgt_RRelocationTable& ) const
{
const XmlObjMgt_Element& anElement = theSource;
Handle(XCAFDoc_Animation) aTarget = Handle(XCAFDoc_Animation)::DownCast(theTarget);
if (aTarget.IsNull())
return Standard_False;
XmlObjMgt_DOMString aNameStr = anElement.getAttribute(::AnimationName());
XmlObjMgt_DOMString anImageFirstIdxStr = anElement.getAttribute(::ImageFirstIdx());
XmlObjMgt_DOMString anImageLastIdxStr = anElement.getAttribute(::ImageLastIdx());
XmlObjMgt_DOMString anAnimFirstIdxStr = anElement.getAttribute(::AnimationFirstIdx());
XmlObjMgt_DOMString anAnimLastIdxStr = anElement.getAttribute(::AnimationLastIdx());
if (aNameStr == NULL || anImageFirstIdxStr == NULL || anImageLastIdxStr == NULL ||
anAnimFirstIdxStr == NULL || anAnimLastIdxStr == NULL)
return Standard_False;
Standard_Integer anImageFirstIdx = 0;
Standard_Integer anImageLastIdx = 0;
if (!anImageFirstIdxStr.GetInteger(anImageFirstIdx) || !anImageLastIdxStr.GetInteger(anImageLastIdx))
return Standard_False;
Handle(TColStd_HArray1OfByte) anImage = new TColStd_HArray1OfByte(anImageFirstIdx, anImageLastIdx);
Standard_Integer anAnimFirstIdx = 0;
Standard_Integer anAnimLastIdx = 0;
if (!anAnimFirstIdxStr.GetInteger(anAnimFirstIdx) || !anAnimLastIdxStr.GetInteger(anAnimLastIdx))
return Standard_False;
Handle(TColStd_HArray1OfByte) anAnim = new TColStd_HArray1OfByte(anAnimFirstIdx, anAnimLastIdx);
XmlObjMgt_DOMString aDataStr = XmlObjMgt::GetStringValue(theSource);
Standard_SStream anSS(aDataStr.GetString());
Standard_Byte aValue;
for (Standard_Integer i = anImageFirstIdx; i <= anImageLastIdx; ++i)
{
anSS >> aValue;
anImage->ChangeValue(i) = aValue;
}
for (Standard_Integer i = anAnimFirstIdx; i <= anAnimLastIdx; ++i)
{
anSS >> aValue;
anAnim->ChangeValue(i) = aValue;
}
aTarget->Set(new TCollection_HAsciiString(aNameStr.GetString()), anImage, anImage);
return Standard_True;
}
//=======================================================================
//function : Paste
//purpose : transient -> persistent (store)
//=======================================================================
void XmlMXCAFDoc_AnimationDriver::Paste(const Handle(TDF_Attribute)& theSource,
XmlObjMgt_Persistent& theTarget,
XmlObjMgt_SRelocationTable&) const
{
Handle(XCAFDoc_Animation) anAnimation = Handle(XCAFDoc_Animation)::DownCast(theSource);
if (anAnimation.IsNull())
return;
XmlObjMgt_DOMString aName = anAnimation->GetName()->String().ToCString();
theTarget.Element().setAttribute(::AnimationName(), aName);
Handle(TColStd_HArray1OfByte) anImage = anAnimation->GetImage();
Handle(TColStd_HArray1OfByte) anAnim = anAnimation->GetAnimation();
if (anImage.IsNull() || anAnim.IsNull())
{
return;
}
const Standard_Integer anImageFirstInd = anImage->Lower();
const Standard_Integer anImageLastInd = anAnim->Upper();
const Standard_Integer anAnimFirstInd = anAnim->Lower();
const Standard_Integer anAnimLastInd = anAnim->Upper();
const Standard_Integer aMaxSize = anImageLastInd - anImageFirstInd + anAnimLastInd - anAnimFirstInd + 2;
LDOM_OSStream anOSS(aMaxSize);
for (Standard_Integer i = anImageFirstInd; i <= anImageLastInd; ++i)
{
anOSS << std::hex << anImage->Value(i);
}
for (Standard_Integer i = anAnimFirstInd; i <= anAnimLastInd; ++i)
{
anOSS << std::hex << anAnim->Value(i);
}
Standard_Character* dump = (Standard_Character*)anOSS.str(); // copying! Don't forget to delete it.
XmlObjMgt::SetStringValue(theTarget, dump, Standard_True);
delete[] dump;
}

View File

@@ -0,0 +1,51 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 _XmlMXCAFDoc_AnimationDriver_HeaderFile
#define _XmlMXCAFDoc_AnimationDriver_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <XmlMDF_ADriver.hxx>
#include <Standard_Boolean.hxx>
#include <XmlObjMgt_RRelocationTable.hxx>
#include <XmlObjMgt_SRelocationTable.hxx>
class Message_Messenger;
class TDF_Attribute;
class XmlObjMgt_Persistent;
class XmlMXCAFDoc_AnimationDriver;
DEFINE_STANDARD_HANDLE(XmlMXCAFDoc_AnimationDriver, XmlMDF_ADriver)
//! Attribute Driver.
class XmlMXCAFDoc_AnimationDriver : public XmlMDF_ADriver
{
public:
Standard_EXPORT XmlMXCAFDoc_AnimationDriver(const Handle(Message_Messenger)& theMessageDriver);
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT Standard_Boolean Paste (const XmlObjMgt_Persistent& Source, const Handle(TDF_Attribute)& Target, XmlObjMgt_RRelocationTable& RelocTable) const Standard_OVERRIDE;
Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Source, XmlObjMgt_Persistent& Target, XmlObjMgt_SRelocationTable& RelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XmlMXCAFDoc_AnimationDriver,XmlMDF_ADriver)
};
#endif // _XmlMXCAFDoc_AnimationDriver_HeaderFile

View File

@@ -0,0 +1,63 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 <Message_Messenger.hxx>
#include <Standard_Type.hxx>
#include <TDF_Attribute.hxx>
#include <XCAFDoc_AnimationTool.hxx>
#include <XmlMXCAFDoc_AnimationToolDriver.hxx>
#include <XmlObjMgt_Persistent.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_AnimationToolDriver,XmlMDF_ADriver)
//=======================================================================
//function :
//purpose :
//=======================================================================
XmlMXCAFDoc_AnimationToolDriver::XmlMXCAFDoc_AnimationToolDriver
(const Handle(Message_Messenger)& theMsgDriver)
: XmlMDF_ADriver (theMsgDriver, "xcaf", "AnimationTool")
{
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Handle(TDF_Attribute) XmlMXCAFDoc_AnimationToolDriver::NewEmpty() const
{
return new XCAFDoc_AnimationTool();
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Standard_Boolean XmlMXCAFDoc_AnimationToolDriver::Paste(const XmlObjMgt_Persistent& ,
const Handle(TDF_Attribute)& ,
XmlObjMgt_RRelocationTable& ) const
{
return Standard_True;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
void XmlMXCAFDoc_AnimationToolDriver::Paste(const Handle(TDF_Attribute)& ,
XmlObjMgt_Persistent& ,
XmlObjMgt_SRelocationTable& ) const
{
}

View File

@@ -0,0 +1,52 @@
// Created on: 2017-10-02
// Created by: Elena MOZOKHINA
// Copyright (c) 2016 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 _XmlMXCAFDoc_AnimationToolDriver_HeaderFile
#define _XmlMXCAFDoc_AnimationToolDriver_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <XmlMDF_ADriver.hxx>
#include <Standard_Boolean.hxx>
#include <XmlObjMgt_RRelocationTable.hxx>
#include <XmlObjMgt_SRelocationTable.hxx>
class Message_Messenger;
class TDF_Attribute;
class XmlObjMgt_Persistent;
class XmlMXCAFDoc_AnimationToolDriver;
DEFINE_STANDARD_HANDLE(XmlMXCAFDoc_AnimationToolDriver, XmlMDF_ADriver)
//! Attribute Driver.
class XmlMXCAFDoc_AnimationToolDriver : public XmlMDF_ADriver
{
public:
Standard_EXPORT XmlMXCAFDoc_AnimationToolDriver(const Handle(Message_Messenger)& theMsgDriver);
Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean Paste (const XmlObjMgt_Persistent& theSource, const Handle(TDF_Attribute)& theTarget, XmlObjMgt_RRelocationTable& theRelocTable) const Standard_OVERRIDE;
Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& theSource, XmlObjMgt_Persistent& theTarget, XmlObjMgt_SRelocationTable& theRelocTable) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(XmlMXCAFDoc_AnimationToolDriver,XmlMDF_ADriver)
};
#endif // _XmlMXCAFDoc_AnimationToolDriver_HeaderFile

View File

@@ -46,6 +46,7 @@ vclipplane change pln2 equation -0.707 0.707 0 -25
vclipplane change pln2 capping on
vclipplane change pln2 capping color 0.5 0.5 0.9
vclipplane change pln2 capping hatch on
vclipplane change pln2 capping hatchStipple 7
vclipplane set pln2 object b3
checkcolor $x3_coord $y3_coord 0.5 0.5 0.9

View File

@@ -72,5 +72,5 @@ vdisplay pp1 pp2
vzoom 0.8
puts "Enable capping planes"
vclipplane pln1 -set -equation 0 0 -1 $aPln1Z -capping 1 -color 0.5 0.5 0.5 -texname $aHatch -texscale 0.02 -0.02 -useObjMaterial 1
vclipplane pln2 -set -equation 0 1 0 [expr -$aPln2Y] -capping 1 -color 0.8 0.8 0.9 -texname $aHatch -texscale 0.02 -0.02
vclipplane pln1 -set -equation 0 0 -1 $aPln1Z -capping 1 -color 0.5 0.5 0.5 -hatchtexture $aHatch -hatchscale 0.02 -0.02 -useObjMaterial 1
vclipplane pln2 -set -equation 0 1 0 [expr -$aPln2Y] -capping 1 -color 0.8 0.8 0.9 -hatchtexture $aHatch -hatchscale 0.02 -0.02

View File

@@ -0,0 +1,64 @@
puts "=================================="
puts "AIS_ViewCube - display and erase with default settings"
puts "=================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
set anImage3 $imagedir/${casename}_3.png
set anImage4 $imagedir/${casename}_4.png
vclear
vclose ALL
vinit
# -------------------------------------
# create helper object
# -------------------------------------
box aBox1 15 20 70
vdisplay aBox1 -dispMode 1
vaxo
vfit
# -------------------------------------
# display view cube object
# -------------------------------------
vviewcube -enable -size 70 -adaptsize -position 120 250
vmoveto 118 230
if {[vreadpixel 118 230 name] != "DARKTURQUOISE 1"} {
puts "ERROR: Highlighting of view cube side is wrong."
}
vmoveto 0 0
vdump $anImage1
# -------------------------------------
# Check side
# -------------------------------------
vselect 125 200
if {[vreadpixel 115 233 name] != "GRAY95 1"} {
puts "ERROR: Display of view cube is wrong."
}
if {[vreadpixel 190 136 name] != "IVORY 1"} {
puts "ERROR: Position of TOP camera is wrong."
}
vdump $anImage2
# -------------------------------------
# Check edge
# -------------------------------------
vselect 163 242
if {[vreadpixel 141 234 name] != "GRAY76 1"} {
puts "ERROR: Position of TOP-RIGHT camera is wrong."
}
vdump $anImage3
# -------------------------------------
# Check vertex
# -------------------------------------
vselect 121 213
if {[vreadpixel 120 250 name] != "GRAY95 1"} {
puts "ERROR: Position of TOP-RIGHT-BACK camera is wrong."
}
vdump $anImage4
vviewcube -remove
vclear

46
tests/v3d/viewcube/move Normal file
View File

@@ -0,0 +1,46 @@
puts "=================================="
puts "AIS_ViewCube - check positioning of View Cube"
puts "=================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
set anImage3 $imagedir/${casename}_3.png
set anImage4 $imagedir/${casename}_4.png
vclear
vclose ALL
vinit
# -------------------------------------
# display view cube object
# -------------------------------------
vviewcube -enable -size 70 -adaptsize
# -------------------------------------
# check positioning of view cube object
# -------------------------------------
if {[vreadpixel 96 285 name] != "GRAY68 1"} {
puts "ERROR: Bottom left View Cube fails."
}
vdump $anImage1
vviewcube -position 200 200
if {[vreadpixel 200 176 name] != "GRAY68 1"} {
puts "ERROR: Center View Cube fails."
}
vdump $anImage2
vviewcube -position 310 100
if {[vreadpixel 310 73 name] != "GRAY68 1"} {
puts "ERROR: Top right View Cube fails."
}
vdump $anImage3
vviewcube -position 140 240
if {[vreadpixel 140 217 name] != "GRAY68 1"} {
puts "ERROR: Custom View Cube fails."
}
vdump $anImage4
vviewcube -remove
vclear

33
tests/v3d/viewcube/part Normal file
View File

@@ -0,0 +1,33 @@
puts "====================================="
puts "AIS_ViewCube - test custom appearance"
puts "====================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
set anImage3 $imagedir/${casename}_3.png
vclear
vclose ALL
vinit
vviewcube -enable -hideedges
if {[vreadpixel 186 236 name] != "BLACK 0"} {
puts "ERROR: Invalid display of View Cube without edges."
}
vdump $anImage1
vviewcube -showedges -hidevertices
if {[vreadpixel 150 258 name] != "BLACK 0"} {
puts "ERROR: Invalid display of View Cube without vertices."
}
vdump $anImage2
vviewcube -hideedges -hidevertices
if {[vreadpixel 186 236 name] != "BLACK 0" || [vreadpixel 150 258 name] != "BLACK 0"} {
puts "ERROR: Invalid display of View Cube without edges & vertices."
}
vdump $anImage3
vviewcube -remove
vclear

84
tests/v3d/viewcube/style Normal file
View File

@@ -0,0 +1,84 @@
puts "=================================="
puts "AIS_ViewCube - display custom styled View Cube"
puts "=================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
set anImage3 $imagedir/${casename}_3.png
set anImage4 $imagedir/${casename}_4.png
set anImage5 $imagedir/${casename}_5.png
set anImage6 $imagedir/${casename}_6.png
set anImage7 $imagedir/${casename}_7.png
vclear
vclose ALL
vinit
# -------------------------------------
# Color
# -------------------------------------
vviewcube -enable -boxcolor 0.69 0.88 1 -arrowcolor 0 0.4 0.54 -textcolor 0 0.4 0.54
if {[vreadpixel 118 273 name] != "LIGHTSLATEGRAY 1" || [vreadpixel 270 260 name] != "GRAY15 0.24705882370471954"} {
puts "ERROR: Errors in changing View Cube colors."
}
vdump $anImage1
# -------------------------------------
# Transparency
# -------------------------------------
vviewcube -reset
vviewcube -transparency 0.5
if {[vreadpixel 118 273 name] != "GRAY17 0.37254902720451355" || [vreadpixel 270 260 name] != "GRAY48 0.24705882370471954"} {
puts "ERROR: Errors in changing View Cube common transparency."
}
vdump $anImage2
vviewcube -reset
vviewcube -boxtransparency 0.4 -arrowtransparency 0.2
if {[vreadpixel 118 273 name] != "GRAY16 0.5058823823928833" || [vreadpixel 270 260 name] != "GRAY76 0.63921570777893066"} {
puts "ERROR: Errors in changing View Cube separate transparency."
}
vdump $anImage3
# -------------------------------------
# Arrows
# -------------------------------------
vviewcube -reset
vviewcube -arrowangle 30 -arrowlength 30
if {[vreadpixel 270 268 name] != "BLACK 0" || [vreadpixel 291 259 name] != "GRAY48 0.24705882370471954"} {
puts "ERROR: Errors in changing View Cube arrow style."
}
vdump $anImage4
# -------------------------------------
# Font
# -------------------------------------
vviewcube -reset
vviewcube -font "Impact" -fontheight 16
if {[vreadpixel 150 200 name] != "BLACK 0.729411780834198" || [vreadpixel 168 391 name] != "RED 1"} {
puts "ERROR: Errors in changing View Cube font."
}
vdump $anImage5
# -------------------------------------
# Padding
# -------------------------------------
vviewcube -reset
vviewcube -boxpadding 10 -axispadding 20 -arrowpadding 10
if {[vreadpixel 71 263 name] != "BLACK 0" || [vreadpixel 37 266 name] != "BLUE2 1"} {
puts "ERROR: Errors in changing View Cube padding."
}
vdump $anImage6
# -------------------------------------
# Corner radius
# -------------------------------------
vviewcube -reset
vviewcube -cornerradius 0.2
vdump $anImage7
vviewcube -remove
vclear

28
tests/v3d/viewcube/view Normal file
View File

@@ -0,0 +1,28 @@
puts "=================================="
puts "AIS_ViewCube - check view affinity"
puts "=================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
vclear
vclose ALL
vinit view1
vinit view2
vviewcube -enable
if {[vreadpixel 150 220 name] != "GRAY68 1"} {
puts "ERROR: display of View Cube in view2 fails."
}
vdump $anImage1
vactivate view1
if {[vreadpixel 150 220 name] != "BLACK 0"} {
puts "ERROR: View Cube should not be displayed in view1."
}
vdump $anImage2
vactivate view2
vviewcube -remove

25
tests/v3d/viewcube/view2 Normal file
View File

@@ -0,0 +1,25 @@
puts "=================================="
puts "AIS_ViewCube - check view affinity"
puts "=================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
vclear
vclose ALL
vinit view1
vviewcube -enable
if {[vreadpixel 150 220 name] != "GRAY68 1"} {
puts "ERROR: display of View Cube in view1 fails."
}
vdump $anImage1
vviewcube -remove
vinit view2
vviewcube -enable
if {[vreadpixel 150 220 name] != "GRAY68 1"} {
puts "ERROR: View Cube should not be displayed in view1."
}
vdump $anImage2
vviewcube -remove