'STEP'에 해당되는 글 1건

  1. 2011.05.13 Open CASCADE - STEP FileRead 분석
posted by Full-stack Developer 2011. 5. 13. 16:49
 

 

 

 

<이미지 편집이 순조롭지 못합니다.. ㅠㅠ > 3개의 그림을 세로로 나열하고 싶었으나.. 제공되지 않는듯..>

 

 첫번째 그림 : STEP 및 기타 Solid Viewing을 제공하는 오픈 소스입니다. 출처는 Opencascade C#예제 소스에 담겨져 있습니다.

두번째~ 네번째 그림 : STEP파일을 읽어오기 위해 해당 메뉴버튼을 눌른 상황입니다.

●솔루션 내 프로젝트

●사용 언어

IE(인터페이스)

C#

OCC(동적 클래스 라이브러리)

C++

shell(동적 클래스 라이브러리)

C++

 

<step 파일 열기 버튼 클릭시 최초 접근하는 메소드>

 

private void ImportStep_Click(object sender, System.EventArgs e)

{

Form2 curForm = (Form2) this.ActiveMdiChild;

if (curForm == null)

return;

this.myModelFormat=IE.ModelFormat.STEP;

curForm.ImportModel(this.myModelFormat);

}

 

 

<모델 포맷의 정의>

 

protected IE.ModelFormat myModelFormat;

 

 

<this.ActiveMdiChild;>

 

//현재 활성상태인 MDI(다중 문서 인터페이스)자식창을 가져온다.

 

 

<curForm.ImportModel(this.myModelFormat);> (Form2.cs 로 이동한다.)

 

public void ImportModel(IE.ModelFormat format)

{

int theformat=10;

System.Windows.Forms.OpenFileDialog openDialog = new OpenFileDialog();

string DataDir=((Environment.GetEnvironmentVariable("CASROOT")) + "\\..\\data");

string filter="";

switch (format)

{

case ModelFormat.BREP:

openDialog.InitialDirectory = (DataDir + "\\occ");

theformat=0;

filter= "BREP Files (*.brep *.rle)|*.brep; *.rle"

break;

case ModelFormat.CSFDB:

theformat=1;

filter= "CSFDB Files (*.csfdb)|*.csfdb"

break;

 

case IE.ModelFormat.STEP:

openDialog.InitialDirectory = (DataDir + "\\step");

theformat=2;

filter="STEP Files (*.stp *.step)|*.stp; *.step"

break;

 

 

 

case IE.ModelFormat.IGES:

openDialog.InitialDirectory = (DataDir + "\\iges");

theformat=3;

filter="IGES Files (*.igs *.iges)|*.igs; *.iges"

break;

default:

break;

}

openDialog.Filter = filter+"|All files (*.*)|*.*" ;

if(openDialog.ShowDialog() == DialogResult.OK)

{

string filename = openDialog.FileName;

if ( filename=="")

return;

this.Cursor=System.Windows.Forms.Cursors.WaitCursor;

if (!myView.TranslateModel(filename, theformat, true))

MessageBox.Show("Cann't read this file", "Error!",

MessageBoxButtons.OK, MessageBoxIcon.Warning);

this.Cursor=System.Windows.Forms.Cursors.Default;

}

this.myView.ZoomAllView();

}

 

 

<this.myView.ZoomAllView();> (shell.h)

 

void ZoomAllView(void)

{

if (myOCCViewer != NULL)

myOCCViewer->ZoomAllView();

}

 

 

<myOCCViewer->ZoomAllView();> (OCCViewer.cpp)

 

void OCCViewer::ZoomAllView(void)

{

if (!myView.IsNull())

{

myView->FitAll();

myView->ZFitAll();

}

}

 

 

 

 

 

<if (!myView.IsNull())> (Handle_Standard_Transient.hxx)

 

//! Check for being null

Standard_Boolean IsNull() const

{

return entity == UndefinedHandleAddress;

}

 

 

<myView->FitAll();> (Handle_V3d_View.hxx)

 

V3d_View* operator->() const

{

return (V3d_View *)ControlAccess();

}

 

 

<return (V3d_View *)ControlAccess();> (Handle_Standard_Transient.hxx)

 

Standard_Transient* ControlAccess() const

{

return entity;

}

 

 

<myView->ZFitAll();> (Handle_V3d_View.hxx)

 

V3d_View* operator->() const

{

return (V3d_View *)ControlAccess();

}

 

 

<return (V3d_View *)ControlAccess();> (Handle_Standard_Transient.hxx)

 

Standard_Transient* ControlAccess() const

{

return entity;

}

 

 

(Form1.cs)

 

private void Form1_Activated(object sender, System.EventArgs e)

{

if (this.toolBarView.Visible) //true

this.SelectionChanged();

}

 

 

 

 

<this.SelectionChanged();> (Form1.cs)

 

public void SelectionChanged()

