Files
TestEIn/Controller.vb
T
Dario Sassi 62d7de4b75 TestEIn :
- piccola correzione a Controller per copia Pezzo/Layer/Oggetto.
2014-11-18 17:36:56 +00:00

2086 lines
66 KiB
VB.net

'----------------------------------------------------------------------------
' EgalTech 2014-2014
'----------------------------------------------------------------------------
' File : Controller.vb Data : 04.11.14 Versione : 1.5k1
' Contenuto : Classe Controller (parte di MCV).
'
'
'
' Modifiche : 04.11.14 DS Creazione modulo.
'
'
'----------------------------------------------------------------------------
Imports Microsoft.VisualBasic
Imports System.Globalization
Imports TestEIn.EgtInterface
Public Class Controller
' Events
Public Enum IBT As Integer
TY_NULL = 0
TY_STRING
TY_DOUBLE
TY_3DOUBLE
TY_POINT3D
End Enum
Public Event SetInputBox(ByVal sTitle As String, ByVal sLabel As String, ByVal nType As IBT)
Public Event AddInputCheck(ByVal sLabel As String)
Public Event AddButtonShow()
Public Event SetInputBoxString(ByVal sText As String)
Public Event SetInputBoxDouble(ByVal dVal As Double)
Public Event SetInputBoxPoint3d(ByVal ptP As Point3d)
Public Event SetInputBoxVector3d(ByVal vtV As Vector3d)
Public Event UpdateUI(ByVal sender As Object, ByVal bReloadUI As Boolean)
' Documento e Vista
Private m_Scene As Scene
' Comandi e Stati
Public Enum CMD As Integer
NULL = 0
GRID
GRID_ELEVATION
GRID_ORIGIN
GRID_ROTATE
GRID_3P
NEWPART
NEWLAYER
SETCURRPARTLAYER
RESETCURRPARTLAYER
LAYERCOLOR
SELECTPARTLAYEROBJ
DESELECTPARTLAYEROBJ
RELOCATEPARTLAYEROBJ
COPYPARTLAYEROBJ
SHOW
HIDE
SETNAME
SETINFO
POINT
LINE2P
CIRCLECR
ARCCSE
ARC3P
PLANE
EXTRUDE
REVOLVE
REVOLVEPLUS
RULED
DELETE
CHANGECOLOR
RESETCOLOR
INVERTCRVSURF
EXTENDCURVE
BREAKCURVE
JOINCURVE
EXPLODECURVE
MOVE
ROTATE
ROTATE3D
MIRROR
SCALE
SCALE3D
End Enum
Public Enum GRID_TYPE As Integer
NONE = 0
TOP
FRONT
RIGHT
BACK
LEFT
BOTTOM
End Enum
Private m_nLastCmd As CMD = CMD.NULL
Private m_nStep As Integer = 0
Private m_ptP1 As Point3d
Private m_ptP2 As Point3d
Private m_ptLast As Point3d
Private m_ptCont As Point3d
Private m_dLast As Double = 0
Private m_dPrev As Double = 0
Private m_d3Last() As Double = {0, 0, 0}
Private m_d3Prev() As Double = {0, 0, 0}
Private m_nLast1 As Integer = 0
Private m_nLast2 As Integer = 0
Private m_sLast As String = String.Empty
Private m_bLast As Boolean = False
' Metodi
Public Sub SetScene(ByRef scene As Scene)
m_Scene = scene
End Sub
Public Sub SetLastPoint3d(ByRef ptP As Point3d)
m_ptLast = ptP
End Sub
Public Sub SetLastDouble(ByVal dVal As Double)
m_dLast = dVal
End Sub
Public Sub SetLast3Double(ByVal d3Val() As Double)
If d3Val.Length >= 1 Then
m_d3Last(0) = d3Val(0)
If d3Val.Length >= 2 Then
m_d3Last(1) = d3Val(1)
If d3Val.Length >= 3 Then
m_d3Last(2) = d3Val(2)
End If
End If
End If
End Sub
Public Sub SetLastIntegers(ByVal nVal1 As Integer, ByVal nVal2 As Integer)
m_nLast1 = nVal1
m_nLast2 = nVal2
End Sub
Public Sub SetLastString(ByRef sVal As String)
m_sLast = sVal
End Sub
Public Sub SetLastBoolean(ByVal bVal As Boolean)
m_bLast = bVal
End Sub
Private Function GetDoubleFromString(ByRef sText As String, ByRef dVal As Double) As Boolean
Return Double.TryParse(sText, NumberStyles.Float, CultureInfo.InvariantCulture, dVal)
End Function
Private Function GetPoint3dFromString(ByRef sText As String, ByRef PtVal As Point3d) As Boolean
Dim sItems() As String = sText.Split(",".ToCharArray)
Dim bOk As Boolean = False
PtVal = Point3d.ORIG
If sItems.Count() >= 1 Then
bOk = Double.TryParse(sItems(0), NumberStyles.Float, CultureInfo.InvariantCulture, PtVal.x)
If sItems.Count() >= 2 Then
bOk = Double.TryParse(sItems(1), NumberStyles.Float, CultureInfo.InvariantCulture, PtVal.y) And bOk
If sItems.Count() >= 3 Then
bOk = Double.TryParse(sItems(2), NumberStyles.Float, CultureInfo.InvariantCulture, PtVal.z) And bOk
End If
End If
End If
Return bOk
End Function
Public Sub ResetStatus()
m_nStep = 0
m_Scene.ResetStatus()
End Sub
Public Function RepeatLastCommand() As Boolean
Return ExecuteCommand(m_nLastCmd)
End Function
Public Function ExecuteCommand(ByVal nCmd As CMD) As Boolean
' posso partire solo con stato libero
If m_nStep <> 0 Then
Return False
End If
' salvo ed eseguo il comando
m_nLastCmd = nCmd
ProcessStatus()
Return True
End Function
Public Function ProcessStatus() As Boolean
Select Case m_nLastCmd
' Grid
Case CMD.GRID
Return ProcessGrid()
' Grid origin
Case CMD.GRID_ELEVATION
Return ProcessGridElevation()
Case CMD.GRID_ORIGIN
Return ProcessGridOrigin()
' rotazione Griglia/Cplane
Case CMD.GRID_ROTATE
Return ProcessGridRotate()
' Griglia/Cplane dati 3 punti
Case CMD.GRID_3P
Return ProcessGrid3P()
' Nuovo Pezzo
Case CMD.NEWPART
Return ProcessNewPart()
' Nuovo Layer
Case CMD.NEWLAYER
Return ProcessNewLayer()
' Imposto pezzo e layer correnti
Case CMD.SETCURRPARTLAYER
Return ProcessSetCurrPartLayer()
' Cancello pezzo e layer correnti
Case CMD.RESETCURRPARTLAYER
Return ProcessResetCurrPartLayer()
' Imposto colore del layer
Case CMD.LAYERCOLOR
Return ProcessLayerColor()
' Seleziono Pezzo/Layer/Oggetto
Case CMD.SELECTPARTLAYEROBJ
Return ProcessSelectPartLayerObj()
' Deseleziono Pezzo/Layer/Oggetto
Case CMD.DESELECTPARTLAYEROBJ
Return ProcessDeselectPartLayerObj()
' Riloco Pezzo/Layer/Oggetto
Case CMD.RELOCATEPARTLAYEROBJ
Return ProcessRelocatePartLayerObj()
' Copio Pezzo/Layer/Oggetto
Case CMD.COPYPARTLAYEROBJ
Return ProcessCopyPartLayerObj()
' Visualizza
Case CMD.SHOW
Return ProcessShow()
' Nascondi
Case CMD.HIDE
Return ProcessHide()
' Name
Case CMD.SETNAME
Return ProcessSetName()
' Info
Case CMD.SETINFO
Return ProcessSetInfo()
' Point
Case CMD.POINT
Return ProcessPoint()
' Line2P
Case CMD.LINE2P
Return ProcessLine2P()
' CircleCR
Case CMD.CIRCLECR
Return ProcessCircleCR()
' ArcCSE
Case CMD.ARCCSE
Return ProcessArcCSE()
' Arc3P
Case CMD.ARC3P
Return ProcessArc3P()
' Plane
Case CMD.PLANE
Return ProcessPlane()
' Extrude
Case CMD.EXTRUDE
Return ProcessExtrude()
' Revolve
Case CMD.REVOLVE
Return ProcessRevolve()
' Revolve Plus
Case CMD.REVOLVEPLUS
Return ProcessRevolvePlus()
' Ruled
Case CMD.RULED
Return ProcessRuled()
' Delete
Case CMD.DELETE
Return ProcessDelete()
' Change Color
Case CMD.CHANGECOLOR
Return ProcessChangeColor()
' Reset Color
Case CMD.RESETCOLOR
Return ProcessResetColor()
' Invert Curve or Surface
Case CMD.INVERTCRVSURF
Return ProcessInvertCurveSurf()
' Extend Curve
Case CMD.EXTENDCURVE
Return ProcessExtendCurve()
' Break Curve
Case CMD.BREAKCURVE
Return ProcessBreakCurve()
' Join Curve
Case CMD.JOINCURVE
Return ProcessJoinCurve()
' Separate Curve
Case CMD.EXPLODECURVE
Return ProcessExplodeCurve()
' Move
Case CMD.MOVE
Return ProcessMove()
' Rotate
Case CMD.ROTATE
ProcessRotate()
' Rotate 3d
Case CMD.ROTATE3D
ProcessRotate3D()
' Mirror
Case CMD.MIRROR
ProcessMirror()
' Scale
Case CMD.SCALE
ProcessScale()
' Scale 3d
Case CMD.SCALE3D
ProcessScale3D()
Case Else
Return False
End Select
Return True
End Function
Public Function ExecuteDrag() As Boolean
Select Case m_nLastCmd
Case CMD.GRID_ROTATE
DragGridRotate()
Case CMD.LINE2P
DragLine2P()
Case CMD.CIRCLECR
DragCircleCR()
Case CMD.ARCCSE
DragArcCSE()
Case CMD.ARC3P
DragArc3P()
Case CMD.EXTRUDE
DragExtrude()
Case CMD.REVOLVE
DragRevolve()
Case CMD.REVOLVEPLUS
DragRevolvePlus()
Case CMD.MOVE
DragMove()
Case CMD.ROTATE
DragRotate()
Case CMD.ROTATE3D
DragRotate3D()
Case CMD.MIRROR
DragMirror()
Case CMD.SCALE
DragScale()
Case CMD.SCALE3D
DragScale3D()
Case Else
Return False
End Select
Return True
End Function
Private Function ProcessGrid() As Boolean
If m_nStep <> 0 Then
Return False
End If
Dim frNew As New Frame3d
Select Case m_nLast1
Case GRID_TYPE.TOP
frNew.Setup(Point3d.ORIG, Vector3d.X_AX, Vector3d.Y_AX, Vector3d.Z_AX)
Case GRID_TYPE.FRONT
frNew.Setup(Point3d.ORIG, Vector3d.X_AX, Vector3d.Z_AX, -Vector3d.Y_AX)
Case GRID_TYPE.RIGHT
frNew.Setup(Point3d.ORIG, Vector3d.Y_AX, Vector3d.Z_AX, Vector3d.X_AX)
Case GRID_TYPE.BACK
frNew.Setup(Point3d.ORIG, -Vector3d.X_AX, Vector3d.Z_AX, Vector3d.Y_AX)
Case GRID_TYPE.LEFT
frNew.Setup(Point3d.ORIG, -Vector3d.Y_AX, Vector3d.Z_AX, -Vector3d.X_AX)
Case GRID_TYPE.BOTTOM
frNew.Setup(Point3d.ORIG, -Vector3d.X_AX, Vector3d.Y_AX, -Vector3d.Z_AX)
Case Else
Return False
End Select
EgtSetGridFrame(frNew)
EgtDraw()
Return True
End Function
Private Function ProcessGridElevation() As Boolean
Select Case m_nStep
Case 0
' non serve il gruppo di drag
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per elevazione griglia
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("GRID", "Insert Elevation", IBT.TY_DOUBLE)
Case 1
' recupero il piano di griglia corrente
Dim frCurr As New Frame3d
EgtGetGridFrame(frCurr)
' cambio l'elevazione dell'origine
frCurr.Move(EgtGetGridVersZ() * m_dLast)
' imposto nuova griglia
EgtSetGridFrame(frCurr)
' reset stato scena
m_Scene.ResetStatus()
' aggiorno stato
m_nStep = 0
RaiseEvent UpdateUI(Me, False)
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Function ProcessGridOrigin() As Boolean
Select Case m_nStep
Case 0
' non serve il gruppo di drag
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per origine griglia
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("GRID", "Insert Origin", IBT.TY_POINT3D)
Case 1
' recupero il piano di griglia corrente
Dim frCurr As New Frame3d
EgtGetGridFrame(frCurr)
' ne modifico l'origine
frCurr.Move(m_ptLast - frCurr.Orig())
' imposto nuova griglia
EgtSetGridFrame(frCurr)
' reset stato scena
m_Scene.ResetStatus()
' aggiorno stato
m_nStep = 0
RaiseEvent UpdateUI(Me, False)
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Function ProcessGridRotate() As Boolean
Select Case m_nStep
Case 0
' non serve il gruppo di drag
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per rotazione griglia
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("GRID ROTATE", "Insert First Point on Axis", IBT.TY_POINT3D)
Case 1
m_ptP1 = m_ptLast
m_ptP2 = m_ptP1
m_nStep = 2
RaiseEvent SetInputBox("GRID ROTATE", "Insert Second Point on Axis", IBT.TY_POINT3D)
RaiseEvent AddButtonShow()
Case 2
m_ptP2 = m_ptLast
m_nStep = 3
RaiseEvent SetInputBox("GRID ROTATE", "Insert angle", IBT.TY_DOUBLE)
Case 3
' eseguo rotazione
Dim VtAx As Vector3d = m_ptP2 - m_ptP1
Dim frCurr As New Frame3d
EgtGetGridFrame(frCurr)
frCurr.Rotate(m_ptP1, VtAx, m_dLast)
EgtSetGridFrame(frCurr)
' reset
m_Scene.ResetStatus()
m_nStep = 0
RaiseEvent UpdateUI(Me, False)
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragGridRotate()
If m_nStep = 2 Then
EgtSetGeoLine(m_ptP1, m_ptLast)
EgtDraw()
ElseIf m_nStep = 3 Then
EgtSetGeoLine(m_ptP1, m_ptP2)
EgtDraw()
End If
End Sub
Private Function ProcessGrid3P() As Boolean
Select Case m_nStep
Case 0
' non serve il gruppo di drag
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per rotazione griglia
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("GRID 3 POINTS", "Insert Origin", IBT.TY_POINT3D)
Case 1
m_ptP1 = m_ptLast
m_ptP2 = m_ptP1
m_nStep = 2
RaiseEvent SetInputBox("GRID 3 POINTS", "Insert Point on X Axis", IBT.TY_POINT3D)
Case 2
m_ptP2 = m_ptLast
m_nStep = 3
RaiseEvent SetInputBox("GRID 3 POINTS", "Insert Point Near Y Axis", IBT.TY_POINT3D)
Case 3
' calcolo griglia per 3 punti
Dim frCurr As New Frame3d
If Not frCurr.Setup(m_ptP1, m_ptP2, m_ptLast) Then
m_Scene.ResetStatus()
m_nStep = 0
Return False
End If
EgtSetGridFrame(frCurr)
' reset
m_Scene.ResetStatus()
m_nStep = 0
RaiseEvent UpdateUI(Me, False)
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Function ProcessNewPart() As Boolean
If m_nStep <> 0 Then
Return False
End If
' inserisco un nuovo gruppo (piece) sotto la radice
Dim nIdNewPart As Integer = EgtCreateGroup(GDB_ID.ROOT)
' inserisco un nuovo gruppo (layer) sotto quello appena creato
Dim nIdNewLayer As Integer = EgtCreateGroup(nIdNewPart)
' se ok, salvo nuova situazione
If nIdNewPart <> GDB_ID.NULL And nIdNewLayer <> GDB_ID.NULL Then
m_nCurrPart = nIdNewPart
m_nCurrLayer = nIdNewLayer
SetModified()
End If
Return True
End Function
Private Function ProcessNewLayer() As Boolean
If m_nStep <> 0 Then
Return False
End If
' inserisco un nuovo gruppo (layer) sotto il pezzo corrente
Dim nIdNewLayer As Integer = EgtCreateGroup(m_nCurrPart)
' se ok, salvo nuova situazione
If nIdNewLayer <> GDB_ID.NULL Then
m_nCurrLayer = nIdNewLayer
SetModified()
End If
Return True
End Function
Private Function ProcessSetCurrPartLayer() As Boolean
If m_nStep <> 0 Then
Return False
End If
SetCurrPartLayer(m_nLast1, m_nLast2)
Return True
End Function
Private Function ProcessResetCurrPartLayer() As Boolean
If m_nStep <> 0 Then
Return False
End If
ResetCurrPartLayer()
Return True
End Function
Private Function ProcessLayerColor() As Boolean
If m_nStep <> 0 Then
Return False
End If
Dim nCurrId As Integer
If m_nCurrPart <> GDB_ID.NULL Then
nCurrId = m_nCurrPart
If m_nCurrLayer <> GDB_ID.NULL Then
nCurrId = m_nCurrLayer
End If
Else
Return False
End If
Dim ColDlg As New ColorDialog
ColDlg.AnyColor = True
Dim colObj As Color3d
EgtGetCalcColor(nCurrId, colObj)
ColDlg.Color = colObj.ToColor()
ColDlg.FullOpen = True
If ColDlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
colObj.FromColor(ColDlg.Color)
EgtSetColor(nCurrId, colObj)
SetModified()
EgtDraw()
End If
Return True
End Function
Private Function ProcessSelectPartLayerObj() As Boolean
If m_nStep <> 0 Then
Return False
End If
' se gruppo
If EgtGetType(m_nLast1) = GDB_TY.GROUP Then
' se pezzo
If EgtGetParent(m_nLast1) = GDB_ID.ROOT Then
' seleziono tutti gli oggetti del pezzo
If Not EgtSelectPartObjs(m_nLast1) Then
Return False
End If
' se layer
ElseIf EgtGetParent(EgtGetParent(m_nLast1)) = GDB_ID.ROOT Then
' seleziono tutti gli oggetti del layer
If Not EgtSelectLayerObjs(m_nLast1) Then
Return False
End If
' altrimenti errore
Else
Return False
End If
' altrimenti entità
Else
' la seleziono
If Not EgtSelectObj(m_nLast1) Then
Return False
End If
End If
SetModified()
EgtDraw()
Return True
End Function
Private Function ProcessDeselectPartLayerObj() As Boolean
If m_nStep <> 0 Then
Return False
End If
' se gruppo
If EgtGetType(m_nLast1) = GDB_TY.GROUP Then
' se pezzo
If EgtGetParent(m_nLast1) = GDB_ID.ROOT Then
' deseleziono tutti gli oggetti del pezzo
If Not EgtDeselectPartObjs(m_nLast1) Then
Return False
End If
' se layer
ElseIf EgtGetParent(EgtGetParent(m_nLast1)) = GDB_ID.ROOT Then
' deseleziono tutti gli oggetti del layer
If Not EgtDeselectLayerObjs(m_nLast1) Then
Return False
End If
' altrimenti errore
Else
Return False
End If
' altrimenti entità
Else
' la deseleziono
If Not EgtDeselectObj(m_nLast1) Then
Return False
End If
End If
SetModified()
EgtDraw()
Return True
End Function
Private Function ProcessRelocatePartLayerObj() As Boolean
If m_nStep <> 0 Then
Return False
End If
Dim nRefId As Integer = GDB_ID.NULL
Dim nPos As GDB_POS = GDB_POS.SON
' se gruppo
If EgtGetType(m_nLast1) = GDB_TY.GROUP Then
' se pezzo
If EgtGetParent(m_nLast1) = GDB_ID.ROOT Then
' il riferimento è dopo l'ultimo sotto la radice
nRefId = EgtGetLastInGroup(GDB_ID.ROOT)
nPos = GDB_POS.AFTER
' se layer
ElseIf EgtGetParent(EgtGetParent(m_nLast1)) = GDB_ID.ROOT Then
' il riferimento è il pezzo corrente
nRefId = m_nCurrPart
' se il pezzo sorgente è il corrente
If EgtGetParent(m_nLast1) = m_nCurrPart Then
' il riferimento è dopo l'ultimo sotto il pezzo
nRefId = EgtGetLastInGroup(m_nCurrPart)
nPos = GDB_POS.AFTER
End If
' altrimenti errore
Else
Return False
End If
' altrimenti entità
Else
' il riferimento è il layer corrente
nRefId = m_nCurrLayer
' se il layer sorgente è il corrente
If EgtGetParent(m_nLast1) = m_nCurrLayer Then
' il riferimento è dopo l'ultimo sotto il layer
nRefId = EgtGetLastInGroup(m_nCurrLayer)
nPos = GDB_POS.AFTER
End If
End If
EgtRelocateGlob(m_nLast1, nRefId, nPos)
SetModified()
EgtDraw()
Return True
End Function
Private Function ProcessCopyPartLayerObj() As Boolean
If m_nStep <> 0 Then
Return False
End If
EgtDeselectAll()
Dim nNewId = GDB_ID.NULL
' se gruppo
If EgtGetType(m_nLast1) = GDB_TY.GROUP Then
' se pezzo
If EgtGetParent(m_nLast1) = GDB_ID.ROOT Then
' eseguo copia
nNewId = EgtCopyGlob(m_nLast1, GDB_ID.ROOT)
' seleziono tutti gli oggetti del pezzo
If Not EgtSelectPartObjs(nNewId) Then
Return False
End If
' se layer
ElseIf EgtGetParent(EgtGetParent(m_nLast1)) = GDB_ID.ROOT Then
' eseguo copia
nNewId = EgtCopyGlob(m_nLast1, m_nCurrPart)
' seleziono tutti gli oggetti del layer
If Not EgtSelectLayerObjs(nNewId) Then
Return False
End If
' altrimenti errore
Else
Return False
End If
' altrimenti entità
Else
' eseguo copia
nNewId = EgtCopyGlob(m_nLast1, m_nCurrLayer)
' la seleziono
If Not EgtSelectObj(nNewId) Then
Return False
End If
End If
' dichiaro modifica
SetModified()
' preparo per il drag
If Not PrepareTransform() Then
Return False
End If
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per Move
m_nLastCmd = CMD.MOVE
m_bLast = False
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("MOVE", "Insert Base Point", IBT.TY_POINT3D)
Return True
End Function
Private Function ProcessShow() As Boolean
If m_nStep <> 0 Then
Return False
End If
If m_nLast1 <> GDB_ID.NULL Then
Dim nStat As GDB_ST = GDB_ST.ON_
EgtGetStatus(m_nLast1, nStat)
If nStat = GDB_ST.OFF Then
EgtSetStatus(m_nLast1, GDB_ST.ON_)
SetModified(False)
EgtDraw()
End If
End If
Return True
End Function
Private Function ProcessHide() As Boolean
If m_nStep <> 0 Then
Return False
End If
If m_nLast1 <> GDB_ID.NULL Then
Dim nStat As GDB_ST = GDB_ST.ON_
EgtGetStatus(m_nLast1, nStat)
If nStat <> GDB_ST.OFF Then
EgtSetStatus(m_nLast1, GDB_ST.OFF)
SetModified(False)
EgtDraw()
End If
End If
Return True
End Function
Private Function ProcessSetName() As Boolean
Select Case m_nStep
Case 0
' posso partire solo se esiste una entità riferita
If m_nLast1 = GDB_ID.NULL Then
Return False
End If
' recupero e imposto eventuale nome già assegnato
m_sLast = String.Empty
EgtGetName(m_nLast1, m_sLast)
' imposto stato a prima stringa per nome
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("NAME", "Insert Name", IBT.TY_STRING)
RaiseEvent SetInputBoxString(m_sLast)
Case 1
' assegno il nome
If Not String.IsNullOrWhiteSpace(m_sLast) Then
EgtSetName(m_nLast1, m_sLast)
Else
EgtRemoveName(m_nLast1)
End If
' reset stato scena
m_Scene.ResetStatus()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Function ProcessSetInfo() As Boolean
Select Case m_nStep
Case 0
' posso partire solo se esiste una entità riferita
If m_nLast1 = GDB_ID.NULL Then
Return False
End If
' imposto stato a prima stringa per info
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("INFO", "Insert Info (Key=Val)", IBT.TY_STRING)
Case 1
' divido la stringa in chiave e valore
Dim sItems() As String = m_sLast.Split("=".ToCharArray)
If sItems.Count() = 2 Then
' assegno l'info
If Not String.IsNullOrWhiteSpace(sItems(1)) Then
EgtSetInfo(m_nLast1, sItems(0), sItems(1))
' rimuovo l'info
Else
EgtRemoveInfo(m_nLast1, sItems(0))
End If
End If
' reset stato scena
m_Scene.ResetStatus()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Function ProcessPoint() As Boolean
Select Case m_nStep
Case 0
' deve esistere un gruppo corrente
If GetCurrLayer() = GDB_ID.NULL Then
Return False
End If
' non serve il gruppo di drag
' imposto stato a primo punto per point
m_Scene.SetStatusSelPoint()
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("POINT", "Insert Point", IBT.TY_POINT3D)
RaiseEvent SetInputBoxPoint3d(m_ptCont)
Case 1
' creo il punto (i dati sono in globale)
If EgtCreateGeoPoint(GetCurrLayer(), m_ptLast.Loc(GetCurrLayer())) Then
m_ptCont = m_ptLast
End If
' reset stato scena
m_Scene.ResetStatus()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Function ProcessLine2P() As Boolean
Select Case m_nStep
Case 0
' deve esistere un gruppo corrente e devo poter creare il gruppo di drag
If GetCurrLayer() = GDB_ID.NULL Or Not m_Scene.CreateDragGroup() Then
Return False
End If
' imposto stato a primo punto per Line2P
m_Scene.SetStatusSelPoint()
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("LINE", "Insert Start Point", IBT.TY_POINT3D)
RaiseEvent SetInputBoxPoint3d(m_ptCont)
Case 1
m_ptP1 = m_ptLast
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("LINE", "Insert End Point ", IBT.TY_POINT3D)
RaiseEvent SetInputBoxPoint3d(m_ptLast.Loc(GetCurrLayer()))
RaiseEvent AddButtonShow()
Case 2
' reset scena
m_Scene.ResetStatus(False)
' creo la linea (i punti sono in globale)
If EgtCreateCurveLine(GetCurrLayer(), m_ptP1.Loc(GetCurrLayer()), m_ptLast.Loc(GetCurrLayer())) Then
m_ptCont = m_ptLast
End If
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragLine2P()
If m_nStep = 2 Then
' durante la creazione di oggetti il gruppo di Drag ha riferimento globale
Dim nId As Integer = EgtGetFirstInGroup(m_Scene.GetDragGroup())
If nId = GDB_ID.NULL Then
EgtCreateCurveLine(m_Scene.GetDragGroup(), m_ptP1, m_ptLast)
Else
EgtModifyCurveEndPoint(nId, m_ptLast)
End If
EgtDraw()
End If
End Sub
Private Function ProcessCircleCR() As Boolean
Select Case m_nStep
Case 0
' deve esistere un gruppo corrente e devo poter creare il gruppo di drag
If GetCurrLayer() = GDB_ID.NULL Or Not m_Scene.CreateDragGroup() Then
Return False
End If
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per CircleCR
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("CIRCLE", "Insert Center", IBT.TY_POINT3D)
Case 1
m_ptP1 = m_ptLast
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("CIRCLE", "Insert Point", IBT.TY_POINT3D)
RaiseEvent AddButtonShow()
Case 2
' reset scena
m_Scene.ResetStatus(False)
' creo la circonferenza (i punti sono in globale)
EgtCreateCurveCircleCPN(GetCurrLayer(), m_ptP1.Loc(GetCurrLayer()), m_ptLast.Loc(GetCurrLayer()), EgtGetGridVersZ())
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragCircleCR()
If m_nStep = 2 Then
' durante la creazione di oggetti il gruppo di Drag ha riferimento globale
Dim nId As Integer = EgtGetFirstInGroup(m_Scene.GetDragGroup())
If nId = GDB_ID.NULL Then
EgtCreateCurveCircleCPN(m_Scene.GetDragGroup(), m_ptP1, m_ptLast, EgtGetGridVersZ())
Else
EgtModifyCurveCircleCPN(nId, m_ptLast)
End If
EgtDraw()
End If
End Sub
Private Function ProcessArcCSE() As Boolean
Select Case m_nStep
Case 0
' deve esistere un gruppo corrente e devo poter creare il gruppo di drag
If GetCurrLayer() = GDB_ID.NULL Or Not m_Scene.CreateDragGroup() Then
Return False
End If
' imposto stato a primo punto per ArcCSE
m_Scene.SetStatusSelPoint()
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("ARC", "Insert Center", IBT.TY_POINT3D)
Case 1
m_ptP1 = m_ptLast
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("ARC", "Insert Start Point", IBT.TY_POINT3D)
RaiseEvent AddButtonShow()
Case 2
m_ptP2 = m_ptLast
m_nStep = 3
m_Scene.EnableDrag()
RaiseEvent SetInputBox("ARC", "Insert Point Near End", IBT.TY_POINT3D)
Case 3
' reset scena
m_Scene.ResetStatus(False)
' creo l'arco (i punti sono in globale)
Dim nId = EgtCreateCurveArcC2PN(GetCurrLayer(), m_ptP1.Loc(GetCurrLayer()), m_ptP2.Loc(GetCurrLayer()), m_ptLast.Loc(GetCurrLayer()), EgtGetGridVersZ())
If nId <> GDB_ID.NULL Then
Dim PtP As Point3d
EgtEndPoint(nId, PtP)
m_ptCont = PtP.Glob(GetCurrLayer())
End If
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragArcCSE()
If m_nStep = 2 Then
' durante la creazione di oggetti il gruppo di Drag ha riferimento globale
Dim nId As Integer = EgtGetFirstInGroup(m_Scene.GetDragGroup())
If nId = GDB_ID.NULL Then
EgtCreateCurveLine(m_Scene.GetDragGroup(), m_ptP1, m_ptLast)
Else
EgtModifyCurveEndPoint(nId, m_ptLast)
End If
EgtDraw()
ElseIf m_nStep = 3 Then
' durante la creazione di oggetti il gruppo di Drag ha riferimento globale
Dim nId As Integer = EgtGetFirstInGroup(m_Scene.GetDragGroup())
If EgtGetType(nId) <> GDB_TY.CRV_ARC Then
EgtErase(nId)
nId = GDB_ID.NULL
End If
If nId = GDB_ID.NULL Then
EgtCreateCurveArcC2PN(m_Scene.GetDragGroup(), m_ptP1, m_ptP2, m_ptLast, EgtGetGridVersZ())
Else
EgtModifyCurveArcC2PN(nId, m_ptLast)
End If
EgtDraw()
End If
End Sub
Private Function ProcessArc3P() As Boolean
Select Case m_nStep
Case 0
' deve esistere un gruppo corrente e devo poter creare il gruppo di drag
If GetCurrLayer() = GDB_ID.NULL Or Not m_Scene.CreateDragGroup() Then
Return False
End If
' imposto stato a primo punto per Arc3P
m_Scene.SetStatusSelPoint()
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("ARC", "Insert Start Point", IBT.TY_POINT3D)
RaiseEvent SetInputBoxPoint3d(m_ptCont)
Case 1
m_ptP1 = m_ptLast
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("ARC", "Insert End Point", IBT.TY_POINT3D)
RaiseEvent AddButtonShow()
Case 2
m_ptP2 = m_ptLast
m_nStep = 3
m_Scene.EnableDrag()
RaiseEvent SetInputBox("ARC", "Insert Mid Point", IBT.TY_POINT3D)
Case 3
' reset scena
m_Scene.ResetStatus(False)
' creo l'arco (i punti sono in globale)
If EgtCreateCurveArc3P(GetCurrLayer(), m_ptP1.Loc(GetCurrLayer()), m_ptLast.Loc(GetCurrLayer()), m_ptP2.Loc(GetCurrLayer())) Then
m_ptCont = m_ptP2
End If
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragArc3P()
If m_nStep = 2 Then
' durante la creazione di oggetti il gruppo di Drag ha riferimento globale
Dim nId As Integer = EgtGetFirstInGroup(m_Scene.GetDragGroup())
If nId = GDB_ID.NULL Then
EgtCreateCurveLine(m_Scene.GetDragGroup(), m_ptP1, m_ptLast)
Else
EgtModifyCurveEndPoint(nId, m_ptLast)
End If
EgtDraw()
ElseIf m_nStep = 3 Then
' durante la creazione di oggetti il gruppo di Drag ha riferimento globale
Dim nId As Integer = EgtGetFirstInGroup(m_Scene.GetDragGroup())
If EgtGetType(nId) <> GDB_TY.CRV_ARC Then
EgtErase(nId)
nId = GDB_ID.NULL
End If
If nId = GDB_ID.NULL Then
EgtCreateCurveArc3P(m_Scene.GetDragGroup(), m_ptP1, m_ptLast, m_ptP2)
Else
EgtModifyCurveArc3P(nId, m_ptLast)
End If
EgtDraw()
End If
End Sub
Private Function ProcessPlane() As Boolean
If m_nStep <> 0 Then
Return False
End If
' posso partire solo se esiste un gruppo corrente
If GetCurrLayer() = GDB_ID.NULL Then
Return False
End If
' creo la superficie piana (a partire da un contorno selezionato)
EgtCreateSurfTriMeshByContour(GetCurrLayer(), EgtGetLastSelectedObj(), EPS_STM)
EgtDeselectAll()
' reset stato scena
m_Scene.ResetStatus()
' reset stato
m_nStep = 0
SetModified()
Return True
End Function
Private Function ProcessExtrude() As Boolean
Select Case m_nStep
Case 0
' deve esistere un gruppo corrente e devo poter creare il gruppo di drag
If GetCurrLayer() = GDB_ID.NULL Or Not m_Scene.CreateDragGroup() Then
Return False
End If
' imposto stato a lunghezza di estrusione
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("EXTRUSION", "Insert length", IBT.TY_DOUBLE)
RaiseEvent AddButtonShow()
Case 1
' reset scena
m_Scene.ResetStatus(False)
' creo la superficie di estrusione (a partire da un contorno selezionato)
Dim VtExtr As Vector3d = EgtGetGridVersZ().Loc(GetCurrLayer()) * m_dLast
EgtCreateSurfTriMeshByExtrusion(GetCurrLayer(), EgtGetLastSelectedObj(), VtExtr, EPS_STM)
EgtDeselectAll()
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragExtrude()
If m_nStep = 1 Then
' cancello eventuale vecchia superficie di estrusione
EgtErase(EgtGetFirstInGroup(m_Scene.GetDragGroup()))
' creo la superficie di estrusione (a partire da un contorno selezionato)
Dim VtExtr As New Vector3d(0, 0, m_dLast)
EgtCreateSurfTriMeshByExtrusion(m_Scene.GetDragGroup(), EgtGetLastSelectedObj(), VtExtr, EPS_STM)
EgtDraw()
End If
End Sub
Private Function ProcessRevolve() As Boolean
Select Case m_nStep
Case 0
' deve esistere un gruppo corrente e devo poter creare il gruppo di drag
If GetCurrLayer() = GDB_ID.NULL Or Not m_Scene.CreateDragGroup() Then
Return False
End If
' imposto stato a primo punto
m_Scene.SetStatusSelPoint()
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("REVOLVE", "Insert First Point on Axis", IBT.TY_POINT3D)
Case 1
m_ptP1 = m_ptLast
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("REVOLVE", "Insert Second Point on Axis", IBT.TY_POINT3D)
RaiseEvent AddButtonShow()
Case 2
' reset scena
m_Scene.ResetStatus(False)
' creo la superficie di rivoluzione (i punti sono in globale)
Dim vtAx As Vector3d = m_ptLast - m_ptP1
EgtCreateSurfTriMeshByScrewing(GetCurrLayer(), EgtGetLastSelectedObj(),
m_ptP1.Loc(GetCurrLayer()), vtAx.Loc(GetCurrLayer()),
360, 0, EPS_STM)
EgtDeselectAll()
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragRevolve()
If m_nStep = 2 Then
EgtSetGeoLine(m_ptP1, m_ptLast)
EgtDraw()
End If
End Sub
Private Function ProcessRevolvePlus() As Boolean
Select Case m_nStep
Case 0
' deve esistere un gruppo corrente e devo poter creare il gruppo di drag
If GetCurrLayer() = GDB_ID.NULL Or Not m_Scene.CreateDragGroup() Then
Return False
End If
' imposto stato a primo punto
m_Scene.SetStatusSelPoint()
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("REVOLVE+", "Insert First Point on Axis", IBT.TY_POINT3D)
Case 1
m_ptP1 = m_ptLast
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("REVOLVE+", "Insert Second Point on Axis", IBT.TY_POINT3D)
Case 2
m_ptP2 = m_ptLast
m_dLast = 360
m_nStep = 3
m_Scene.DisableDrag()
RaiseEvent SetInputBox("REVOLVE+", "Insert Angle", IBT.TY_DOUBLE)
RaiseEvent SetInputBoxString("360")
RaiseEvent AddButtonShow()
Case 3
m_ptP2 = m_ptLast
m_dPrev = m_dLast
m_dLast = 0
m_nStep = 4
m_Scene.DisableDrag()
RaiseEvent SetInputBox("REVOLVE+", "Insert Move", IBT.TY_DOUBLE)
RaiseEvent SetInputBoxString("0")
Case 4
' reset scena
m_Scene.ResetStatus(False)
' creo la superficie di rivoluzione (i punti sono in globale)
Dim vtAx As Vector3d = m_ptP2 - m_ptP1
EgtCreateSurfTriMeshByScrewing(GetCurrLayer(), EgtGetLastSelectedObj(),
m_ptP1.Loc(GetCurrLayer()), vtAx.Loc(GetCurrLayer()),
m_dPrev, m_dLast, EPS_STM)
EgtDeselectAll()
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragRevolvePlus()
If m_nStep = 2 Then
EgtSetGeoLine(m_ptP1, m_ptLast)
EgtDraw()
ElseIf m_nStep = 3 Then
EgtSetGeoLine(m_ptP1, m_ptP2)
' cancello eventuale vecchia superficie
EgtErase(EgtGetFirstInGroup(m_Scene.GetDragGroup()))
' creo la superficie di rivoluzione (i punti sono in globale)
Dim vtAx As Vector3d = m_ptP2 - m_ptP1
EgtCreateSurfTriMeshByScrewing(m_Scene.GetDragGroup(), EgtGetLastSelectedObj(),
m_ptP1, vtAx, m_dLast, 0, EPS_STM)
EgtDraw()
ElseIf m_nStep = 4 Then
EgtSetGeoLine(m_ptP1, m_ptP2)
' cancello eventuale vecchia superficie
EgtErase(EgtGetFirstInGroup(m_Scene.GetDragGroup()))
' creo la superficie di rivoluzione (i punti sono in globale)
Dim vtAx As Vector3d = m_ptP2 - m_ptP1
EgtCreateSurfTriMeshByScrewing(m_Scene.GetDragGroup(), EgtGetLastSelectedObj(),
m_ptP1, vtAx, m_dPrev, m_dLast, EPS_STM)
EgtDraw()
End If
End Sub
Private Function ProcessRuled() As Boolean
If m_nStep <> 0 Then
Return False
End If
' posso partire solo se esiste un gruppo corrente
If GetCurrLayer() = GDB_ID.NULL Then
Return False
End If
' creo la superficie rigata (a partire da due contorni selezionati)
Dim nLastId As Integer = EgtGetLastSelectedObj()
Dim nPrevId As Integer = EgtGetPrevSelectedObj()
EgtCreateSurfTriMeshRuled(GetCurrLayer(), nPrevId, nLastId, EPS_STM)
EgtDeselectAll()
' reset stato scena
m_Scene.ResetStatus()
' reset stato
m_nStep = 0
SetModified()
Return True
End Function
Private Function ProcessDelete() As Boolean
If m_nStep <> 0 Then
Return False
End If
If m_nLast1 <> GDB_ID.NULL Then
EgtErase(m_nLast1)
If m_nLast1 = m_nCurrPart Then
ResetCurrPartLayer()
ElseIf m_nLast1 = m_nCurrLayer Then
SetCurrPartLayer(m_nCurrPart, EgtGetFirstGroupInGroup(m_nCurrPart))
End If
' reset
m_Scene.ResetStatus()
m_nStep = 0
SetModified()
End If
Return True
End Function
Private Function ProcessChangeColor() As Boolean
If m_nStep <> 0 Then
Return False
End If
' verifico ci sia qualcosa di selezionato
Dim nId As Integer = EgtGetFirstSelectedObj()
If nId = GDB_ID.NULL Then
Return False
End If
' lancio dialogo scelta colore
Dim ColDlg As New ColorDialog()
ColDlg.AnyColor = True
Dim colObj As Color3d
EgtGetCalcColor(nId, colObj)
ColDlg.Color = colObj.ToColor()
ColDlg.FullOpen = True
If ColDlg.ShowDialog() <> Windows.Forms.DialogResult.OK Then
Return False
End If
' assegno nuovo colore
colObj.FromColor(ColDlg.Color)
EgtSetColor(GDB_ID.SEL, colObj)
EgtDeselectAll()
' reset stato scena
m_Scene.ResetStatus()
' reset stato
m_nStep = 0
SetModified()
Return True
End Function
Private Function ProcessResetColor() As Boolean
If m_nStep <> 0 Then
Return False
End If
' verifico ci sia qualcosa di selezionato
Dim nId As Integer = EgtGetFirstSelectedObj()
If nId = GDB_ID.NULL Then
Return False
End If
' reset colore
EgtResetColor(GDB_ID.SEL)
EgtDeselectAll()
' reset stato scena
m_Scene.ResetStatus()
' reset stato
m_nStep = 0
SetModified()
Return True
End Function
Private Function ProcessInvertCurveSurf() As Boolean
If m_nStep <> 0 Then
Return False
End If
' lancio l'inversione delle curve/superfici
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
Select Case EgtGetType(nId)
Case GDB_TY.CRV_LINE, GDB_TY.CRV_ARC, GDB_TY.CRV_BEZ, GDB_TY.CRV_COMPO
EgtInvertCurve(nId)
Case GDB_TY.SRF_MESH
EgtInvertSurface(nId)
End Select
nId = EgtGetNextSelectedObj()
End While
EgtDeselectAll()
' reset stato scena
m_Scene.ResetStatus()
' reset stato
m_nStep = 0
SetModified()
Return True
End Function
Private Function ProcessExtendCurve() As Boolean
Select Case m_nStep
Case 0
' imposto stato a lunghezza di estensione
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("EXTEND", "Insert Length", IBT.TY_DOUBLE)
Case 1
' eseguo estensione sull'estremo più vicino al punto di selezione
Dim nId As Integer = EgtGetLastSelectedObj()
EgtExtendCurveByLen(nId, m_dLast, m_ptLast.Loc(nId))
EgtDeselectAll()
' reset stato scena
m_Scene.ResetStatus()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Function ProcessBreakCurve() As Boolean
Select Case m_nStep
Case 0
m_Scene.SetStatusSelPoint()
' imposto stato a punto per BreakCurve
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("BREAK", "Insert Point on Curve", IBT.TY_POINT3D)
Case 1
' eseguo spezzatura
EgtSplitCurveAtPoint(EgtGetLastSelectedObj(), m_ptLast)
EgtDeselectAll()
' reset stato scena
m_Scene.ResetStatus()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Function ProcessJoinCurve() As Boolean
If m_nStep <> 0 Then
Return False
End If
' posso partire solo se esiste un gruppo corrente
If GetCurrLayer() = GDB_ID.NULL Then
Return False
End If
' creo vettore di entità selezionate
Dim nCrvNum As Integer = 0
Dim nCrvIds(EgtGetSelectedObjNbr() - 1) As Integer
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
nCrvIds(nCrvNum) = nId
nCrvNum = nCrvNum + 1
nId = EgtGetNextSelectedObj()
End While
' creo la curva composita (concatenando le curve selezionate)
EgtCreateCurveCompoByChain(GetCurrLayer(), nCrvNum, nCrvIds, New Point3d, True)
EgtDeselectAll()
' reset stato scena
m_Scene.ResetStatus()
' reset stato
m_nStep = 0
SetModified()
Return True
End Function
Private Function ProcessExplodeCurve() As Boolean
If m_nStep <> 0 Then
Return False
End If
' opero su tutti gli oggetti selezionati
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' recupero il successivo, perchè il corrente verrà cancellato
Dim nNextId = EgtGetNextSelectedObj()
' eseguo esplosione
Select Case EgtGetType(nId)
Case GDB_TY.CRV_COMPO
' separo la curva composita nelle curve componenti
EgtSeparateCurveCompo(nId)
Case GDB_TY.CRV_BEZ
' approssimo la curva di Bezier con archi
EgtExplodeCurveBezier(nId, 10 * EPS_SMALL, True)
Case GDB_TY.EXT_TEXT
' esplodo il testo nei suoi contorni
EgtExplodeText(nId)
End Select
' passo al successivo
nId = nNextId
End While
EgtDeselectAll()
' reset stato scena
m_Scene.ResetStatus()
' reset stato
m_nStep = 0
SetModified()
Return True
End Function
Private Function ProcessMove() As Boolean
Select Case m_nStep
Case 0
' verifico condizioni e preparo per il drag
If Not PrepareTransform() Then
Return False
End If
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per Move
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("MOVE", "Insert Base Point", IBT.TY_POINT3D)
RaiseEvent AddInputCheck("Copy")
Case 1
m_ptP1 = m_ptLast
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("MOVE", "Insert Target Point", IBT.TY_POINT3D)
RaiseEvent AddButtonShow()
Case 2
m_Scene.ResetStatus(False)
' eseguo copia e movimento
If m_bLast Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
Dim nCopyId As Integer = EgtCopyGlob(nId, GetCurrLayer())
EgtMoveGlob(nCopyId, (m_ptLast - m_ptP1))
nId = EgtGetNextSelectedObj()
End While
' eseguo movimento
Else
EgtMoveGlob(GDB_ID.SEL, (m_ptLast - m_ptP1))
End If
EgtDeselectAll()
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragMove()
If m_nStep = 2 Then
' ripristino lo stato iniziale
EgtChangeGroupFrame(m_Scene.GetDragGroup(), Frame3d.GLOB)
' eseguo tutto il movimento
EgtMoveGlob(m_Scene.GetDragGroup(), (m_ptLast - m_ptP1))
EgtSetGeoLine(m_ptP1, m_ptLast)
EgtDraw()
End If
End Sub
Private Function ProcessRotate() As Boolean
Select Case m_nStep
Case 0
' verifico condizioni e preparo per il drag
If Not PrepareTransform() Then
Return False
End If
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per Rotate
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("ROTATE", "Insert Center", IBT.TY_POINT3D)
RaiseEvent AddInputCheck("Copy")
Case 1
m_ptP1 = m_ptLast
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("ROTATE", "Insert Base Point", IBT.TY_POINT3D)
Case 2
m_ptP2 = m_ptLast
m_nStep = 3
m_Scene.EnableDrag()
EgtSetGeoLine(m_ptP1, m_ptLast)
RaiseEvent SetInputBox("ROTATE", "Insert Rotation Point", IBT.TY_POINT3D)
RaiseEvent AddButtonShow()
Case 3
m_Scene.ResetStatus(False)
' calcolo parametri di rotazione
Dim dAngRotDeg As Double = 0
Dim bDet As Boolean = True
EgtGetVectorRotation((m_ptP2 - m_ptP1), (m_ptLast - m_ptP1), EgtGetGridVersZ(), dAngRotDeg, bDet)
' eseguo copia e rotazione
If m_bLast Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
Dim nCopyId As Integer = EgtCopyGlob(nId, GetCurrLayer())
EgtRotateGlob(nCopyId, m_ptP1, EgtGetGridVersZ(), dAngRotDeg)
nId = EgtGetNextSelectedObj()
End While
' eseguo rotazione
Else
EgtRotateGlob(GDB_ID.SEL, m_ptP1, EgtGetGridVersZ(), dAngRotDeg)
End If
EgtDeselectAll()
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragRotate()
If m_nStep = 2 Then
EgtSetGeoLine(m_ptP1, m_ptLast)
EgtDraw()
ElseIf m_nStep = 3 Then
EgtSetGeoLine(m_ptP1, m_ptLast)
' ripristino lo stato iniziale
EgtChangeGroupFrame(m_Scene.GetDragGroup(), Frame3d.GLOB)
' eseguo rotazione
Dim dAngRotDeg As Double = 0
Dim bDet As Boolean = True
EgtGetVectorRotation((m_ptP2 - m_ptP1), (m_ptLast - m_ptP1), EgtGetGridVersZ(), dAngRotDeg, bDet)
EgtRotateGlob(m_Scene.GetDragGroup(), m_ptP1, EgtGetGridVersZ(), dAngRotDeg)
EgtDraw()
End If
End Sub
Private Function ProcessRotate3D() As Boolean
Select Case m_nStep
Case 0
' verifico condizioni e preparo per il drag
If Not PrepareTransform() Then
Return False
End If
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per Rotate3d
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("ROTATE 3D", "Insert First Point on Axis", IBT.TY_POINT3D)
RaiseEvent AddInputCheck("Copy")
Case 1
m_ptP1 = m_ptLast
m_ptP2 = m_ptP1
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("ROTATE 3D", "Insert Second Point on Axis", IBT.TY_POINT3D)
RaiseEvent AddButtonShow()
Case 2
m_ptP2 = m_ptLast
m_nStep = 3
m_dLast = 0
' abilito dialogo
RaiseEvent SetInputBox("ROTATE 3D", "Insert angle", IBT.TY_DOUBLE)
Case 3
m_Scene.ResetStatus(False)
' calcolo parametri di rotazione
Dim VtAx As Vector3d = m_ptP2 - m_ptP1
' eseguo copia e rotazione
If m_bLast Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
Dim nCopyId As Integer = EgtCopyGlob(nId, GetCurrLayer())
EgtRotateGlob(nCopyId, m_ptP1, VtAx, m_dLast)
nId = EgtGetNextSelectedObj()
End While
' eseguo rotazione
Else
EgtRotateGlob(GDB_ID.SEL, m_ptP1, VtAx, m_dLast)
End If
EgtDeselectAll()
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragRotate3D()
If m_nStep = 2 Then
EgtSetGeoLine(m_ptP1, m_ptLast)
EgtDraw()
ElseIf m_nStep = 3 Then
EgtSetGeoLine(m_ptP1, m_ptP2)
' ripristino lo stato iniziale
EgtChangeGroupFrame(m_Scene.GetDragGroup(), Frame3d.GLOB)
' eseguo rotazione
Dim VtAx As Vector3d = m_ptP2 - m_ptP1
EgtRotateGlob(m_Scene.GetDragGroup(), m_ptP1, VtAx, m_dLast)
EgtDraw()
End If
End Sub
Private Function ProcessMirror() As Boolean
Select Case m_nStep
Case 0
' verifico condizioni e preparo per il drag
If Not PrepareTransform() Then
Return False
End If
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per Mirror
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("MIRROR", "Insert Start Point", IBT.TY_POINT3D)
RaiseEvent AddInputCheck("Copy")
Case 1
m_ptP1 = m_ptLast
m_ptP2 = m_ptP1
m_nStep = 2
m_Scene.EnableDrag()
RaiseEvent SetInputBox("MIRROR", "Insert End Point", IBT.TY_POINT3D)
RaiseEvent AddButtonShow()
Case 2
m_Scene.ResetStatus(False)
' esecuzione
Dim VtNorm As Vector3d = (m_ptLast - m_ptP1) ^ EgtGetGridVersZ()
If VtNorm.Len > EPS_SMALL Then
' eseguo copia e mirror
If m_bLast Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
Dim nCopyId As Integer = EgtCopyGlob(nId, GetCurrLayer())
EgtMirrorGlob(nCopyId, m_ptP1, VtNorm)
nId = EgtGetNextSelectedObj()
End While
' eseguo rotazione
Else
EgtMirrorGlob(GDB_ID.SEL, m_ptP1, VtNorm)
End If
End If
EgtDeselectAll()
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragMirror()
If m_nStep = 2 Then
' linea di mirror
EgtSetGeoLine(m_ptP1, m_ptLast)
' ripristino lo stato iniziale, tramite annullo mirror precedente
Dim VtNorm As Vector3d = (m_ptP2 - m_ptP1) ^ EgtGetGridVersZ()
If VtNorm.Len > EPS_SMALL Then
EgtMirrorGlob(m_Scene.GetDragGroup(), m_ptP1, VtNorm)
End If
' eseguo mirror
VtNorm = (m_ptLast - m_ptP1) ^ EgtGetGridVersZ()
If VtNorm.Len > EPS_SMALL Then
EgtMirrorGlob(m_Scene.GetDragGroup(), m_ptP1, VtNorm)
End If
' salvo il punto
m_ptP2 = m_ptLast
EgtDraw()
End If
End Sub
Private Function ProcessScale() As Boolean
Select m_nStep
Case 0
' verifico condizioni e preparo per il drag
If Not PrepareTransform() Then
Return False
End If
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per Rotate
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("SCALE", "Insert Center", IBT.TY_POINT3D)
RaiseEvent AddInputCheck("Copy")
Case 1
m_ptP1 = m_ptLast
m_dPrev = 1
m_dLast = 1
m_nStep = 2
RaiseEvent SetInputBox("SCALE", "Insert Factor", IBT.TY_DOUBLE)
RaiseEvent SetInputBoxString("1")
RaiseEvent AddButtonShow()
Case 2
m_Scene.ResetStatus(False)
' calcolo parametri di scalatura
Dim frScale As New Frame3d
EgtGetGridFrame(frScale)
frScale.ChangeOrigin(m_ptP1)
' eseguo copia e scalatura
If m_bLast Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
Dim nCopyId As Integer = EgtCopyGlob(nId, GetCurrLayer())
EgtScaleGlob(nCopyId, frScale, m_dLast, m_dLast, m_dLast)
nId = EgtGetNextSelectedObj()
End While
' eseguo scalatura
Else
EgtScaleGlob(GDB_ID.SEL, frScale, m_dLast, m_dLast, m_dLast)
End If
EgtDeselectAll()
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragScale()
If m_nStep = 2 Then
' il fattore non può essere troppo piccolo o negativo
If m_dLast < EPS_SMALL Then
Return
End If
' calcolo parametri di scalatura
Dim frScale As New Frame3d
EgtGetGridFrame(frScale)
frScale.ChangeOrigin(m_ptP1)
Dim dScale As Double = m_dLast / m_dPrev
' eseguo scalatura
EgtScaleGlob(m_Scene.GetDragGroup(), frScale, dScale, dScale, dScale)
m_dPrev = m_dLast
EgtDraw()
End If
End Sub
Private Function ProcessScale3D() As Boolean
Select Case m_nStep
Case 0
' verifico condizioni e preparo per il drag
If Not PrepareTransform() Then
Return False
End If
m_Scene.SetStatusSelPoint()
' imposto stato a primo punto per Rotate
m_nStep = 1
' abilito dialogo
RaiseEvent SetInputBox("SCALE 3D", "Insert Center", IBT.TY_POINT3D)
RaiseEvent AddInputCheck("Copy")
Case 1
m_ptP1 = m_ptLast
m_d3Prev(0) = 1
m_d3Prev(1) = 1
m_d3Prev(2) = 1
m_d3Last(0) = 1
m_d3Last(1) = 1
m_d3Last(2) = 1
m_nStep = 2
m_Scene.DisableDrag()
RaiseEvent SetInputBox("SCALE 3D", "Insert Factor", IBT.TY_3DOUBLE)
RaiseEvent SetInputBoxString("1,1,1")
RaiseEvent AddButtonShow()
Case 2
m_Scene.ResetStatus(False)
' calcolo parametri di scalatura
Dim frScale As New Frame3d
EgtGetGridFrame(frScale)
frScale.ChangeOrigin(m_ptP1)
' eseguo copia e scalatura
If m_bLast Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
Dim nCopyId As Integer = EgtCopyGlob(nId, GetCurrLayer())
EgtScaleGlob(nCopyId, frScale, m_d3Last(0), m_d3Last(1), m_d3Last(2))
nId = EgtGetNextSelectedObj()
End While
' eseguo scalatura
Else
EgtScaleGlob(GDB_ID.SEL, frScale, m_d3Last(0), m_d3Last(1), m_d3Last(2))
End If
EgtDeselectAll()
EgtDraw()
' aggiorno stato
m_nStep = 0
SetModified()
Case Else
m_nStep = 0
Return False
End Select
Return True
End Function
Private Sub DragScale3D()
If m_nStep = 2 Then
' il fattore non può essere troppo piccolo o negativo
If m_d3Last(0) < EPS_SMALL Or m_d3Last(1) < EPS_SMALL Or m_d3Last(2) < EPS_SMALL Then
Return
End If
' calcolo parametri di scalatura
Dim frScale As New Frame3d
EgtGetGridFrame(frScale)
frScale.ChangeOrigin(m_ptP1)
Dim d3Scale(3) As Double
d3Scale(0) = m_d3Last(0) / m_d3Prev(0)
d3Scale(1) = m_d3Last(1) / m_d3Prev(1)
d3Scale(2) = m_d3Last(2) / m_d3Prev(2)
' eseguo scalatura
EgtScaleGlob(m_Scene.GetDragGroup(), frScale, d3Scale(0), d3Scale(1), d3Scale(2))
m_d3Prev(0) = m_d3Last(0)
m_d3Prev(1) = m_d3Last(1)
m_d3Prev(2) = m_d3Last(2)
EgtDraw()
End If
End Sub
Private Function PrepareTransform() As Boolean
' posso partire solo da stato libero
If m_nStep <> 0 Then
Return False
End If
' verifico ci sia qualcosa di selezionato
If EgtGetFirstSelectedObj() = GDB_ID.NULL Then
Return False
End If
' creo il gruppo di drag e vi copio le entità selezionate
If Not m_Scene.CreateDragGroup() Then
Return False
End If
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
If Not m_Scene.AddToDragGroup(nId) Then
m_Scene.EraseDragGroup()
Return False
End If
nId = EgtGetNextSelectedObj()
End While
Return True
End Function
'-------------------------------- Currente Part and Layer ----------------------------------------
Private m_nCurrPart = GDB_ID.NULL
Private m_nCurrLayer = GDB_ID.NULL
Public Function GetCurrPart() As Integer
Return m_nCurrPart
End Function
Public Function GetCurrLayer() As Integer
Return m_nCurrLayer
End Function
Private Function SetCurrPartLayer(ByVal nPart As Integer, ByVal nLayer As Integer) As Boolean
' reset
m_nCurrPart = GDB_ID.NULL
m_nCurrLayer = GDB_ID.NULL
' verifico esistenza e validità pezzo
If EgtExistsObj(nPart) And EgtGetParent(nPart) = GDB_ID.ROOT Then
m_nCurrPart = nPart
Else
Return False
End If
' verifico esistenza e validità layer
If EgtExistsObj(nLayer) And EgtGetParent(nLayer) = nPart Then
m_nCurrLayer = nLayer
Else
Return False
End If
Return True
End Function
Private Function ResetCurrPartLayer() As Boolean
' reset
m_nCurrPart = GDB_ID.NULL
m_nCurrLayer = GDB_ID.NULL
' cerco il primo pezzo
Dim nIdPart As Integer = EgtGetFirstGroupInGroup(GDB_ID.ROOT)
If nIdPart <> GDB_ID.NULL Then
' assegno il pezzo corrente
m_nCurrPart = nIdPart
' cerco il primo layer del pezzo
Dim nIdLayer As Integer = EgtGetFirstGroupInGroup(m_nCurrPart)
If nIdLayer <> GDB_ID.NULL Then
' assegno il layer corrente
m_nCurrLayer = nIdLayer
End If
End If
Return True
End Function
'-------------------------------- Modified Status ------------------------------------------------
Private m_sCurrFile As String = String.Empty
Private m_bModified As Boolean = False
Public Sub SetCurrFile(ByRef sFile As String)
m_sCurrFile = sFile
End Sub
Public Sub ResetCurrFile()
m_sCurrFile = String.Empty
End Sub
Public Function GetCurrFile() As String
Return m_sCurrFile
End Function
Public Sub SetModified(Optional ByVal bReloadUI As Boolean = True)
m_bModified = True
RaiseEvent UpdateUI(Me, bReloadUI)
End Sub
Public Sub ResetModified(Optional ByVal bReloadUI As Boolean = True)
m_bModified = False
RaiseEvent UpdateUI(Me, bReloadUI)
End Sub
Public Function GetModified() As Boolean
Return m_bModified
End Function
Public Function ManageModified() As Boolean
' se non modificato, procedo normalmente
If Not m_bModified Then
Return True
End If
' chiedo cosa fare
Dim sMsg As String = "Salvare le modifiche"
If Not String.IsNullOrEmpty(m_sCurrFile) Then
sMsg += " a " + m_sCurrFile
End If
sMsg += " ?"
Dim nRes = MessageBox.Show(sMsg, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
Select Case nRes
Case Windows.Forms.DialogResult.Yes
m_Scene.SaveProject(m_sCurrFile)
Return True
Case Windows.Forms.DialogResult.No
Return True
Case Else
Return False
End Select
End Function
End Class