From 5723c92e0916bb79a406618fda3cc9925f599a57 Mon Sep 17 00:00:00 2001 From: Riccardo Elitropi Date: Fri, 20 Feb 2026 16:51:40 +0100 Subject: [PATCH] EgtExecutor 3.1b2 : - in Trimming aggiunte funzioni per interpolazione curve di sincronizzazione - in LUA_GENERAL aggiunto il dialogo di tipo Brush/ColorPicker. --- EXE_Trimming.cpp | 70 ++++++++ EgtExecutor.rc | Bin 19652 -> 19652 bytes LUA_General.cpp | 425 +++++++++++++++++++++++++++++++++-------------- Lua_Trimming.cpp | 32 ++++ 4 files changed, 406 insertions(+), 121 deletions(-) diff --git a/EXE_Trimming.cpp b/EXE_Trimming.cpp index 08bbb4b..c6fe70d 100644 --- a/EXE_Trimming.cpp +++ b/EXE_Trimming.cpp @@ -641,6 +641,76 @@ ExeTrimmingGetRuledBezier( int nParentId, const INTVECTOR& vIds, int nEdge1Id, i return nSurfBzId ; } +// --------------------------------------------------------------------------- +bool +ExeTrimmingInterpolateSyncLines( int nParentId, int nSync1Id, int nSync2Id, int nBorder1Id, + int nBorder2Id, double dEdgeLinTol, double dEdgeAngTol, + int& nFirstId, int& nCount) +{ + // Verifica database geometrico + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + + // Reset parametri di ritorno + nFirstId = GDB_ID_NULL ; + nCount = 0 ; + + // Aggiusto la tolleranza lineare e angolare se necessario + double dMyEdgeLinTol = Clamp( dEdgeLinTol, EPS_SMALL, 1e5 * EPS_SMALL) ; + double dMyEdgeAngTol = Clamp( dEdgeAngTol, EPS_ANG_SMALL, 60.) ; + + // recupero le due curve di sincronizzazione + const ICurve* pSync1 = GetCurve( pGeomDB->GetGeoObj( nSync1Id)) ; + const ICurve* pSync2 = GetCurve( pGeomDB->GetGeoObj( nSync2Id)) ; + bool bOk = ( pSync1 != nullptr && pSync1->IsValid() && + pSync2 != nullptr && pSync2->IsValid()) ; + + // Recupero le due curve di bordo + const ICurve* pCrvEdge1 = GetCurve( pGeomDB->GetGeoObj( nBorder1Id)) ; + const ICurve* pCrvEdge2 = GetCurve( pGeomDB->GetGeoObj( nBorder2Id)) ; + bOk = bOk && ( pCrvEdge1 != nullptr && pCrvEdge1->IsValid()) ; + bOk = bOk && ( pCrvEdge2 != nullptr && pCrvEdge2->IsValid()) ; + + // Calcolo le Curve di sincornizzazione Interpolate + BIPNTVECTOR vSyncPoints ; + bOk = bOk && GetTrimmingSyncInterpolation( pCrvEdge1, pCrvEdge2, pSync1, pSync2, dMyEdgeLinTol, + dMyEdgeAngTol, vSyncPoints) ; + if ( bOk && ! vSyncPoints.empty()) { + // Inserisco le curve di sincronizzazione nel DB + // [orientate da pCrvEdge1 a pCrvEdge2] + for ( int i = 0 ; bOk && i < ssize( vSyncPoints) ; ++ i) { + PtrOwner pSyncLine( CreateCurveLine()) ; + bOk = ( ! IsNull( pSyncLine) && pSyncLine->Set( vSyncPoints[i].first, vSyncPoints[i].second)) ; + if ( bOk) { + if ( pCrvEdge1->IsPointOn( vSyncPoints[i].second, dMyEdgeLinTol)) + pSyncLine->Invert() ; + int nSyncId = pGeomDB->AddGeoObj( GDB_ID_NULL, nParentId, Release( pSyncLine)) ; + bOk = ( nSyncId != CMD_ID_NULL) ; + if ( i == 0) + nFirstId = nSyncId ; + } + } + nCount = ssize( vSyncPoints) ; + } + + ExeSetModified() ; + // Se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTrimmingInterpolateSyncLines(" + ToString( nParentId) + "," + + ToString( nSync1Id) + "," + + ToString( nSync2Id) + "," + + ToString( nBorder1Id) + "," + + ToString( nBorder2Id) + "," + + ToString( dEdgeLinTol) + "," + + ToString( dEdgeAngTol) + ")" + + " -- bOk=" + ToString( bOk) + + " -- nFirstId=" + ToString( nFirstId) + " nCount=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + + return bOk ; +} + // --------------------------------------------------------------------------- bool ExeTrimmingGetSurfBzSyncPoints( int nParentId, int nEdge1Id, int nEdge2Id, double dLinTol, diff --git a/EgtExecutor.rc b/EgtExecutor.rc index 2906d677eb77995917016ea791254dc899231ff8..992894ce5496cc20d8e28f06c3afe9d0a068f5f9 100644 GIT binary patch delta 225 zcmX>ylkvz*#trM3)jb*V7}6PX7*ZLEfmne-gCUrqgdq`#Gl9HNpll|HJz3DLb#olc z941Di&A-`PnSqoe*K!sx?>N)s4T4pSMw1=6k~jAW*?>e(i-FY$N+HxVD8kglDRC$f oYw_lZF2#(3`CylMf?bvabW!4FLAQ;}n8K4Mx*Xg*!OMgR0F3ZDZ~y=R delta 252 zcmX>ylkvz*#trM3wOtwV7}6PX7%~}(88R3Y7&I6{fg+g(c))) { + bOk = false; + break ; + } + } + if ( bOk) { + try { + unsigned long hex = stoul( sVal, nullptr, 16) ; + BYTE r = ( hex >> 16) & 0xFF ; + BYTE g = ( hex >> 8) & 0xFF ; + BYTE b = hex & 0xFF ; + g_selectedColor[i] = RGB( r, g, b) ; + } catch (...) {} + } + } + } + + // nascondo qualsiasi tipo di componente ( per sicurezza) + HWND hwndEdit = GetDlgItem( hwndDlg, IDC_EDIT1 + i) ; + if ( hwndEdit) + ShowWindow( hwndEdit, SW_HIDE) ; + HWND hwndCombo = GetDlgItem( hwndDlg, IDC_COMBO1 + i) ; + if ( hwndCombo) + ShowWindow( hwndCombo, SW_HIDE) ; + HWND hwndChk = GetDlgItem( hwndDlg, IDC_CHECK1 + i) ; + if ( hwndChk) + ShowWindow( hwndChk, SW_HIDE) ; + + // margini per dimensione del rettangolo preview pickColor + const int MARGIN_RIGHT = 8 ; // spazio tra preview e bordo destro dialog + const int PREVIEW_HEIGHT = 20 ; // altezza del rettangolo + const int PREVIEW_MIN_WIDTH = 40 ; // larghezza minima + + // ottieni o crea la static preview (allargata fino al bordo destro del dialog) + HWND hwndPreview = GetDlgItem( hwndDlg, IDC_STATIC_PREVIEW + i) ; + RECT rcLabel ; + HWND hwndLabel = GetDlgItem( hwndDlg, IDC_TEXT1 + i) ; + RECT rcClient ; GetClientRect( hwndDlg, &rcClient) ; // coordinate client del dialog + if ( hwndLabel && GetWindowRect( hwndLabel, &rcLabel)) { + // converti rcLabel in coordinate client + POINT ptLabel = { rcLabel.right, rcLabel.top } ; + ScreenToClient( hwndDlg, &ptLabel) ; + int x = ptLabel.x + 8 ; // distanza dal label + int y = ptLabel.y ; + int width = rcClient.right - x - MARGIN_RIGHT ; + if ( width < PREVIEW_MIN_WIDTH) + width = PREVIEW_MIN_WIDTH ; + if ( ! hwndPreview) { + hwndPreview = CreateWindowEx( + 0, L"STATIC", NULL, + WS_CHILD | WS_VISIBLE | SS_NOTIFY | SS_CENTERIMAGE | WS_BORDER, + x, y, width, PREVIEW_HEIGHT, + hwndDlg, ( HMENU)( IDC_STATIC_PREVIEW + i), + GetModuleHandle( NULL), NULL) ; + } + else { + // aggiornamento posizione e dimensione se già esiste + LONG_PTR style = GetWindowLongPtr( hwndPreview, GWL_STYLE) ; + style |= SS_NOTIFY | SS_CENTERIMAGE | WS_BORDER ; + style &= ~SS_OWNERDRAW ; + SetWindowLongPtr( hwndPreview, GWL_STYLE, style) ; + SetWindowPos( hwndPreview, HWND_TOP, x, y, width, PREVIEW_HEIGHT, SWP_SHOWWINDOW | SWP_FRAMECHANGED) ; + } + // pulizia e aggiornamento brush colori + SetWindowText( hwndPreview, L"") ; + if ( g_hColorBrush[i]) { + DeleteObject( g_hColorBrush[i]) ; + g_hColorBrush[i] = NULL ; + } + g_hColorBrush[i] = CreateSolidBrush( g_selectedColor[i]) ; + // ridisegno + InvalidateRect( hwndPreview, NULL, TRUE) ; + UpdateWindow( hwndPreview) ; + } + // pulizia elementi testuali + if ( hwndPreview) + SetWindowText( hwndPreview, L"") ; + if ( g_hColorBrush[i]) { + DeleteObject( g_hColorBrush[i]) ; + g_hColorBrush[i] = NULL ; + } + // creazione brush di colori + g_hColorBrush[i] = CreateSolidBrush( g_selectedColor[i]) ; + if ( hwndPreview) { + SetWindowPos( hwndPreview, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE) ; + InvalidateRect( hwndPreview, NULL, TRUE) ; + UpdateWindow( hwndPreview) ; + } + s_nType[i] = CTRL_COLOR ; + } + else { + SetDlgItemText( hwndDlg, IDC_EDIT1 + i, stringtoW( s_sEdit[i])) ; + ShowWindow( GetDlgItem( hwndDlg, IDC_COMBO1 + i), SW_HIDE) ; + ShowWindow( GetDlgItem( hwndDlg, IDC_CHECK1 + i), SW_HIDE) ; + s_nType[i] = CTRL_EDIT ; } - ComboBox_SetCurSel( hwndCBox, nSel) ; - ShowWindow( GetDlgItem( hwndDlg, IDC_EDIT1 + i), SW_HIDE) ; - ShowWindow( GetDlgItem( hwndDlg, IDC_CHECK1 + i), SW_HIDE) ; - s_nType[i] = CTRL_COMBO ; } else { - SetDlgItemText( hwndDlg, IDC_EDIT1 + i, stringtoW( s_sEdit[i])) ; + ShowWindow( GetDlgItem( hwndDlg, IDC_TEXT1 + i), SW_HIDE) ; + ShowWindow( GetDlgItem( hwndDlg, IDC_EDIT1 + i), SW_HIDE) ; ShowWindow( GetDlgItem( hwndDlg, IDC_COMBO1 + i), SW_HIDE) ; ShowWindow( GetDlgItem( hwndDlg, IDC_CHECK1 + i), SW_HIDE) ; - s_nType[i] = CTRL_EDIT ; + ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_PREVIEW + i), SW_HIDE) ; + s_nType[i] = CTRL_NONE ; } } - else { - ShowWindow( GetDlgItem( hwndDlg, IDC_TEXT1 + i), SW_HIDE) ; - ShowWindow( GetDlgItem( hwndDlg, IDC_EDIT1 + i), SW_HIDE) ; - ShowWindow( GetDlgItem( hwndDlg, IDC_COMBO1 + i), SW_HIDE) ; - ShowWindow( GetDlgItem( hwndDlg, IDC_CHECK1 + i), SW_HIDE) ; - s_nType[i] = CTRL_NONE ; + break ; + case WM_CTLCOLORSTATIC : + { + HDC hdcStatic = ( HDC)wParam ; + HWND hwndCtrl = ( HWND)lParam ; + int ctrlId = GetDlgCtrlID( hwndCtrl) ; + if ( ctrlId >= IDC_STATIC_PREVIEW && ctrlId < IDC_STATIC_PREVIEW + MAX_CTRLS) { + int idx = ctrlId - IDC_STATIC_PREVIEW ; + if ( g_hColorBrush[idx] == NULL) + g_hColorBrush[idx] = CreateSolidBrush( g_selectedColor[idx]) ; + SetBkMode( hdcStatic, OPAQUE) ; + SetBkColor( hdcStatic, g_selectedColor[idx]) ; + return ( INT_PTR)g_hColorBrush[idx] ; + } + } + case WM_COMMAND : { + int id = LOWORD( wParam) ; + int code = HIWORD( wParam) ; + // comando di Preview per brush di colori mediante click del mouse + if ( code == STN_CLICKED && id >= IDC_STATIC_PREVIEW && id < IDC_STATIC_PREVIEW + MAX_CTRLS) { + int idx = id - IDC_STATIC_PREVIEW ; + HWND hwndPreview = GetDlgItem( hwndDlg, IDC_STATIC_PREVIEW + idx) ; + if ( ! hwndPreview) + return TRUE ; + // apertura ChooseColor (usa hwndDlg come owner) + CHOOSECOLOR cc = {} ; + cc.lStructSize = sizeof( cc) ; + cc.hwndOwner = hwndDlg ; + cc.lpCustColors = g_customColors ; + cc.rgbResult = g_selectedColor[idx] ; + cc.Flags = CC_FULLOPEN | CC_RGBINIT ; + if ( ChooseColor( &cc)) { + g_selectedColor[idx] = cc.rgbResult ; + if ( g_hColorBrush[idx]) { + DeleteObject( g_hColorBrush[idx]) ; + g_hColorBrush[idx] = NULL ; + } + g_hColorBrush[idx] = CreateSolidBrush( g_selectedColor[idx]) ; + InvalidateRect(hwndPreview, NULL, TRUE) ; + UpdateWindow( hwndPreview) ; + } + return TRUE ; + } + + switch ( LOWORD( wParam)) { + case IDOK : + for ( int i = 0 ; i < s_nCtrls ; ++ i) { + AtoWEX<128> wsEdit( "") ; + s_sEdit[i] = "" ; + switch ( s_nType[i]) { + case CTRL_CHECK : + s_sEdit[i] = ( IsDlgButtonChecked( hwndDlg, IDC_CHECK1 + i) == BST_CHECKED ? "1" : "0") ; + break ; + case CTRL_COMBO : + if ( GetDlgItemText( hwndDlg, IDC_COMBO1 + i, LPWSTR( wsEdit), 128) > 0) + s_sEdit[i] = wstrztoA( wsEdit) ; + break ; + case CTRL_EDIT : + if ( GetDlgItemText( hwndDlg, IDC_EDIT1 + i, LPWSTR( wsEdit), 128) > 0) + s_sEdit[i] = wstrztoA( wsEdit) ; + break ; + case CTRL_COLOR : + { + COLORREF col = g_selectedColor[i] ; + BYTE r = GetRValue( col), g = GetGValue( col), b = GetBValue( col) ; + char buf[16] ; + sprintf_s( buf, sizeof( buf), "#%02X%02X%02X", r, g, b) ; + s_sEdit[i] = buf ; + break ; + } + } + } + [[fallthrough]] ; + case IDCANCEL : { + // pulizia brush colori + for ( int i = 0 ; i < MAX_CTRLS ; ++ i) { + if ( g_hColorBrush[i]) { + DeleteObject( g_hColorBrush[i]) ; + g_hColorBrush[i] = NULL ; + } + } + EndDialog( hwndDlg, wParam) ; + return TRUE ; + } } } - break ; - case WM_COMMAND : - switch ( LOWORD( wParam)) { - case IDOK : - for ( int i = 0 ; i < s_nCtrls ; ++ i) { - AtoWEX<128> wsEdit( "") ; - s_sEdit[i] = "" ; - switch ( s_nType[i]) { - case CTRL_CHECK : - s_sEdit[i] = ( IsDlgButtonChecked( hwndDlg, IDC_CHECK1 + i) == BST_CHECKED ? "1" : "0") ; - break ; - case CTRL_COMBO : - if ( GetDlgItemText( hwndDlg, IDC_COMBO1 + i, LPWSTR( wsEdit), 128) > 0) - s_sEdit[i] = wstrztoA( wsEdit) ; - break ; - case CTRL_EDIT : - if ( GetDlgItemText( hwndDlg, IDC_EDIT1 + i, LPWSTR( wsEdit), 128) > 0) - s_sEdit[i] = wstrztoA( wsEdit) ; - break ; - } - } - [[fallthrough]] ; - case IDCANCEL : - EndDialog( hwndDlg, wParam) ; - return TRUE ; - } - } - return FALSE ; -} + } + return FALSE ; +} //------------------------------------------------------------------------------- static int diff --git a/Lua_Trimming.cpp b/Lua_Trimming.cpp index 5c1c769..88214e3 100644 --- a/Lua_Trimming.cpp +++ b/Lua_Trimming.cpp @@ -222,6 +222,37 @@ LuaTrimmingGetRuledBezier( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaTrimmingInterpolateSyncLines( lua_State* L) +{ + // 7 parametri : nParentId, nFirstSyncId, nSecondSyncId, nBorder1Id, nBorder2Id, dEdgeLinTol, dEdgeAngTol + int nParentId ; + LuaCheckParam( L, 1, nParentId) ; + int nSync1Id ; + LuaCheckParam( L, 2, nSync1Id) ; + int nSync2Id ; + LuaCheckParam( L, 3, nSync2Id) ; + int nBorder1Id ; + LuaCheckParam( L, 4, nBorder1Id) ; + int nBorder2Id ; + LuaCheckParam( L, 5, nBorder2Id) ; + double dEdgeLinTol ; + LuaCheckParam( L, 6, dEdgeLinTol) ; + double dEdgeAngTol ; + LuaCheckParam( L, 7, dEdgeAngTol) ; + LuaClearStack( L) ; + // Interpolo le curve di sincronizzazione + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + bool bOk = ExeTrimmingInterpolateSyncLines( nParentId, nSync1Id, nSync2Id, nBorder1Id, + nBorder2Id, dEdgeLinTol, dEdgeAngTol, nFirstId, nCount) ; + LuaSetParam( L, bOk) ; + LuaSetParam( L, nFirstId) ; + LuaSetParam( L, nCount) ; + return 3 ; +} + //------------------------------------------------------------------------------- static int LuaTrimmingGetSurfBzSyncPoints( lua_State* L) @@ -269,6 +300,7 @@ LuaInstallTrimming( LuaMgr& luaMgr) // --- Recupero Surf Bezier Ruled bOk = bOk && luaMgr.RegisterFunction( "EgtTrimmingGetRuledBezier", LuaTrimmingGetRuledBezier) ; // --- Recupero linee di sincronizzazione + bOk = bOk && luaMgr.RegisterFunction( "EgtTrimmingInterpolateSyncLines", LuaTrimmingInterpolateSyncLines) ; bOk = bOk && luaMgr.RegisterFunction( "EgtTrimmingGetSurfBzSyncPoints", LuaTrimmingGetSurfBzSyncPoints) ; return bOk ; } \ No newline at end of file