mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-19 13:40:49 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
15
samples/CSharp/OCC/OCC.cpp
Executable file
15
samples/CSharp/OCC/OCC.cpp
Executable file
@@ -0,0 +1,15 @@
|
||||
// OCC.cpp : Defines the entry point for the DLL application.
|
||||
//
|
||||
//__declspec(dllexport)
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "OCCViewer.h"
|
||||
#pragma unmanaged
|
||||
BOOL APIENTRY DllMain( HANDLE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
248
samples/CSharp/OCC/OCC.vcproj
Executable file
248
samples/CSharp/OCC/OCC.vcproj
Executable file
@@ -0,0 +1,248 @@
|
||||
<?xml version="1.0" encoding="windows-1251"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="OCC"
|
||||
ProjectGUID="{DCB139CF-2190-412E-B72F-8B080CC01422}"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="2"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
ManagedExtensions="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(CASROOT)\inc"
|
||||
PreprocessorDefinitions="WNT"
|
||||
MinimalRebuild="false"
|
||||
BasicRuntimeChecks="0"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="TKV3d.lib TKV2d.lib TKHLR.lib TKService.lib TKBool.lib TKPShape.lib TKMath.lib TKBO.lib TKernel.lib TKPrim.lib TKTopAlgo.lib TKBRep.lib TKGeomAlgo.lib TKG2d.lib TKG3d.lib PTKernel.lib TKShapeSchema.lib TKXSBase.lib TKIGES.lib TKSTEP.lib TKSTEP209.lib TKSTEPAttr.lib TKSTEPBase.lib TKShHealing.lib TKSTL.lib TKVRML.lib"
|
||||
OutputFile="$(OutDir)/OCC.dll"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="$(CASROOT)\win32\vc8\lib"
|
||||
GenerateDebugInformation="true"
|
||||
AssemblyDebug="1"
|
||||
ProgramDatabaseFile="$(OutDir)/OCC.pdb"
|
||||
SubSystem="2"
|
||||
ResourceOnlyDLL="false"
|
||||
ImportLibrary="$(OutDir)/OCC.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="2"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
ManagedExtensions="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="$(CASROOT)\inc"
|
||||
PreprocessorDefinitions="WNT"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="TKV3d.lib TKV2d.lib TKHLR.lib TKService.lib TKBool.lib TKPShape.lib TKMath.lib TKBO.lib TKernel.lib TKPrim.lib TKTopAlgo.lib TKBRep.lib TKGeomAlgo.lib TKG2d.lib TKG3d.lib PTKernel.lib TKShapeSchema.lib TKXSBase.lib TKIGES.lib TKSTEP.lib TKSTEP209.lib TKSTEPAttr.lib TKSTEPBase.lib TKShHealing.lib TKSTL.lib TKVRML.lib"
|
||||
OutputFile="$(OutDir)/OCC.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="$(CASROOT)\win32\vc8\lib"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(OutDir)/OCC.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\OCC.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\OCCViewer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\OCCViewer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
573
samples/CSharp/OCC/OCCViewer.cpp
Executable file
573
samples/CSharp/OCC/OCCViewer.cpp
Executable file
@@ -0,0 +1,573 @@
|
||||
#include "StdAfx.h"
|
||||
#include ".\occviewer.h"
|
||||
|
||||
#pragma warning( disable : 4800 )
|
||||
OCCViewer::OCCViewer(void)
|
||||
{
|
||||
myGraphicDevice=NULL;
|
||||
myViewer=NULL;
|
||||
myView=NULL;
|
||||
myAISContext=NULL;
|
||||
}
|
||||
|
||||
OCCViewer::~OCCViewer(void)
|
||||
{
|
||||
myView->Remove();
|
||||
}
|
||||
|
||||
bool OCCViewer::InitViewer(void* wnd)
|
||||
{
|
||||
try {
|
||||
myGraphicDevice = new Graphic3d_WNTGraphicDevice();
|
||||
} catch (Standard_Failure) {
|
||||
return false;
|
||||
}
|
||||
TCollection_ExtendedString a3DName("Visu3D");
|
||||
myViewer = new V3d_Viewer( myGraphicDevice, a3DName.ToExtString(),"", 1000.0,
|
||||
V3d_XposYnegZpos, Quantity_NOC_GRAY30,
|
||||
V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
|
||||
Standard_True, Standard_False);
|
||||
|
||||
myViewer->Init();
|
||||
myViewer->SetDefaultLights();
|
||||
myViewer->SetLightOn();
|
||||
myView = myViewer->CreateView();
|
||||
Handle(WNT_Window) aWNTWindow = new WNT_Window(myGraphicDevice, reinterpret_cast<HWND> (wnd));
|
||||
myView->SetWindow(aWNTWindow);
|
||||
if (!aWNTWindow->IsMapped())
|
||||
aWNTWindow->Map();
|
||||
myAISContext = new AIS_InteractiveContext(myViewer);
|
||||
myAISContext->UpdateCurrentViewer();
|
||||
myView->Redraw();
|
||||
myView->MustBeResized();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool OCCViewer::ImportBRep(char* filename)
|
||||
{
|
||||
Standard_CString aFileName = (Standard_CString) filename;
|
||||
TopoDS_Shape aShape;
|
||||
BRep_Builder aBuilder;
|
||||
Standard_Boolean result = BRepTools::Read(aShape,aFileName,aBuilder);
|
||||
if (!result)
|
||||
return false;
|
||||
if(myAISContext->HasOpenedContext())
|
||||
myAISContext->CloseLocalContext();
|
||||
myAISContext->Display(new AIS_Shape(aShape));
|
||||
return true;
|
||||
}
|
||||
|
||||
void OCCViewer::UpdateView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->MustBeResized();
|
||||
}
|
||||
|
||||
void OCCViewer::RedrawView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->Redraw();
|
||||
}
|
||||
|
||||
void OCCViewer::SetDegenerateModeOn(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetDegenerateModeOn();
|
||||
}
|
||||
|
||||
void OCCViewer::SetDegenerateModeOff(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetDegenerateModeOff();
|
||||
}
|
||||
|
||||
void OCCViewer::WindowFitAll(int Xmin, int Ymin, int Xmax, int Ymax)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->WindowFitAll(Xmin, Ymin, Xmax, Ymax);
|
||||
}
|
||||
|
||||
void OCCViewer::Place(int x, int y, float zoomFactor)
|
||||
{
|
||||
Quantity_Factor aZoomFactor = zoomFactor;
|
||||
if (!myView.IsNull())
|
||||
myView->Place(x, y, aZoomFactor);
|
||||
}
|
||||
|
||||
void OCCViewer::Zoom(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->Zoom(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
void OCCViewer::Pan(int x, int y)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->Pan(x, y);
|
||||
}
|
||||
|
||||
void OCCViewer::Rotation(int x, int y)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->Rotation(x, y);
|
||||
}
|
||||
|
||||
void OCCViewer::StartRotation(int x, int y)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->StartRotation(x, y);
|
||||
}
|
||||
|
||||
void OCCViewer::Select(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if (!myAISContext.IsNull())
|
||||
myAISContext->Select(x1, y1, x2, y2, myView);
|
||||
}
|
||||
|
||||
void OCCViewer::Select(void)
|
||||
{
|
||||
if (!myAISContext.IsNull())
|
||||
myAISContext->Select();
|
||||
}
|
||||
|
||||
void OCCViewer::MoveTo(int x, int y)
|
||||
{
|
||||
if ((!myAISContext.IsNull()) && (!myView.IsNull()))
|
||||
myAISContext->MoveTo(x, y, myView);
|
||||
}
|
||||
|
||||
void OCCViewer::ShiftSelect(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if ((!myAISContext.IsNull()) && (!myView.IsNull()))
|
||||
myAISContext->ShiftSelect(x1, y1, x2, y2, myView);
|
||||
}
|
||||
|
||||
void OCCViewer::ShiftSelect(void)
|
||||
{
|
||||
if (!myAISContext.IsNull())
|
||||
myAISContext->ShiftSelect();
|
||||
}
|
||||
|
||||
void OCCViewer::BackgroundColor(int& r, int& g, int& b)
|
||||
{
|
||||
Standard_Real R1;
|
||||
Standard_Real G1;
|
||||
Standard_Real B1;
|
||||
if (!myView.IsNull())
|
||||
myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
|
||||
r = (int)R1*255;
|
||||
g = (int)G1*255;
|
||||
b = (int)B1*255;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OCCViewer::UpdateCurrentViewer(void)
|
||||
{
|
||||
if (!myAISContext.IsNull())
|
||||
myAISContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void OCCViewer::FrontView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetProj(V3d_Xpos);
|
||||
}
|
||||
|
||||
void OCCViewer::TopView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetProj(V3d_Zpos);
|
||||
}
|
||||
|
||||
void OCCViewer::LeftView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetProj(V3d_Ypos);
|
||||
}
|
||||
|
||||
void OCCViewer::BackView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetProj(V3d_Xneg);
|
||||
}
|
||||
|
||||
void OCCViewer::RightView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetProj(V3d_Yneg);
|
||||
}
|
||||
|
||||
void OCCViewer::BottomView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetProj(V3d_Zneg);
|
||||
}
|
||||
|
||||
void OCCViewer::AxoView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetProj(V3d_XposYnegZpos);
|
||||
}
|
||||
|
||||
void OCCViewer::ZoomAllView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
{
|
||||
myView->FitAll();
|
||||
myView->ZFitAll();
|
||||
}
|
||||
}
|
||||
|
||||
float OCCViewer::Scale(void)
|
||||
{
|
||||
if (myView.IsNull())
|
||||
return -1;
|
||||
else
|
||||
return (float)myView->Scale();
|
||||
}
|
||||
|
||||
void OCCViewer::ResetView(void)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->Reset();
|
||||
}
|
||||
|
||||
void OCCViewer::SetDisplayMode(int aMode)
|
||||
{
|
||||
if (myAISContext.IsNull())
|
||||
return;
|
||||
AIS_DisplayMode CurrentMode;
|
||||
if (aMode == 0)
|
||||
CurrentMode=AIS_WireFrame;
|
||||
else
|
||||
CurrentMode=AIS_Shaded;
|
||||
if(myAISContext->NbCurrents()==0 || myAISContext->NbSelected()==0)
|
||||
myAISContext->SetDisplayMode(CurrentMode);
|
||||
else
|
||||
{
|
||||
for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent())
|
||||
myAISContext->SetDisplayMode(myAISContext->Current(),aMode,Standard_False);
|
||||
|
||||
}
|
||||
myAISContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void OCCViewer::SetColor(int r, int g, int b)
|
||||
{
|
||||
if (myAISContext.IsNull())
|
||||
return;
|
||||
Quantity_Color col = Quantity_Color(r/255.,g/255.,b/255.,Quantity_TOC_RGB);
|
||||
for (;myAISContext->MoreCurrent ();myAISContext->NextCurrent ())
|
||||
myAISContext->SetColor (myAISContext->Current(),col.Name());
|
||||
}
|
||||
|
||||
void OCCViewer::ObjectColor(int& r, int& g, int& b)
|
||||
{
|
||||
if (myAISContext.IsNull())
|
||||
return;
|
||||
r=255;
|
||||
g=255;
|
||||
b=255;
|
||||
Handle_AIS_InteractiveObject Current ;
|
||||
Quantity_Color ObjCol;
|
||||
myAISContext->InitCurrent();
|
||||
if (!myAISContext->MoreCurrent())
|
||||
return;
|
||||
Current = myAISContext->Current();
|
||||
if ( Current->HasColor () ) {
|
||||
ObjCol = myAISContext->Color(myAISContext->Current());
|
||||
Quantity_Parameter r1, r2, r3;
|
||||
ObjCol.Values(r1, r2, r3, Quantity_TOC_RGB);
|
||||
r=(int)r1*255;
|
||||
g=(int)r2*255;
|
||||
b=(int)r3*255;
|
||||
}
|
||||
}
|
||||
|
||||
void OCCViewer::SetBackgroundColor(int r, int g, int b)
|
||||
{
|
||||
if (!myView.IsNull())
|
||||
myView->SetBackgroundColor(Quantity_TOC_RGB,r/255.,g/255.,b/255.);
|
||||
}
|
||||
|
||||
void OCCViewer::EraseObjects(void)
|
||||
{
|
||||
if (myAISContext.IsNull())
|
||||
return;
|
||||
for(myAISContext->InitCurrent();myAISContext->MoreCurrent();myAISContext->NextCurrent())
|
||||
myAISContext->Erase(myAISContext->Current(),Standard_True,Standard_False);
|
||||
myAISContext->ClearCurrents();
|
||||
}
|
||||
|
||||
float OCCViewer::GetVersion(void)
|
||||
{
|
||||
return (float)OCC_VERSION;
|
||||
}
|
||||
|
||||
void OCCViewer::SetMaterial(int theMaterial)
|
||||
{
|
||||
if (myAISContext.IsNull())
|
||||
return;
|
||||
for ( myAISContext->InitCurrent(); myAISContext->MoreCurrent (); myAISContext->NextCurrent () )
|
||||
myAISContext->SetMaterial( myAISContext->Current(), (Graphic3d_NameOfMaterial)theMaterial );
|
||||
myAISContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void OCCViewer::SetTransparency(int theTrans)
|
||||
{
|
||||
if (myAISContext.IsNull())
|
||||
return;
|
||||
for( myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextSelected() )
|
||||
myAISContext->SetTransparency( myAISContext->Current(), ((Standard_Real)theTrans) / 10.0 );
|
||||
}
|
||||
|
||||
bool OCCViewer::ImportCsfdb(char* filename)
|
||||
{
|
||||
Standard_CString aFileName = (Standard_CString) filename;
|
||||
if ( FSD_File::IsGoodFileType(aFileName) != Storage_VSOk )
|
||||
return false;
|
||||
|
||||
static FSD_File fileDriver;
|
||||
TCollection_AsciiString aName( aFileName );
|
||||
if ( fileDriver.Open( aName, Storage_VSRead ) != Storage_VSOk )
|
||||
return false;
|
||||
|
||||
Handle(ShapeSchema) schema = new ShapeSchema();
|
||||
Handle(Storage_Data) data = schema->Read( fileDriver );
|
||||
if ( data->ErrorStatus() != Storage_VSOk )
|
||||
return false;
|
||||
fileDriver.Close();
|
||||
|
||||
Handle(Storage_HSeqOfRoot) roots = data->Roots();
|
||||
for ( int i = 1; i <= roots->Length() ; i++ )
|
||||
{
|
||||
Handle(Storage_Root) r = roots->Value( i );
|
||||
Handle(Standard_Persistent) p = r->Object();
|
||||
Handle(PTopoDS_HShape) aPShape = Handle(PTopoDS_HShape)::DownCast(p);
|
||||
if ( !aPShape.IsNull() )
|
||||
{
|
||||
PTColStd_PersistentTransientMap aMap;
|
||||
TopoDS_Shape aTShape;
|
||||
MgtBRep::Translate( aPShape, aMap, aTShape, MgtBRep_WithTriangle );
|
||||
myAISContext->Display(new AIS_Shape(aTShape));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OCCViewer::ImportIges(char* filename)
|
||||
{
|
||||
Standard_CString aFileName = (Standard_CString) filename;
|
||||
IGESControl_Reader Reader;
|
||||
int status = Reader.ReadFile( aFileName );
|
||||
|
||||
if ( status == IFSelect_RetDone )
|
||||
{
|
||||
Reader.TransferRoots();
|
||||
TopoDS_Shape aShape = Reader.OneShape();
|
||||
myAISContext->Display(new AIS_Shape(aShape));
|
||||
} else
|
||||
return false;
|
||||
myAISContext->UpdateCurrentViewer();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OCCViewer::ImportStep(char* filename)
|
||||
{
|
||||
Standard_CString aFileName = (Standard_CString) filename;
|
||||
STEPControl_Reader aReader;
|
||||
IFSelect_ReturnStatus status = aReader.ReadFile(aFileName);
|
||||
if ( status == IFSelect_RetDone )
|
||||
{
|
||||
bool failsonly = false;
|
||||
aReader.PrintCheckLoad( failsonly, IFSelect_ItemsByEntity );
|
||||
|
||||
int nbr = aReader.NbRootsForTransfer();
|
||||
aReader.PrintCheckTransfer( failsonly, IFSelect_ItemsByEntity );
|
||||
for ( Standard_Integer n = 1; n <= nbr; n++ )
|
||||
{
|
||||
Standard_Boolean ok = aReader.TransferRoot( n );
|
||||
int nbs = aReader.NbShapes();
|
||||
if ( nbs > 0 )
|
||||
{
|
||||
for ( int i = 1; i <= nbs; i++ )
|
||||
{
|
||||
TopoDS_Shape shape = aReader.Shape( i );
|
||||
myAISContext->Display(new AIS_Shape(shape));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OCCViewer::ExportBRep(char* filename)
|
||||
{
|
||||
myAISContext->InitCurrent();
|
||||
if (!myAISContext->MoreCurrent())
|
||||
return false;
|
||||
Handle_AIS_InteractiveObject anIO = myAISContext->Current();
|
||||
Handle_AIS_Shape anIS=Handle_AIS_Shape::DownCast(anIO);
|
||||
return (bool)BRepTools::Write( anIS->Shape(), (Standard_CString)filename ); ;
|
||||
}
|
||||
|
||||
|
||||
bool OCCViewer::ExportIges(char* filename)
|
||||
{
|
||||
IGESControl_Controller::Init();
|
||||
IGESControl_Writer writer( Interface_Static::CVal( "XSTEP.iges.unit" ),
|
||||
Interface_Static::IVal( "XSTEP.iges.writebrep.mode" ) );
|
||||
|
||||
|
||||
for ( myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent() )
|
||||
{
|
||||
Handle_AIS_InteractiveObject anIO = myAISContext->Current();
|
||||
Handle_AIS_Shape anIS=Handle_AIS_Shape::DownCast(anIO);
|
||||
TopoDS_Shape shape = anIS->Shape();
|
||||
writer.AddShape ( shape );
|
||||
}
|
||||
writer.ComputeModel();
|
||||
return (bool)writer.Write( (Standard_CString)filename );
|
||||
}
|
||||
|
||||
bool OCCViewer::ExpotStep(char* filename)
|
||||
{
|
||||
STEPControl_StepModelType type = STEPControl_AsIs;
|
||||
IFSelect_ReturnStatus status;
|
||||
STEPControl_Writer writer;
|
||||
for ( myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent() )
|
||||
{
|
||||
Handle_AIS_InteractiveObject anIO = myAISContext->Current();
|
||||
Handle_AIS_Shape anIS=Handle_AIS_Shape::DownCast(anIO);
|
||||
TopoDS_Shape shape = anIS->Shape();
|
||||
status = writer.Transfer( shape , type );
|
||||
if ( status != IFSelect_RetDone )
|
||||
return false;
|
||||
}
|
||||
|
||||
status = writer.Write( (Standard_CString)filename );
|
||||
if ( status != IFSelect_RetDone )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OCCViewer::ExportStl(char* filename)
|
||||
{
|
||||
TopoDS_Compound comp;
|
||||
BRep_Builder builder;
|
||||
builder.MakeCompound( comp );
|
||||
|
||||
for ( myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent() )
|
||||
{
|
||||
Handle_AIS_InteractiveObject anIO = myAISContext->Current();
|
||||
Handle_AIS_Shape anIS=Handle_AIS_Shape::DownCast(anIO);
|
||||
TopoDS_Shape shape = anIS->Shape();
|
||||
if ( shape.IsNull() )
|
||||
return false;
|
||||
builder.Add( comp, shape );
|
||||
}
|
||||
|
||||
StlAPI_Writer writer;
|
||||
writer.Write( comp, (Standard_CString)filename );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OCCViewer::ExportVrml(char* filename)
|
||||
{
|
||||
TopoDS_Compound res;
|
||||
BRep_Builder builder;
|
||||
builder.MakeCompound( res );
|
||||
|
||||
for ( myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent() )
|
||||
{
|
||||
Handle_AIS_InteractiveObject anIO = myAISContext->Current();
|
||||
Handle_AIS_Shape anIS=Handle_AIS_Shape::DownCast(anIO);
|
||||
TopoDS_Shape shape = anIS->Shape();
|
||||
if ( shape.IsNull() )
|
||||
return false;
|
||||
|
||||
builder.Add( res, shape );
|
||||
}
|
||||
|
||||
VrmlAPI_Writer writer;
|
||||
writer.Write( res, (Standard_CString)filename );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OCCViewer::Dump(char *filename)
|
||||
{
|
||||
if (myView.IsNull())
|
||||
return false;
|
||||
myView->Redraw();
|
||||
return (bool)myView->Dump(filename);
|
||||
}
|
||||
|
||||
bool OCCViewer::IsObjectSelected(void)
|
||||
{
|
||||
if (myAISContext.IsNull())
|
||||
return false;
|
||||
myAISContext->InitCurrent();
|
||||
return (bool)myAISContext->MoreCurrent();
|
||||
}
|
||||
|
||||
int OCCViewer::DisplayMode(void)
|
||||
{
|
||||
if (myAISContext.IsNull())
|
||||
return -1;
|
||||
int mode = -1;
|
||||
bool OneOrMoreInShading=false;
|
||||
bool OneOrMoreInWireframe=false;
|
||||
for (myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent())
|
||||
{
|
||||
if ( myAISContext->IsDisplayed( myAISContext->Current(), 1 ) )
|
||||
OneOrMoreInShading = true;
|
||||
if ( myAISContext->IsDisplayed( myAISContext->Current(), 0 ) )
|
||||
OneOrMoreInWireframe = true;
|
||||
}
|
||||
if (OneOrMoreInShading&&OneOrMoreInWireframe)
|
||||
mode=10;
|
||||
else if(OneOrMoreInShading)
|
||||
mode=1;
|
||||
else if (OneOrMoreInWireframe)
|
||||
mode=0;
|
||||
return mode;
|
||||
}
|
||||
|
||||
void OCCViewer::CreateNewView(void* wnd)
|
||||
{
|
||||
if (myAISContext.IsNull())
|
||||
return;
|
||||
myView = myAISContext->CurrentViewer()->CreateView();
|
||||
if (myGraphicDevice.IsNull())
|
||||
myGraphicDevice = new Graphic3d_WNTGraphicDevice();
|
||||
Handle(WNT_Window) aWNTWindow = new WNT_Window(myGraphicDevice, reinterpret_cast<HWND> (wnd));
|
||||
myView->SetWindow(aWNTWindow);
|
||||
Standard_Integer w=100, h=100;
|
||||
aWNTWindow->Size(w,h);
|
||||
if (!aWNTWindow->IsMapped())
|
||||
aWNTWindow->Map();
|
||||
}
|
||||
|
||||
bool OCCViewer::SetAISContext(OCCViewer* Viewer)
|
||||
{
|
||||
this->myAISContext=Viewer->GetAISContext();
|
||||
if (myAISContext.IsNull())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Handle_AIS_InteractiveContext OCCViewer::GetAISContext(void)
|
||||
{
|
||||
return myAISContext;
|
||||
}
|
||||
|
||||
int OCCViewer::CharToInt(char symbol)
|
||||
{
|
||||
TCollection_AsciiString msg = symbol;
|
||||
return msg.IntegerValue();
|
||||
}
|
69
samples/CSharp/OCC/OCCViewer.h
Executable file
69
samples/CSharp/OCC/OCCViewer.h
Executable file
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
#include "stdafx.h"
|
||||
|
||||
|
||||
class OCCViewer
|
||||
{
|
||||
public:
|
||||
__declspec(dllexport) OCCViewer(void);
|
||||
__declspec(dllexport) ~OCCViewer(void);
|
||||
private:
|
||||
Handle_V3d_Viewer myViewer;
|
||||
Handle_V3d_View myView;
|
||||
Handle_AIS_InteractiveContext myAISContext;
|
||||
Handle_Graphic3d_WNTGraphicDevice myGraphicDevice;
|
||||
public:
|
||||
__declspec(dllexport) bool InitViewer(void* wnd);
|
||||
__declspec(dllexport) bool ImportBRep(char* filename);
|
||||
__declspec(dllexport) void UpdateView(void);
|
||||
__declspec(dllexport) void RedrawView(void);
|
||||
__declspec(dllexport) void SetDegenerateModeOn(void);
|
||||
__declspec(dllexport) void SetDegenerateModeOff(void);
|
||||
__declspec(dllexport) void WindowFitAll(int Xmin, int Ymin, int Xmax, int Ymax);
|
||||
__declspec(dllexport) void Place(int x, int y, float zoomFactor);
|
||||
__declspec(dllexport) void Zoom(int x1, int y1, int x2, int y2);
|
||||
__declspec(dllexport) void Pan(int x, int y);
|
||||
__declspec(dllexport) void Rotation(int x, int y);
|
||||
__declspec(dllexport) void StartRotation(int x, int y);
|
||||
__declspec(dllexport) void Select(int x1, int y1, int x2, int y2);
|
||||
__declspec(dllexport) void Select(void);
|
||||
__declspec(dllexport) void MoveTo(int x, int y);
|
||||
__declspec(dllexport) void ShiftSelect(int x1, int y1, int x2, int y2);
|
||||
__declspec(dllexport) void ShiftSelect(void);
|
||||
__declspec(dllexport) void BackgroundColor(int& r, int& g, int& b);
|
||||
__declspec(dllexport) void UpdateCurrentViewer(void);
|
||||
__declspec(dllexport) void FrontView(void);
|
||||
__declspec(dllexport) void TopView(void);
|
||||
__declspec(dllexport) void LeftView(void);
|
||||
__declspec(dllexport) void BackView(void);
|
||||
__declspec(dllexport) void RightView(void);
|
||||
__declspec(dllexport) void BottomView(void);
|
||||
__declspec(dllexport) void AxoView(void);
|
||||
__declspec(dllexport) void ZoomAllView(void);
|
||||
__declspec(dllexport) float Scale(void);
|
||||
__declspec(dllexport) void PanGloView(void);
|
||||
__declspec(dllexport) void ResetView(void);
|
||||
__declspec(dllexport) void SetDisplayMode(int aMode);
|
||||
__declspec(dllexport) void SetColor(int r, int g, int b);
|
||||
__declspec(dllexport) void ObjectColor(int& r, int& g, int& b);
|
||||
__declspec(dllexport) void SetBackgroundColor(int r, int g, int b);
|
||||
__declspec(dllexport) void EraseObjects(void);
|
||||
__declspec(dllexport) float GetVersion(void);
|
||||
__declspec(dllexport) void SetMaterial(int theMaterial);
|
||||
__declspec(dllexport) void SetTransparency(int theTrans);
|
||||
__declspec(dllexport) bool ImportCsfdb(char* filename);
|
||||
__declspec(dllexport) bool ImportIges(char* filename);
|
||||
__declspec(dllexport) bool ImportStep(char* filename);
|
||||
__declspec(dllexport) bool ExportBRep(char* filename);
|
||||
__declspec(dllexport) bool ExportIges(char* filename);
|
||||
__declspec(dllexport) bool ExpotStep(char* filename);
|
||||
__declspec(dllexport) bool ExportStl(char* filename);
|
||||
__declspec(dllexport) bool ExportVrml(char* filename);
|
||||
__declspec(dllexport) bool Dump(char* filename);
|
||||
__declspec(dllexport) bool IsObjectSelected(void);
|
||||
__declspec(dllexport) int DisplayMode(void);
|
||||
__declspec(dllexport) void CreateNewView(void* wnd);
|
||||
__declspec(dllexport) bool SetAISContext(OCCViewer* Viewer);
|
||||
Handle_AIS_InteractiveContext GetAISContext(void);
|
||||
__declspec(dllexport) int CharToInt(char symbol);
|
||||
};
|
40
samples/CSharp/OCC/ReadMe.txt
Executable file
40
samples/CSharp/OCC/ReadMe.txt
Executable file
@@ -0,0 +1,40 @@
|
||||
========================================================================
|
||||
DYNAMIC LINK LIBRARY : OCC Project Overview
|
||||
========================================================================
|
||||
|
||||
AppWizard has created this OCC DLL for you.
|
||||
This file contains a summary of what you will find in each of the files that
|
||||
make up your OCC application.
|
||||
|
||||
|
||||
OCC.vcproj
|
||||
This is the main project file for VC++ projects generated using an Application Wizard.
|
||||
It contains information about the version of Visual C++ that generated the file, and
|
||||
information about the platforms, configurations, and project features selected with the
|
||||
Application Wizard.
|
||||
|
||||
OCC.cpp
|
||||
This is the main DLL source file.
|
||||
|
||||
When created, this DLL does not export any symbols. As a result, it
|
||||
will not produce a .lib file when it is built. If you wish this project
|
||||
to be a project dependency of some other project, you will either need to
|
||||
add code to export some symbols from the DLL so that an export library
|
||||
will be produced, or you can set the Ignore Input Library property to Yes
|
||||
on the General propert page of the Linker folder in the project's Property
|
||||
Pages dialog box.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other standard files:
|
||||
|
||||
StdAfx.h, StdAfx.cpp
|
||||
These files are used to build a precompiled header (PCH) file
|
||||
named OCC.pch and a precompiled types file named StdAfx.obj.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other notes:
|
||||
|
||||
AppWizard uses "TODO:" comments to indicate parts of the source code you
|
||||
should add to or customize.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
8
samples/CSharp/OCC/stdafx.cpp
Executable file
8
samples/CSharp/OCC/stdafx.cpp
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// OCC.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
72
samples/CSharp/OCC/stdafx.h
Executable file
72
samples/CSharp/OCC/stdafx.h
Executable file
@@ -0,0 +1,72 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files:
|
||||
#include <windows.h>
|
||||
//standard OCC types
|
||||
#pragma warning( disable : 4311 )
|
||||
#pragma warning( disable : 4312 )
|
||||
#pragma warning( disable : 4267 )
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Standard_CString.hxx>
|
||||
#include <Standard_Version.hxx>
|
||||
#include <Standard_Persistent.hxx>
|
||||
//collections
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <PTColStd_PersistentTransientMap.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
//for OCC graphic
|
||||
#include <WNT_Window.hxx>
|
||||
#include <Graphic3d_WNTGraphicDevice.hxx>
|
||||
#include <Quantity_NameOfColor.hxx>
|
||||
#include <Graphic3d_NameOfMaterial.hxx>
|
||||
//for object display
|
||||
#include <V3d_Viewer.hxx>
|
||||
#include <V3d_View.hxx>
|
||||
#include <AIS_InteractiveContext.hxx>
|
||||
#include <AIS_Shape.hxx>
|
||||
#include <AIS_Trihedron.hxx>
|
||||
#include <AIS_DisplayMode.hxx>
|
||||
#include <V3d_TypeOfOrientation.hxx>
|
||||
#include <V3d_TypeOfVisualization.hxx>
|
||||
#include <V3d_TypeOfShadingModel.hxx>
|
||||
#include <V3d_TypeOfUpdate.hxx>
|
||||
//topology
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
//brep tools
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRepTools.hxx>
|
||||
#include <MgtBRep.hxx>
|
||||
//geometry
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <Geom_Axis2Placement.hxx>
|
||||
//csfdb I/E
|
||||
#include <FSD_File.hxx>
|
||||
#include <ShapeSchema.hxx>
|
||||
#include <Storage_Data.hxx>
|
||||
#include <Storage_Error.hxx>
|
||||
#include <Storage_HSeqOfRoot.hxx>
|
||||
#include <Storage_Root.hxx>
|
||||
#include <PTopoDS_HShape.hxx>
|
||||
#include <PTColStd_TransientPersistentMap.hxx>
|
||||
// iges I/E
|
||||
#include <IGESControl_Reader.hxx>
|
||||
#include <IGESControl_Controller.hxx>
|
||||
#include <IGESControl_Writer.hxx>
|
||||
#include <IFSelect_ReturnStatus.hxx>
|
||||
#include <Interface_Static.hxx>
|
||||
//step I/E
|
||||
#include <STEPControl_Reader.hxx>
|
||||
#include <STEPControl_Writer.hxx>
|
||||
//for stl export
|
||||
#include <StlAPI_Writer.hxx>
|
||||
//for vrml export
|
||||
#include <VrmlAPI_Writer.hxx>
|
Reference in New Issue
Block a user