{

if (this.MdiChildren.Length == 0 )

return

IE.Form2 curForm = (IE.Form2) this.ActiveMdiChild;

if ( curForm == null )

return

switch (curForm.View.DisplayMode())

{

case -1:

this.shading.Enabled=false

this.wireframe.Enabled=false

break

case 0:

this.wireframe.Enabled=false

this.shading.Enabled=true

this.transparency.Enabled=false

break

case 1:

this.wireframe.Enabled=true

this.shading.Enabled=false

this.transparency.Enabled=true

break

case 10:

this.wireframe.Enabled=true

this.shading.Enabled=true

this.transparency.Enabled=true

break

default:

break

}

bool IsSelected = curForm.View.IsObjectSelected();

if (IsSelected)

{

this.color.Enabled=true

this.material.Enabled=true

this.delete.Enabled=true

}

else

{

this.color.Enabled=false

this.material.Enabled=false

this.transparency.Enabled=false

this.delete.Enabled=false

}

if (curForm.DegenerateMode)

{

this.HlrOff.Pushed=false

this.HlrOn.Pushed=true

}

else

{

this.HlrOff.Pushed=true

this.HlrOn.Pushed=false

}

if (curForm.Mode == IE.CurrentAction3d.CurAction3d_WindowZooming)

this.ZoomWin.Pushed=false

 

}

 

 

<switch (curForm.View.DisplayMode())> (Form2.cs) -> (shell.h)

 

public shell View

{

get

{

return this.myView;

}

set

{

this.myView=value

}

}

 

 

int DisplayMode(void)

{

if (myOCCViewer != NULL)

return myOCCViewer->DisplayMode();

else return -1;

}

 

 

 

<return myOCCViewer->DisplayMode();> (OCCViewer.cpp)

 

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;

}

 

 

<if (myAISContext.IsNull())> (Handle_Standard_Transient.hxx)

 

//! Check for being null

Standard_Boolean IsNull() const

{

return entity == UndefinedHandleAddress;

}

 

 

<for(myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent())> (OCCViewr.cpp)

-> (Handle_AIS_InteractiveContext.hxx)

 

AIS_InteractiveContext* operator->() const

{

return (AIS_InteractiveContext *)ControlAccess();

}

 

 

 

 

 

<return (AIS_InteractiveContext *)ControlAccess();> (Handle_Standard_Transient.hxx)

 

//! Returns non-const pointer to referred object

Standard_Transient* ControlAccess() const

{

return entity;

}

 

 

->(Handle_AIS_InteractiveContext.hxx)

 

AIS_InteractiveContext* operator->() const

{

return (AIS_InteractiveContext *)ControlAccess();

}

 

 

<return (AIS_InteractiveContext *)ControlAccess();> ->(Handle_Standard_Transient.hxx)

 

//! Returns non-const pointer to referred object

Standard_Transient* ControlAccess() const

{

return entity;

}

 

 

<bool IsSelected = curForm.View.IsObjectSelected();> (Form1.cs)

 

public shell View

{

get

{

return this.myView;

}

set

{

this.myView=value

}

}

 

 

->(shell.h)

 

bool IsObjectSelected(void){

if (myOCCViewer != NULL)

return myOCCViewer->IsObjectSelected();

else

return false

}

 

<return myOCCViewer->IsObjectSelected();> (OCCViewer.cpp)

 

bool OCCViewer::IsObjectSelected(void)

{

if (myAISContext.IsNull())

return false

myAISContext->InitCurrent();

return (bool)myAISContext->MoreCurrent();

}

 

 

<if (myAISContext.IsNull())> (Handle_Standard_Transient.hxx)

 

//! Check for being null

Standard_Boolean IsNull() const

{

return entity == UndefinedHandleAddress;

}

 

 

<myAISContext->InitCurrent();> (Handle_AIS_InteractiveContext.hxx)

 

AIS_InteractiveContext* operator->() const

{

return (AIS_InteractiveContext *)ControlAccess();

}

 

 

<return (AIS_InteractiveContext *)ControlAccess();> (Handle_Standard_Transient.hxx)

 

Standard_Transient* ControlAccess() const

{

return entity;

}

 

 

<return (bool)myAISContext->MoreCurrent();> (Handle_AIS_InteractiveContext.hxx)

 

AIS_InteractiveContext* operator->() const

{

return (AIS_InteractiveContext *)ControlAccess();

}

 

<return (AIS_InteractiveContext *)ControlAccess();> (Handle_Standard_Transient.hxx)

 

//! Returns non-const pointer to referred object

Standard_Transient* ControlAccess() const

{

return entity;

}

 

 

<if (curForm.DegenerateMode)> (Form2.cs)

 

public bool DegenerateMode

{

get

{

return this.myDegenerateModeIsOn;

}

set

{

this.myDegenerateModeIsOn=value

}

}

 

 

<if (curForm.Mode == IE.CurrentAction3d.CurAction3d_WindowZooming)> (Form2.cs)

 

public CurrentAction3d Mode

{

get

{

return this.myCurrentMode;

}

set

{

this.myCurrentMode=value

}

}

 

 

 

 

private void Form2_SizeChanged(object sender, System.EventArgs e)

{

myView.UpdateView();

}

 

 

 

[분석결과 ]

STEPControl_Reader는 XSControl_Reader를 파생시켜 데이터를 분석하기 위한 클래스.

실제 파일을 읽는 작업은 XSControl_Reader의 메소드 ReadFile메소드에서 진행.

 

STEP은 기계관련 파일이므로 IFC파일을 읽어내야 했으나.

Opencascade에서는 IFCControl_Reader를 제공 하고 있지 않음.

 

[결론]

IFC파일을 읽어 내려면 XSControl_Reader를 상속받은 IFCControl_Reader를 만들어야 한다.

IFCControl_Reader는 IFC파일 데이터 분석 기능을 Opencascade가 그려내기에 적합한 데이터로 변환하는

기능을 제공 해야한다. (STEP파일 포멧과 IFC파일 포멧은 상당히 유사하다. 단, 스키마가 약간 다름)

출처: 원호형