From d0f9dcaf7275c4ec586189a01b7bdbc8fdbd5def Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 30 Oct 2013 16:50:50 +0000 Subject: [PATCH] Merge from BR_hydro 30/10/2013 --- CMakeLists.txt | 13 +- SalomeGEOMConfig.cmake.in | 1 + adm_local/cmake_files/FindGEOM.cmake | 3 +- resources/CMakeLists.txt | 8 + resources/arrow_down.png | Bin 0 -> 703 bytes resources/arrow_up.png | Bin 0 -> 716 bytes resources/closedpolyline.png | Bin 0 -> 430 bytes resources/closedspline.png | Bin 0 -> 472 bytes resources/edit_points.png | Bin 0 -> 408 bytes resources/join2.png | Bin 0 -> 588 bytes resources/new_point.png | Bin 0 -> 622 bytes resources/new_section.png | Bin 0 -> 811 bytes src/BasicGUI/BasicGUI.cxx | 31 +- src/BasicGUI/BasicGUI.h | 3 - src/BasicGUI/CMakeLists.txt | 2 + src/CMakeLists.txt | 2 +- src/CurveCreator/CMakeLists.txt | 116 +++ src/CurveCreator/CurveCreator.hxx | 52 + src/CurveCreator/CurveCreator_Curve.cxx | 53 + src/CurveCreator/CurveCreator_Curve.hxx | 63 ++ src/CurveCreator/CurveCreator_CurveEditor.cxx | 511 ++++++++++ src/CurveCreator/CurveCreator_CurveEditor.hxx | 166 +++ src/CurveCreator/CurveCreator_Diff.cxx | 588 +++++++++++ src/CurveCreator/CurveCreator_Diff.hxx | 218 ++++ src/CurveCreator/CurveCreator_ICurve.cxx | 459 +++++++++ src/CurveCreator/CurveCreator_ICurve.hxx | 189 ++++ src/CurveCreator/CurveCreator_Listener.hxx | 41 + src/CurveCreator/CurveCreator_Macro.hxx | 44 + src/CurveCreator/CurveCreator_NewPointDlg.cxx | 196 ++++ src/CurveCreator/CurveCreator_NewPointDlg.h | 70 ++ .../CurveCreator_NewSectionDlg.cxx | 149 +++ src/CurveCreator/CurveCreator_NewSectionDlg.h | 70 ++ src/CurveCreator/CurveCreator_Operation.cxx | 402 ++++++++ src/CurveCreator/CurveCreator_Operation.hxx | 205 ++++ src/CurveCreator/CurveCreator_Section.hxx | 44 + src/CurveCreator/CurveCreator_TreeView.cxx | 485 +++++++++ src/CurveCreator/CurveCreator_TreeView.h | 96 ++ src/CurveCreator/CurveCreator_UndoOptsDlg.cxx | 237 +++++ src/CurveCreator/CurveCreator_UndoOptsDlg.h | 73 ++ src/CurveCreator/CurveCreator_Widget.cxx | 942 ++++++++++++++++++ src/CurveCreator/CurveCreator_Widget.h | 120 +++ src/EntityGUI/CMakeLists.txt | 2 + src/EntityGUI/EntityGUI.cxx | 35 +- src/EntityGUI/EntityGUI.h | 3 - src/GEOMBase/GEOMBase_Helper.cxx | 2 +- src/GEOMBase/GEOMBase_Helper.h | 1 + src/GEOMGUI/GEOM_images.ts | 56 ++ src/GEOMGUI/GEOM_msg_en.ts | 268 +++++ src/GEOMGUI/GEOM_msg_fr.ts | 268 +++++ src/GEOMGUI/GeometryGUI.cxx | 17 + src/GEOMGUI/GeometryGUI_Operations.h | 4 + src/GEOMUtils/CMakeLists.txt | 1 + src/GEOMUtils/GEOMUtils.cxx | 29 + src/GEOMUtils/GEOMUtils.hxx | 12 + src/OperationGUI/CMakeLists.txt | 9 + src/OperationGUI/OperationGUI.cxx | 39 + 56 files changed, 6330 insertions(+), 68 deletions(-) create mode 100755 resources/arrow_down.png create mode 100755 resources/arrow_up.png create mode 100755 resources/closedpolyline.png create mode 100755 resources/closedspline.png create mode 100644 resources/edit_points.png create mode 100755 resources/join2.png create mode 100755 resources/new_point.png create mode 100755 resources/new_section.png create mode 100644 src/CurveCreator/CMakeLists.txt create mode 100644 src/CurveCreator/CurveCreator.hxx create mode 100644 src/CurveCreator/CurveCreator_Curve.cxx create mode 100644 src/CurveCreator/CurveCreator_Curve.hxx create mode 100644 src/CurveCreator/CurveCreator_CurveEditor.cxx create mode 100644 src/CurveCreator/CurveCreator_CurveEditor.hxx create mode 100644 src/CurveCreator/CurveCreator_Diff.cxx create mode 100644 src/CurveCreator/CurveCreator_Diff.hxx create mode 100644 src/CurveCreator/CurveCreator_ICurve.cxx create mode 100644 src/CurveCreator/CurveCreator_ICurve.hxx create mode 100755 src/CurveCreator/CurveCreator_Listener.hxx create mode 100644 src/CurveCreator/CurveCreator_Macro.hxx create mode 100755 src/CurveCreator/CurveCreator_NewPointDlg.cxx create mode 100755 src/CurveCreator/CurveCreator_NewPointDlg.h create mode 100755 src/CurveCreator/CurveCreator_NewSectionDlg.cxx create mode 100755 src/CurveCreator/CurveCreator_NewSectionDlg.h create mode 100644 src/CurveCreator/CurveCreator_Operation.cxx create mode 100644 src/CurveCreator/CurveCreator_Operation.hxx create mode 100644 src/CurveCreator/CurveCreator_Section.hxx create mode 100755 src/CurveCreator/CurveCreator_TreeView.cxx create mode 100755 src/CurveCreator/CurveCreator_TreeView.h create mode 100644 src/CurveCreator/CurveCreator_UndoOptsDlg.cxx create mode 100644 src/CurveCreator/CurveCreator_UndoOptsDlg.h create mode 100644 src/CurveCreator/CurveCreator_Widget.cxx create mode 100644 src/CurveCreator/CurveCreator_Widget.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b67be8576..9c93cf639 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,16 @@ CMAKE_DEPENDENT_OPTION(SALOME_GEOM_USE_OPENCV "Enable shape recognition from pic "SALOME_BUILD_GUI" OFF) MARK_AS_ADVANCED(SALOME_BUILD_GUI SALOME_GEOM_USE_OPENCV) +# Debug options (!!! FOR DEVELOPERS ONLY !!! TO BE REMOVED LATER !!!) +IF(CMAKE_BUILD_TYPE MATCHES "^Debug$") + OPTION(SALOME_GEOM_DEBUG_CC "Debug curve creator" OFF) + MARK_AS_ADVANCED(SALOME_GEOM_DEBUG_CC) + + IF(SALOME_GEOM_DEBUG_CC) + ADD_DEFINITIONS(-DDEBUG_CURVE_CREATOR) + ENDIF(SALOME_GEOM_DEBUG_CC) +ENDIF() + # Prerequisites # ============= # Find "big" prerequisites first - they reference themselves many others @@ -230,7 +240,8 @@ INCLUDE(CMakePackageConfigHelpers) SET(_${PROJECT_NAME}_exposed_targets GEOMArchimede BREPExport BREPImport BlockFix GEOMbasic GEOMAlgo GEOMClient GEOMImpl GEOMUtils GEOMEngine GEOM_SupervEngine IGESExport IGESImport GEOMSketcher - SalomeIDLGEOM STEPExport STEPImport STLExport ShHealOper XAO AdvancedEngine OCC2VTK VTKExport + SalomeIDLGEOM STEPExport STEPImport STLExport ShHealOper XAO AdvancedEngine OCC2VTK + VTKExport CurveCreator ) IF(SALOME_BUILD_GUI) LIST(APPEND _${PROJECT_NAME}_exposed_targets diff --git a/SalomeGEOMConfig.cmake.in b/SalomeGEOMConfig.cmake.in index bf98b089f..232ca3f8a 100644 --- a/SalomeGEOMConfig.cmake.in +++ b/SalomeGEOMConfig.cmake.in @@ -169,3 +169,4 @@ SET(GEOM_RepairGUI RepairGUI) SET(GEOM_TransformationGUI TransformationGUI) SET(GEOM_ImportExportGUI ImportExportGUI) SET(GEOM_GEOMShapeRec GEOMShapeRec) +SET(GEOM_CurveCreator CurveCreator) diff --git a/adm_local/cmake_files/FindGEOM.cmake b/adm_local/cmake_files/FindGEOM.cmake index 1aa77280a..345ad524f 100644 --- a/adm_local/cmake_files/FindGEOM.cmake +++ b/adm_local/cmake_files/FindGEOM.cmake @@ -65,4 +65,5 @@ FIND_LIBRARY(GEOM_PrimitiveGUI PrimitiveGUI ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_RepairGUI RepairGUI ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_TransformationGUI TransformationGUI ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_ImportExportGUI ImportExportGUI ${GEOM_ROOT_DIR}/lib/salome) -FIND_LIBRARY(GEOM_GEOMShapeRec GEOMShapeRec ${GEOM_ROOT_DIR}/lib/salome) \ No newline at end of file +FIND_LIBRARY(GEOM_GEOMShapeRec GEOMShapeRec ${GEOM_ROOT_DIR}/lib/salome) +FIND_LIBRARY(GEOM_CurveCreator CurveCreator ${GEOM_ROOT_DIR}/lib/salome) diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 4e4074c29..72f3188d6 100755 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -251,6 +251,14 @@ SET( _res_files union_faces.png coordsys.png translation.png + arrow_down.png + arrow_up.png + closedpolyline.png + closedspline.png + edit_points.png + join2.png + new_point.png + new_section.png # ADVANCED_RESOURCES: pipetshape.png tree_pipetshape.png pipetshape_import_icon.png pipetshape_section.png dlg_pipetshape.png dlg_pipetshapechamfer.png dlg_pipetshapefillet.png diff --git a/resources/arrow_down.png b/resources/arrow_down.png new file mode 100755 index 0000000000000000000000000000000000000000..9a3a1cb64573f7ee2a4b8b83571e194284bff2d7 GIT binary patch literal 703 zcmV;w0zmzVP)Px#1ZP1_K>z@;j|==^1poj5AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy32;bRa{vGf6951U69E94oEQKA0w_sDK~y+Ty_CyK8&MR--J3;r ziuh=-CRAg6fTT@g?IaqFc^P9mK4&EALToox{{j)0F4ToBsI&_UK{ry=D2kR)Q8&`k zg5s*tn5cil=egrVtj1u>q7fTwT7*`N1 zkL4#{YPA})qck?<3t1(}mrkd{w#kgO(&q?1E5?jghso@0%-ikwV6DaYs~U_Njfo3W z0}TcPqMQYhvT__3KE?hM4Q6w4u;ljOQ+)#_UUTUIIgZ1b(}h!WH6kT?91=8`n~P0f z3lSaVoCplbyadK3N`*2XQ)lQ#P3sDk#8@&Ms{G z{aB=SOk1tDflIQ}44QRgwaeuK&-3upq4S;|#F~AQIVTmBSkq|mlYn7r1v6*PX1hC9 zBLp(t8*o7oa5+4Ti?{C(r*En3mqx4?72#KxfbV=OmZ^_l?2VE+a@omY38{fV0GC4q z?e9mtwGGkQI&A3m_$`PMaD{-(ZAGxZpzjB9-rI+m*Nd&HDjbU4*dbuZ+ngRO0To5@ zx^!~004R=004l4008;_004mL004C`008P>0026e000+nl3&F}00009 za7bBm000XU000XU0RWnu7ytkQLPXyA~Qb0QJ%7|4~u3qezdh?$!x(h8hutTU~&g#ONvvS z;O|rcJsuByJ|9@mMq}6-yMgsfmytf(kM|Y}es@Ut(%QyHuUe2YKEovblxpuV5C~xV z?le!y#%A~Ufxwj1iEothEv01(s(MB&oul&CsRcu!5OOp3k(r#r#_%xG1LyFOz%+s1 z34B)`TQwLChmnuRk&WHL=Jipm4PL+}Ny1j=e*A3j;P?V9M>QCUL{NB?KXn55E%+D0Mo?!BZ;YA%0000Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i*t_ z4J!vgqRrF*00AyZL_t(I%k7lCO2j}AfWK9=F;|=BEM%K&WNoYh=_GXw)(4AC${^fB z2+`^qNvln)#qtpQdw^|y1BFA2v)MhCC}(n}bYK~F*!gDXhk<|bMM}Bs>a(>DrsCW| zgFgdRoHL(IQE?8SxKxBc}z{In+Z-D2dfW$(T)k$lpgV_c| zz==)KIj@4Wg$5349riO_2AM7g{+kALZyhiM#=xzsmj}lK@BRiAjp!0EzyYubhoi&j z^y11Nv$`q-a0G;zE+6Zv7-YIUudCt?SkOo*{GmQ6kcPw2rT=UDHt}jd29)SHRjDn( zgEP3{pUhX7|*zijsa`~W_Icfg3AHeF!PTkkvc Y3zE`q3YgYUZvX%Q07*qoM6N<$f(6P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FZT01FZU(%pXi00007bV*G`2i*t_ z4K4(v+-NHR00CG@L_t(I%hi;zPQx$|hQD45i@PVxWks#3Y~2u2**jNZU}LNVyhN1; zU_yNf2FA`25>ltILfM;zN;bHzDqDV$&n8|8s_s)K zfyyON?gaX*=CjGXKb~&;HrDx8RTb9S20%k?MnqQD+I!#yI0x2&Pn4wDb=4{PY=Vlx zTHE%(2)G1#3VhlKw{voKQGC2UKdL=E>_|jzt+iJ{5;2;HbW7bCP0XkwIg##V>Q4xb zekqTxI(93nV+h;X|9DL9<>&kwYOM*{G+BGd~E6@}PPZ!4!i_>eT z+V(XY2)NA;{>@<7!2f_*;o_#RMGRpjQ*IYq4W3uaA?1`wS4Q6cA76mKQ+1M{IUxYk8^LbuCU|Tl6t&kcfx7D1MeKeXXY%8 z+1|{~bAj3ZVwG^%_U3pa&&Hw%=2iyx1^wTGFEeE~Br&$lelmeot1+tcD))=XZ|(~$ zkMhpQn;x*<_(6ka(f8`V|5n_7sNZO(Vs(JE)v-)JE=MDB%5tyNy9{O}k>@}E5f#1X zYJS}7ne5Wl8#(3gAHCbn`BPr1G}8O+J;_I*zXGT0vi~!a+Hg`vj)^Tpaf9HBDc|Lm yUJ+cuXs3Fwn8DeW*Wft=+X^;0t?$AgShif7AhTX@;bLI0F?hQAxvXPx#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FZT01FZU(%pXi00007bV*G`2i*t` z4ks?YRtp0F00GQNL_t(I%hi-2j1y51hQA#a8ek14xK@(Ape~`gZgPSe6o|S*AZQkc zIJG%*2?=RJke4+Wf@%;TaEC-zwxoifdYV<#w4yDUMKJGpX@J{GUNTAl-M8P)|99TP zf3-xU{Fko8@E_jmo;b+$b-fWaN%M0^lIEr9n@$6FD?=R&xC0z|zz%Q-yfGbbVtEIs z1BG|*HZTPyrt4K5*MJDvwNCB$(yU;4-l4oMv>k z7yx|yZPSn902l*jtyZfXjYc(K1%x89RMo&`xH9PZnhst)OVa#<#W5fDv!>G`QU<$^ z5s?LOO+=P%#KdD<`HPFlreNl@s&0RNdxWY!0h+2BIW4^{N~@Vq=}ymHc1|;TzasE$ z*MVDm-4lSOO-ST)STSqg_84H;&mI`CNYcD;S~dXswgGPx#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i*t` z2PzS=PhCa5U|?WmWMp7qU|@Ljlk0bf@!{OdJW<_|@u|NU zr~#httNMR#bFVNtdYNF1U$-~^|GF!l_sjqPjO@&x8F-jK|NZoMkHyP#YyPdCrWV~s6MySL2N){^JrAjUw(Z|A0M{mpdW znTh{5I~&`Ze{2HMObmaR7#My(X88Ez1;giG{0xtuu`oP7wzo38>rDsIfw|%2f2M1@ z%QpSF!SMg@S%!cAPc!^Kx;Xvlj$@w%$chwuwRiC%Y$trrpY>nz`lckq%`29DiaaND zEoIJ0#bi(UPqKmkZ_S=}^Jm6N)98({KbbWd|MTg#e-JG${CxlTRj3jP1_lNmf?>$O zz`*eCWE-Q9c@^9h&-NAmfBxdFVE<9G_fYF#N*R_+&0!=taXvmd_y2(v4FXUXsX)D4 z&cMJB!oa|wg3qNa*aT(GlNph`se;62U|?YQf`qYq84uur8f3u0z@W^)z;Ks=f#CuJ z1H%hk1~L;c@D~FE!#gPbn}LDh8Uq8v9Vnk7z(Z^-kAgu60GyV%4cXfp{Qv*}07*qo IM6N<$f-DIqXaE2J literal 0 HcmV?d00001 diff --git a/resources/new_section.png b/resources/new_section.png new file mode 100755 index 0000000000000000000000000000000000000000..7e89df72397b6718ecf018feef82f96bc99eb753 GIT binary patch literal 811 zcmV+`1JwM9P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FZT01FZU(%pXi00007bV*G`2i*t` z2P*-#<3ia000OH?L_t(I%dM1cNK;W5$N%^2MQyLSFhyEWen<&ic11J4nfb+#ii!li zLMnZ+SPObX&~IYsKJ3bi9I_fJ6`G=FCOLER`EaL|I`A%}(oPbxq8hNY3Q+0x?ew%l|$B(aHU^rzx^xnbtrrBQXEfLpE; zh=zw>EPfID57d^=^TB|W7Eq*AEiR4ZsC0BFZnTW%6dCG`))Lh3&&J5}Fq&K29}QgY zVoNp~v(o`GKYdppisXF_F^O4fbqLwHg+Pn|VgTQldHh&4ArMp}F#Yu0k={^G+8#de zP;&cbCyl)Ujn6@%v!M5!jUTGpu22BG0q8RFaMtUN*KV1>efOTJmA3_$@swY$u)f-` z?bld4%Q>e2O*c65d}o<7;tS~(ye$xpXS5JD)+IjLHs zp{Dhgn&7yd&J8u2Wm(5^{S?4K09#YlC+Bp85USN?T`(BU4FS&$`ut9pS)rG*oRb15 zP1TGH)v4vYUXr91N+}zU$5u8~9LoprO;Hy~oRh~E5`rX2df%WUB1uvU02@&h_=!q2 zuhC{LDFBJ!6+R|kj=rp^4*+ZcivAe8pwMcyu~m5~tX^|$IadeZ41hYK(1gAF4t=(j zR|zSA5di4z?Qf{uRc&5F^8@gcwO&sOAn$eAtM9&Mx@SDoUlZMVUG^f`1|9&P42&ub zPYMA5?;CWWtf>!#5bAZ=m7ekd1SZ2@P6xn72$_;3>8w0vM27hR2&xQ$A^ +#include "GeometryGUI.h" #include "GeometryGUI_Operations.h" +#include "GEOMUtils.hxx" #include #include @@ -155,7 +156,7 @@ bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin } else { OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); - aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); } aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog @@ -165,32 +166,6 @@ bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin } -//======================================================================= -// function : ConvertClickToPoint() -// purpose : Returns the point clicked in 3D view -//======================================================================= -gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) -{ - V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; - aView->Eye( XEye, YEye, ZEye ); - - aView->At( XAt, YAt, ZAt ); - gp_Pnt EyePoint( XEye, YEye, ZEye ); - gp_Pnt AtPoint( XAt, YAt, ZAt ); - - gp_Vec EyeVector( EyePoint, AtPoint ); - gp_Dir EyeDir( EyeVector ); - - gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir ); - Standard_Real X, Y, Z; - aView->Convert( x, y, X, Y, Z ); - gp_Pnt ConvertedPoint( X, Y, Z ); - - gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint ); - gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView ); - return ResultPoint; -} - //===================================================================================== // EXPORTED METHODS //===================================================================================== diff --git a/src/BasicGUI/BasicGUI.h b/src/BasicGUI/BasicGUI.h index aa4efc994..dd120db2a 100644 --- a/src/BasicGUI/BasicGUI.h +++ b/src/BasicGUI/BasicGUI.h @@ -28,7 +28,6 @@ #define BASICGUI_H #include -#include //================================================================================= // class : BasicGUI @@ -42,8 +41,6 @@ public: bool OnGUIEvent( int, SUIT_Desktop* ); bool OnMousePress( QMouseEvent*, SUIT_Desktop*, SUIT_ViewWindow* ); - - gp_Pnt ConvertClickToPoint( int, int, Handle(V3d_View) ); }; #endif // BASICGUI_H diff --git a/src/BasicGUI/CMakeLists.txt b/src/BasicGUI/CMakeLists.txt index d36777d4a..f8fbb5b9d 100755 --- a/src/BasicGUI/CMakeLists.txt +++ b/src/BasicGUI/CMakeLists.txt @@ -34,6 +34,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src/OBJECT ${PROJECT_SOURCE_DIR}/src/GEOMClient + ${PROJECT_SOURCE_DIR}/src/GEOMUtils ${PROJECT_SOURCE_DIR}/src/GEOMImpl ${PROJECT_SOURCE_DIR}/src/GEOMGUI ${PROJECT_SOURCE_DIR}/src/GEOMBase @@ -53,6 +54,7 @@ ADD_DEFINITIONS( SET(_link_LIBRARIES GEOMObject GEOMClient + GEOMUtils GEOMImpl GEOM GEOMBase diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 171f771e6..1e808f43c 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,7 +45,7 @@ IF(SALOME_BUILD_GUI) GEOMBase GEOMToolsGUI DisplayGUI BasicGUI PrimitiveGUI GenerationGUI EntityGUI BuildGUI BooleanGUI TransformationGUI OperationGUI RepairGUI MeasureGUI GroupGUI BlocksGUI AdvancedGUI ImportExportGUI - GEOM_SWIG_WITHIHM + CurveCreator GEOM_SWIG_WITHIHM ) ENDIF() diff --git a/src/CurveCreator/CMakeLists.txt b/src/CurveCreator/CMakeLists.txt new file mode 100644 index 000000000..d11021f4d --- /dev/null +++ b/src/CurveCreator/CMakeLists.txt @@ -0,0 +1,116 @@ +# Copyright (C) 2012-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +INCLUDE(${QT_USE_FILE}) + +# --- options --- + +# additional include directories +INCLUDE_DIRECTORIES( + ${QT_INCLUDE_DIRS} + ${PTHREAD_INCLUDE_DIR} + ${CAS_INCLUDE_DIRS} + ${KERNEL_INCLUDE_DIRS} + ${GUI_INCLUDE_DIRS} + ${PROJECT_SOURCE_DIR}/src/GEOMUtils +) + +# additional preprocessor / compiler flags +ADD_DEFINITIONS( + ${CAS_DEFINITIONS} + ${QT_DEFINITIONS} +) + +# libraries to link to +SET(_link_LIBRARIES + GEOMUtils +) + +IF(SALOME_BUILD_GUI) + LIST(APPEND _link_LIBRARIES + ${GUI_qtx} + ${GUI_suit} + ) +ENDIF(SALOME_BUILD_GUI) + +# --- headers --- + +IF(SALOME_BUILD_GUI) + # header files / to be processed by moc + SET(_moc_HEADERS + CurveCreator_NewSectionDlg.h + CurveCreator_NewPointDlg.h + CurveCreator_TreeView.h +# CurveCreator_UndoOptsDlg.h + CurveCreator_Widget.h + ) +ENDIF(SALOME_BUILD_GUI) + +# header files / no processing +SET(_other_HEADERS + CurveCreator.hxx + CurveCreator_Curve.hxx + CurveCreator_CurveEditor.hxx + CurveCreator_Diff.hxx + CurveCreator_ICurve.hxx + CurveCreator_Listener.hxx + CurveCreator_Macro.hxx + CurveCreator_Operation.hxx + CurveCreator_Section.hxx +) + +# header files / to install +SET(CurveCreator_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) + +# --- sources --- + +IF(SALOME_BUILD_GUI) + # sources / moc wrappings + QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) +ENDIF(SALOME_BUILD_GUI) + +# sources / static +SET(_other_SOURCES + CurveCreator_Curve.cxx + CurveCreator_CurveEditor.cxx + CurveCreator_Diff.cxx + CurveCreator_ICurve.cxx + CurveCreator_Operation.cxx +) +IF(SALOME_BUILD_GUI) + LIST(APPEND _other_SOURCES + CurveCreator_NewPointDlg.cxx + CurveCreator_NewSectionDlg.cxx + CurveCreator_TreeView.cxx +# CurveCreator_UndoOptsDlg.cxx + CurveCreator_Widget.cxx + ) +ENDIF(SALOME_BUILD_GUI) + +# sources / to compile +SET(CurveCreator_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) + +# --- rules --- + +ADD_LIBRARY(CurveCreator ${CurveCreator_SOURCES}) +TARGET_LINK_LIBRARIES(CurveCreator ${_link_LIBRARIES}) +INSTALL(TARGETS CurveCreator EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) + +INSTALL(FILES ${CurveCreator_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) + diff --git a/src/CurveCreator/CurveCreator.hxx b/src/CurveCreator/CurveCreator.hxx new file mode 100644 index 000000000..ce574a05a --- /dev/null +++ b/src/CurveCreator/CurveCreator.hxx @@ -0,0 +1,52 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_HeaderFile +#define _CurveCreator_HeaderFile + +#include + +namespace CurveCreator +{ + + //! Dimension of the curve + enum Dimension + { + Dim2d = 2, + Dim3d = 3 + }; + + //! Type of the section + enum Type + { + Polyline, + BSpline + }; + + //! Points coordinates + typedef float TypeCoord; + + typedef std::deque Coordinates; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_Curve.cxx b/src/CurveCreator/CurveCreator_Curve.cxx new file mode 100644 index 000000000..0d2a4e405 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Curve.cxx @@ -0,0 +1,53 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Curve.cxx +// Author: Sergey KHROMOV + +#include "CurveCreator_Curve.hxx" +#include "CurveCreator_Section.hxx" +#include "CurveCreator_Listener.hxx" + +#include + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_Curve::CurveCreator_Curve + (const CurveCreator::Dimension theDimension) +: CurveCreator_ICurve(theDimension) +{ +} + +//======================================================================= +// function: addPoints +// purpose: +//======================================================================= +void CurveCreator_Curve::addPoints + (const CurveCreator::Coordinates &thePoints, const int theISection) +{ + CurveCreator_Section *aSection = + (theISection == -1 ? mySections.back() : mySections.at(theISection)); + + aSection->myPoints.insert(aSection->myPoints.end(), + thePoints.begin(), thePoints.end()); + if( myListener ) + myListener->pointInserted( theISection, -1 ); +} diff --git a/src/CurveCreator/CurveCreator_Curve.hxx b/src/CurveCreator/CurveCreator_Curve.hxx new file mode 100644 index 000000000..36eeab826 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Curve.hxx @@ -0,0 +1,63 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Curve.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Curve_HeaderFile +#define _CurveCreator_Curve_HeaderFile + +#include "CurveCreator.hxx" +#include "CurveCreator_ICurve.hxx" +#include "CurveCreator_Macro.hxx" +#include "CurveCreator_Operation.hxx" + +#include + +class CurveCreator_Section; +class CurveCreator_Listener; + +/** + * The CurveCreator_Curve object is represented as one or more sets of + * connected points; thus CurveCreator_Curve object can contain several + * not connected curves (polylines or b-splines), each such curve has two + * only ends � start and end points � in other words non-manifold curves + * are not supported. + */ +class CURVECREATOR_EXPORT CurveCreator_Curve : public CurveCreator_ICurve +{ +public: + //! Constructor of the curve. + /** The dimension is explicitly specified in the constructor + * and cannot be changed later. + */ + CurveCreator_Curve(const CurveCreator::Dimension theDimension); + + /** Add points to the specified section (or last section + * if \a theISection is -1). + */ + virtual void addPoints + (const CurveCreator::Coordinates &thePoints, const int theISection = -1); + + friend class CurveCreator_CurveEditor; + friend class CurveCreator_Operation; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_CurveEditor.cxx b/src/CurveCreator/CurveCreator_CurveEditor.cxx new file mode 100644 index 000000000..b52930884 --- /dev/null +++ b/src/CurveCreator/CurveCreator_CurveEditor.cxx @@ -0,0 +1,511 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_CurveEditor.cxx +// Author: Sergey KHROMOV + +#include "CurveCreator_CurveEditor.hxx" + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_CurveEditor::CurveCreator_CurveEditor + (CurveCreator_Curve* thePCurve) + : myNbUndos (0), + myNbRedos (0), + myPCurve (thePCurve), + myUndoDepth (-1), + myOpLevel(0) +{ + if (myPCurve != NULL) { + if (myPCurve->isLocked()) { + // This curve is locked by another editor. Invalid case. + myPCurve = NULL; + } else { + // Lock the curve. + myPCurve->myIsLocked = true; + myCurrenPos = myListDiffs.end(); + } + } +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_CurveEditor::~CurveCreator_CurveEditor() +{ + if (myPCurve != NULL) { + // Unlock the curve. + myPCurve->myIsLocked = false; + } +} + +//======================================================================= +// function: getCurve +// purpose: +//======================================================================= +CurveCreator_Curve *CurveCreator_CurveEditor::getCurve() const +{ + return myPCurve; +} + +//======================================================================= +// function: isAttached +// purpose: +//======================================================================= +bool CurveCreator_CurveEditor::isAttached() const +{ + return (myPCurve != NULL); +} + +//======================================================================= +// function: undo +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::undo() +{ + if (myNbUndos > 0) { + myNbUndos--; + myNbRedos++; + myCurrenPos--; + myCurrenPos->applyUndo(myPCurve); + } +} + +//======================================================================= +// function: redo +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::redo() +{ + if (myNbRedos > 0) { + myCurrenPos->applyRedo(myPCurve); + myCurrenPos++; + myNbRedos--; + myNbUndos++; + } +} + +//======================================================================= +// function: getNbUndo +// purpose: +//======================================================================= +int CurveCreator_CurveEditor::getNbUndo() const +{ + return myNbUndos; +} + +//======================================================================= +// function: getNbRedo +// purpose: +//======================================================================= +int CurveCreator_CurveEditor::getNbRedo() const +{ + return myNbRedos; +} + +//======================================================================= +// function: setUndoDepth +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::setUndoDepth(const int theDepth) +{ + if (theDepth == 0) { + // Reset all undo/redo data. + myNbUndos = 0; + myNbRedos = 0; + myListDiffs.clear(); + myCurrenPos = myListDiffs.end(); + myUndoDepth = 0; + } else if (theDepth == -1) { + // There is nothing to do as the depth become unlimited. + myUndoDepth = -1; + } else if (theDepth > 0) { + // The new "real" depth is set. + if (theDepth < myNbRedos) { + // The new depth is less then number of redos. Remove the latest redos. + int aShift = (myNbRedos - theDepth); + ListDiff::iterator aFromPos = myListDiffs.end(); + + while (aShift--) { + aFromPos--; + } + + myListDiffs.erase(aFromPos, myListDiffs.end()); + myNbRedos = theDepth; + } + + if (theDepth < myNbUndos + myNbRedos) { + // The new depth is less then the total number of differences. + // Remove the first undos. + int aShift = (myNbUndos + myNbRedos - theDepth); + ListDiff::iterator aToPos = myListDiffs.begin(); + + while (aShift--) { + aToPos++; + } + + myListDiffs.erase(myListDiffs.begin(), aToPos); + myNbUndos = theDepth - myNbRedos; + } + + myUndoDepth = theDepth; + } +} + +//======================================================================= +// function: getUndoDepth +// purpose: +//======================================================================= +int CurveCreator_CurveEditor::getUndoDepth() const +{ + return myUndoDepth; +} + +//======================================================================= +// function: setType +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::setType(const CurveCreator::Type theType, + const int theISection) +{ + if (myPCurve != NULL) { + startOperation(); + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::SetType, + theType, theISection); + } + + // Update the curve. + myPCurve->setType(theType, theISection); + finishOperation(); + } +} + +//======================================================================= +// function: addPoints +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::addPoints + (const CurveCreator::Coordinates &thePoints, + const int theISection) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::AddPoints, + thePoints, theISection); + } + + // Update the curve. + myPCurve->addPoints(thePoints, theISection); + finishOperation(); + } +} + +//======================================================================= +// function: addSection +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::addSection + (const std::string& theName, const CurveCreator::Type theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::AddSection, + theName, thePoints, theType, theIsClosed); + } + + // Update the curve. + myPCurve->addSection(theName, theType, theIsClosed, thePoints); + finishOperation(); + } +} + +//======================================================================= +// function: removeSection +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::removeSection(const int theISection) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::RemoveSection, + theISection); + } + + // Update the curve. + myPCurve->removeSection(theISection); + finishOperation(); + } +} + +//======================================================================= +// function: insertPoints +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::insertPoints + (const CurveCreator::Coordinates &thePoints, + const int theISection, + const int theIPnt) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::InsertPoints, + thePoints, theISection, theIPnt); + } + + // Update the curve. + myPCurve->insertPoints(thePoints, theISection, theIPnt); + finishOperation(); + } +} + +//======================================================================= +// function: movePoints +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::movePoint(const int theISection, + const int theOrigIPnt, + const int theNewIPnt ) +{ + startOperation(); + myPCurve->movePoint(theISection, theOrigIPnt, theNewIPnt); + finishOperation(); +} + +//======================================================================= +// function: removePoints +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::removePoints + (const int theISection, + const int theIPnt, + const int theNbPoints) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::RemovePoints, + theISection, theIPnt, theNbPoints); + } + + // Update the curve. + myPCurve->removePoints(theISection, theIPnt, theNbPoints); + finishOperation(); + } +} + +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::clear() +{ + if (myPCurve != NULL) { + startOperation(); + // Set the difference. + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::Clear); + } + + // Update the curve. + myPCurve->clear(); + finishOperation(); + } +} + +//======================================================================= +// function: setCoordinates +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::setCoordinates + (const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::SetCoordinates, + theCoords, theISection, theIPnt); + } + + // Update the curve. + myPCurve->setCoordinates(theCoords, theISection, theIPnt); + finishOperation(); + } +} + +//======================================================================= +// function: setClosed +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::setClosed(const bool theIsClosed, + const int theISection) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::SetClosed, + theIsClosed, theISection); + } + + // Update the curve. + myPCurve->setClosed(theIsClosed, theISection); + finishOperation(); + } +} + +//======================================================================= +// function: setName +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::setName(const std::string& theName, + const int theISection) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::RenameSection, + theName, theISection); + } + myPCurve->setName( theName, theISection ); + finishOperation(); + } +} + +//======================================================================= +// function: moveSection +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::moveSection(const int theISection, + const int theNewIndex) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::MoveSection, + theISection, theNewIndex); + } + + // Update the curve. + myPCurve->moveSection(theISection, theNewIndex); + finishOperation(); + } +} + +//======================================================================= +// function: join +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::join(const int theISectionTo, + const int theISectionFrom) +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::Join, + theISectionTo, theISectionFrom); + } + + // Update the curve. + myPCurve->join(theISectionTo, theISectionFrom); + finishOperation(); + } +} + +//======================================================================= +// function: join +// purpose: +//======================================================================= +void CurveCreator_CurveEditor::join() +{ + if (myPCurve != NULL) { + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(myPCurve, CurveCreator_Operation::Join); + } + + // Update the curve. + myPCurve->join(); + finishOperation(); + } +} + +//======================================================================= +// function: addDiff +// purpose: +//======================================================================= +bool CurveCreator_CurveEditor::addEmptyDiff() +{ + bool isEnabled = false; + + if (myUndoDepth != 0) { + // Forget all Redos after the current one. + if (myNbRedos > 0) { + myNbRedos = 0; + myListDiffs.erase(myCurrenPos, myListDiffs.end()); + } + + if (myUndoDepth == -1 || myNbUndos < myUndoDepth) { + // Increase the number of undos. + myNbUndos++; + } else { + // If there are too many differences, remove the first one. + myListDiffs.pop_front(); + } + + // Add new difference. + myListDiffs.push_back(CurveCreator_Diff()); + myCurrenPos = myListDiffs.end(); + isEnabled = true; + } + + return isEnabled; +} + +void CurveCreator_CurveEditor::startOperation() +{ + myOpLevel++; +} + +void CurveCreator_CurveEditor::finishOperation() +{ + myOpLevel--; +} diff --git a/src/CurveCreator/CurveCreator_CurveEditor.hxx b/src/CurveCreator/CurveCreator_CurveEditor.hxx new file mode 100644 index 000000000..326c19821 --- /dev/null +++ b/src/CurveCreator/CurveCreator_CurveEditor.hxx @@ -0,0 +1,166 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_CurveEditor.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_CurveEditor_HeaderFile +#define _CurveCreator_CurveEditor_HeaderFile + +#include "CurveCreator_Diff.hxx" +#include "CurveCreator_Curve.hxx" + +#include + +/** + * The CurveCreator_CurveEditor is designed to manage of + * editing operations of CurveCreator_Curve class. + */ +class CURVECREATOR_EXPORT CurveCreator_CurveEditor +{ + +private: + + typedef std::list ListDiff; + +public: + + //! Constuctor, initialized by the curve object + CurveCreator_CurveEditor(CurveCreator_Curve* thePCurve); + + //! Destructor, detaches from the Curve + ~CurveCreator_CurveEditor(); + + //! Returns the curve. + CurveCreator_Curve *getCurve() const; + + //! This method returns true if this editor is attached to a valid curve. + bool isAttached() const; + + //! Undo previous operation + void undo(); + + //! Redo last previously �undoed� operation + void redo(); + + //! Get number of available undo operations + int getNbUndo() const; + + //! Get number of available redo operations + int getNbRedo() const; + + //! Set depth of undo operations (unlimited if \a theDepth is -1 + // or disabled if \a theDepth is 0) + void setUndoDepth(const int theDepth = -1); + + //! Get depth of undo operations. + int getUndoDepth() const; + + /** Set type of the specified section (or all sections + * if \a theISection is -1). + */ + void setType(const CurveCreator::Type theType, const int theISection = -1); + + /** Set section closed (or all sections + * if \a theISection is -1). + */ + void setClosed(const bool theIsClosed, const int theISection); + + /** Set section name (if theISection is invalid it is ignored). + */ + void setName(const std::string& theName, const int theISection); + + /** Add points to the specified section (or last section + * if \a theISection is -1). + */ + void addPoints(const CurveCreator::Coordinates &thePoints, + const int theISection = -1); + + //! Add a new section. + void addSection(const std::string &theName, const CurveCreator::Type theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints); + + //! Removes the section. If theISection equals -1, removes the last section. + void removeSection(const int theISection = -1); + + /** Insert points in the given position (add to the end of list + * if \a theIPnt parameter is -1) of the specified section + * (or last section if \a theISection parameter is -1). + */ + void insertPoints(const CurveCreator::Coordinates &thePoints, + const int theISection = -1, + const int theIPnt = -1); + + /** Remove \a nbPoints points from given \a theISection, + * starting from given \a theIPnt (of all points up to the end of + * section if \a theNbPoints is -1). + */ + void removePoints(const int theISection, + const int theIPnt, + const int theNbPoints = -1); + + /** Mobe point in \a theISection from given position \a theOrigIPnt + * to new position \a theNewIPnt. + */ + void movePoint(const int theISection, + const int theOrigIPnt, + const int theNewIPnt ); + + //! Remove all sections. + void clear(); + + //! Set coordinates of specified point + void setCoordinates(const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt); + + /** Move specified \a theISection to the specified position + * in the sections list. + */ + void moveSection(const int theISection, const int theNewIndex); + + //! Join two sections to one section + void join(const int theISectionTo, const int theISectionFrom); + + //! Join all sections to the single curve + void join(); + + void startOperation(); + void finishOperation(); +private: + + /** This method updates all undo/redo information required to be updated + * after curve modification operation. It returns false if undo/redo + * is disabled and true otherwise. + */ + bool addEmptyDiff(); + +private: + + int myNbUndos; + int myNbRedos; + ListDiff::iterator myCurrenPos; + ListDiff myListDiffs; + CurveCreator_Curve* myPCurve; + int myUndoDepth; + int myOpLevel; +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_Diff.cxx b/src/CurveCreator/CurveCreator_Diff.cxx new file mode 100644 index 000000000..e69e51bbd --- /dev/null +++ b/src/CurveCreator/CurveCreator_Diff.cxx @@ -0,0 +1,588 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Diff.cxx +// Author: Sergey KHROMOV + +#include "CurveCreator_Diff.hxx" +#include "CurveCreator_Curve.hxx" + +#include + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_Diff::CurveCreator_Diff() +: myNbUndos (0), + myPUndo (NULL), + myPRedo (NULL) +{ +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_Diff::~CurveCreator_Diff() +{ + clear(); +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType)) { + isOK = true; + + const int aNbSections = theCurve->getNbSections(); + + if (theType == CurveCreator_Operation::Clear) { + // Construct undo for Clear command. + if (aNbSections > 0) { + setNbUndos(aNbSections); + + for (int i = 0; i < aNbSections && isOK; i++) { + // Add AddSection command. + isOK = addSectionToUndo(theCurve, i, myPUndo[i]); + } + } + } else { // theType == CurveCreator_Operation::Join + // Construct undo for Join command. + if (aNbSections > 1) { + // Add the RemovePoints command to remove points of + // the second section fron the first one. + const int aNbPoints = theCurve->getNbPoints(0); + + setNbUndos(aNbSections); + isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, + 0, aNbPoints, -1); + + for (int i = 1; i < aNbSections && isOK; i++) { + // Add AddSection command. + isOK = addSectionToUndo(theCurve, i, myPUndo[i]); + } + } + } + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theIntParam)) { + // Construct undo for RemoveSection command. + // If the last section is removed, one AddSection command is enough. + // If not last section is removed, two commands are requred: AddSection + // and MoveSection. + const int aLastIndex = theCurve->getNbSections() - 1; + + if (theIntParam == aLastIndex) { + setNbUndos(1); + } else { + setNbUndos(2); + } + + isOK = addSectionToUndo(theCurve, theIntParam, myPUndo[0]); + + if (isOK && theIntParam != aLastIndex) { + isOK = myPUndo[1].init(CurveCreator_Operation::MoveSection, + aLastIndex, theIntParam); + } + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theIntParam1, theIntParam2)) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::SetType: + case CurveCreator_Operation::SetClosed: + isOK = setTypeOrClosedToUndo + (theCurve, theType, theIntParam1, theIntParam2); + break; + case CurveCreator_Operation::MoveSection: + setNbUndos(1); + isOK = myPUndo[0].init(theType, theIntParam2, theIntParam1); + break; + case CurveCreator_Operation::Join: + { + // If the last section is removed, one AddSection command is + // enough. If not last section is removed, two commands are + // requred: AddSection and MoveSection. + const int aLastIndex = theCurve->getNbSections() - 1; + const int aNbPoints = theCurve->getNbPoints(theIntParam1); + + if (theIntParam2 == aLastIndex) { + setNbUndos(2); + } else { + setNbUndos(3); + } + + isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, + theIntParam1, aNbPoints, -1); + + if (isOK) { + isOK = addSectionToUndo(theCurve, theIntParam2, myPUndo[1]); + + if (isOK && theIntParam2 != aLastIndex) { + isOK = myPUndo[2].init(CurveCreator_Operation::MoveSection, + aLastIndex, theIntParam2); + } + } + } + break; + default: + break; + } + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2, + const int theIntParam3) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theIntParam1, theIntParam2, theIntParam3)) { + // Construct undo for RemovePoints command. + const CurveCreator::Dimension aDim = theCurve->getDimension(); + const CurveCreator::Coordinates &aPoints = + theCurve->getPoints(theIntParam1); + CurveCreator::Coordinates::const_iterator anIterBegin = + aPoints.begin() + (aDim*theIntParam2); + CurveCreator::Coordinates::const_iterator anIterEnd; + + if (theIntParam3 == -1) { + anIterEnd = aPoints.end(); + } else { + anIterEnd = anIterBegin + (aDim*theIntParam3); + } + + CurveCreator::Coordinates aPointsToAdd; + + setNbUndos(1); + aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd); + isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints, + aPointsToAdd, theIntParam1, theIntParam2); + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theCoords, theIntParam)) { + // Construct undo for AddPoints command. + const int aSectionInd = getSectionIndex(theCurve, theIntParam); + const CurveCreator::Dimension aDim = theCurve->getDimension(); + const CurveCreator::Coordinates &aPoints = + theCurve->getPoints(aSectionInd); + const int aNbPoints = (aPoints.size()/aDim); + + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, + aSectionInd, aNbPoints, -1); + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const std::string& theName, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theName, theCoords, theIntParam1, theIntParam2)) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::AddSection: + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RemoveSection, -1); + break; + } + } + } + if( !isOK ) + clear(); + return isOK; +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theCurve != NULL) { + clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theCoords, theIntParam1, theIntParam2)) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::InsertPoints: + { + const CurveCreator::Dimension aDim = theCurve->getDimension(); + const int aNbPoints = (theCoords.size()/aDim); + const int aSectionInd = getSectionIndex(theCurve, theIntParam1); + int aPointInd; + + if (theIntParam2 == -1) { + aPointInd = theCurve->getNbPoints(aSectionInd); + } else { + aPointInd = theIntParam2; + } + + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, + aSectionInd, aPointInd, aNbPoints); + } + break; + case CurveCreator_Operation::SetCoordinates: + { + const CurveCreator::Coordinates anOldCoords = + theCurve->getCoordinates(theIntParam1, theIntParam2); + + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates, + anOldCoords, theIntParam1, theIntParam2); + } + break; + default: + break; + } + } + + if (!isOK) { + clear(); + } + } + + return isOK; +} + +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const std::string &theName, + const int theIntParam1 ) +{ + bool isOK = false; + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theName, theIntParam1 )) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::RenameSection: + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RenameSection, + theCurve->getSectionName(theIntParam1), theIntParam1); + break; + } + } + if( !isOK ){ + clear(); + } + return isOK; +} + +//======================================================================= +// function: applyUndo +// purpose: +//======================================================================= +void CurveCreator_Diff::applyUndo(CurveCreator_Curve *theCurve) +{ + if (myNbUndos > 0 && myPUndo != NULL) { + for (int i = 0; i < myNbUndos; i++) { + myPUndo[i].apply(theCurve); + } + } +} + +//======================================================================= +// function: applyRedo +// purpose: +//======================================================================= +void CurveCreator_Diff::applyRedo(CurveCreator_Curve *theCurve) +{ + if (myPRedo != NULL) { + myPRedo->apply(theCurve); + } +} + +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_Diff::clear() +{ + if (myPUndo != NULL) { + delete [] myPUndo; + myPUndo = NULL; + } + + myNbUndos = 0; + + if (myPRedo != NULL) { + delete myPRedo; + myPRedo = NULL; + } +} + +//======================================================================= +// function: setNbUndos +// purpose: +//======================================================================= +void CurveCreator_Diff::setNbUndos(const int theNbUndos) +{ + myNbUndos = theNbUndos; + myPUndo = new CurveCreator_Operation[myNbUndos]; +} + +//======================================================================= +// function: getSectionIndex +// purpose: +//======================================================================= +int CurveCreator_Diff::getSectionIndex(const CurveCreator_Curve *theCurve, + const int theIndex) const +{ + return (theIndex == -1 ? theCurve->getNbSections() - 1 : theIndex); +} + +//======================================================================= +// function: addSectionToUndo +// purpose: +//======================================================================= +bool CurveCreator_Diff::addSectionToUndo + (const CurveCreator_Curve *theCurve, + const int theIndex, + CurveCreator_Operation &theOperation) const +{ + const CurveCreator::Coordinates &aPnts = theCurve->getPoints(theIndex); + const CurveCreator::Type aType = theCurve->getType(theIndex); + const bool isClosed = theCurve->isClosed(theIndex); + + bool isOK = theOperation.init(CurveCreator_Operation::AddSection, + aPnts, aType, isClosed); + + return isOK; +} + +//======================================================================= +// function: setTypeOrClosedToUndo +// purpose: +//======================================================================= +bool CurveCreator_Diff::setTypeOrClosedToUndo + (const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = true; + + // Compute number of modified sections. + const bool isSetType = (theType == CurveCreator_Operation::SetType); + int aNbModif = 0; + std::list aListOfInd; + int aValue; + int i; + + if (theIntParam2 == -1) { + // The operation is applied to all sections. We need to collect + // really modified sections for undo. + const int aNbSections = theCurve->getNbSections(); + + if (aNbSections > 0) { + // Get sections to be modified. + for (i = 0; i < aNbSections; i++) { + if (isSetType) { + aValue = theCurve->getType(i); + } else { + aValue = theCurve->isClosed(i); + } + + if (theIntParam1 != aValue) { + aNbModif++; + aListOfInd.push_back(i); + } + } + + if (aNbSections == aNbModif) { + // All sections are modified. We can use one single command + // with -1 section index. + aNbModif = 1; + aListOfInd.clear(); + aListOfInd.push_back(-1); + } + } + } else { + // There is only particular section modified. + // Check if there is a real modification required. + if (isSetType) { + aValue = theCurve->getType(theIntParam2); + } else { + aValue = theCurve->isClosed(theIntParam2); + } + + if (theIntParam1 != aValue) { + aNbModif = 1; + aListOfInd.push_back(theIntParam2); + } + } + + if (aNbModif > 0) { + // Store the undos + std::list::iterator anIter = aListOfInd.begin(); + + if (isSetType) { + aValue = theCurve->getType(*anIter); + } else { + aValue = theCurve->isClosed(*anIter); + } + + setNbUndos(aNbModif); + + for (i = 0; anIter != aListOfInd.end() && isOK; i++, anIter++) { + isOK = myPUndo[i].init(theType, aValue, *anIter); + } + } + + return isOK; +} diff --git a/src/CurveCreator/CurveCreator_Diff.hxx b/src/CurveCreator/CurveCreator_Diff.hxx new file mode 100644 index 000000000..291aaee35 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Diff.hxx @@ -0,0 +1,218 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Diff.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Diff_HeaderFile +#define _CurveCreator_Diff_HeaderFile + +#include "CurveCreator_Operation.hxx" + +class CurveCreator_Curve; + + +/** + * This is the support class for store/retrieve differences of undo/redo + * operations. To fill the difference it is necessary to create it with + * an appropriate type and to call the method initialize with required + * parameters. + */ +class CurveCreator_Diff +{ + +private: + +public: + + /** + * Constructor. + */ + CurveCreator_Diff(); + + /** + * Destructor. + */ + ~CurveCreator_Diff(); + + /** + * This method initializes the difference with an operation without + * parameters. It is applicable to the following operations: + *
    + *
  • Clear
  • + *
  • Join (without arguments)
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType); + + /** + * This method initializes the difference with an operation with one integer + * parameter. It is applicable to the following operations: + *
    + *
  • RemoveSection
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam); + + /** + * This method initializes the difference with an operation with two integer + * parameters. It is applicable to the following operations: + *
    + *
  • SetType
  • + *
  • SetClosed
  • + *
  • MoveSection
  • + *
  • Join (with 2 int arguments)
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2); + + /** + * This method initializes the difference with an operation with three + * integer parameters. It is applicable to the following operations: + *
    + *
  • RemovePoints
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2, + const int theIntParam3); + + /** + * This method initializes the difference with an operation with one + * CurveCreator::Coordinates parameter and one integer parameter. + * It is applicable to the following operations: + *
    + *
  • AddPoints
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam); + + /** + * This method initializes the difference with an operation with one + * CurveCreator::Coordinates parameter and two integer parameters. + * It is applicable to the following operations: + *
    + *
  • InsertPoints
  • + *
  • SetCoordinates
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2); + + /** + * This method initializes the difference with an operation with one + * Name, one CurveCreator::Coordinates parameter and two integer parameters. + * It is applicable to the following operations: + *
    + *
  • AddSection
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const std::string& theName, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2); + + /** + * This method initializes the difference with an operation with one + * string and one integer parameters. + * It is applicable to the following operations: + *
    + *
  • RenameSection
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const std::string &theName, + const int theIntParam1 ); + + /** + * This method applies undo operation to theCurve. + */ + void applyUndo(CurveCreator_Curve *theCurve); + + /** + * This method applies redo operation to theCurve. + */ + void applyRedo(CurveCreator_Curve *theCurve); + +private: + + /** + * This method clears initialized data pointers. + */ + void clear(); + + /** + * This method sets the number of undos and allocates the required + * space for myPUndo. + */ + void setNbUndos(const int theNbUndos); + + /** + * This method returns the section index. It returns theIndex if it is + * a real index and the last section's index if theIndex is equal to -1. + */ + int getSectionIndex(const CurveCreator_Curve *theCurve, + const int theIndex) const; + + /** + * Convert theIndex'th section of theCurve into AddSection command + * and store it in theOperation. Returns true in case of success and + * false otherwise. + */ + bool addSectionToUndo(const CurveCreator_Curve *theCurve, + const int theIndex, + CurveCreator_Operation &theOperation) const; + + /** + * Construct undos for SetType and SetClosed operations. Note: the + * algorithm is optimized taking into account that there are only 2 types + * and 2 values of isClosed flag. If the number of types is increased, + * this algorithm should be re-implemented. + */ + bool setTypeOrClosedToUndo(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2); + +private: + + int myNbUndos; + CurveCreator_Operation *myPUndo; + CurveCreator_Operation *myPRedo; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_ICurve.cxx b/src/CurveCreator/CurveCreator_ICurve.cxx new file mode 100644 index 000000000..819b43b21 --- /dev/null +++ b/src/CurveCreator/CurveCreator_ICurve.cxx @@ -0,0 +1,459 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_ICurve.cxx +// Author: Sergey KHROMOV + +#include "CurveCreator_ICurve.hxx" +#include "CurveCreator_Section.hxx" +#include "CurveCreator_Listener.hxx" + +#include + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_ICurve::CurveCreator_ICurve + (const CurveCreator::Dimension theDimension) +: myIsLocked (false), + myDimension (theDimension), + myListener(NULL) +{ +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_ICurve::~CurveCreator_ICurve() +{ + // Delete all allocated data. + clear(); +} + +//======================================================================= +// function: isLocked +// purpose: +//======================================================================= +bool CurveCreator_ICurve::isLocked() const +{ + return myIsLocked; +} + +//======================================================================= +// function: getDimension +// purpose: +//======================================================================= +CurveCreator::Dimension CurveCreator_ICurve::getDimension() const +{ + return myDimension; +} + +//======================================================================= +// function: getNbPoints +// purpose: +//======================================================================= +int CurveCreator_ICurve::getNbPoints(const int theISection) const +{ + int aNbCoords = 0; + + if (theISection == -1) { + int i = 0; + const int aNbSections = getNbSections(); + + for (; i < aNbSections; i++) { + aNbCoords += mySections[i]->myPoints.size(); + } + } else { + aNbCoords = mySections.at(theISection)->myPoints.size(); + } + + return aNbCoords/myDimension; +} + +//======================================================================= +// function: getNbSections +// purpose: +//======================================================================= +int CurveCreator_ICurve::getNbSections() const +{ + return mySections.size(); +} + +//======================================================================= +// function: getCoordinates +// purpose: +//======================================================================= +CurveCreator::Coordinates CurveCreator_ICurve::getCoordinates + (const int theISection, const int theIPnt) const +{ + CurveCreator_Section *aSection = mySections.at(theISection); + CurveCreator::Coordinates::const_iterator + anIter = aSection->myPoints.begin() + toICoord(theIPnt); + CurveCreator::Coordinates aResult(anIter, anIter + myDimension); + + return aResult; +} + +//======================================================================= +// function: getType +// purpose: +//======================================================================= +CurveCreator::Type CurveCreator_ICurve::getType(const int theISection) const +{ + return mySections.at(theISection)->myType; +} + +//======================================================================= +// function: getPoints +// purpose: +//======================================================================= +const CurveCreator::Coordinates &CurveCreator_ICurve::getPoints + (const int theISection) const +{ + return mySections.at(theISection)->myPoints; +} + +//======================================================================= +// function: isClosed +// purpose: +//======================================================================= +bool CurveCreator_ICurve::isClosed(const int theISection) const +{ + return mySections.at(theISection)->myIsClosed; +} + +std::string CurveCreator_ICurve::getSectionName(const int theISection) const +{ + return mySections.at(theISection)->myName; +} + +//======================================================================= +// function: setType +// purpose: +//======================================================================= +void CurveCreator_ICurve::setType + (const CurveCreator::Type theType, const int theISection) +{ + if (theISection == -1) { + int i = 0; + const int aNbSections = getNbSections(); + + for (; i < aNbSections; i++) { + mySections[i]->myType = theType; + } + if( myListener ) + myListener->curveChanged(); + } else { + if( mySections.at(theISection)->myType != theType ){ + mySections.at(theISection)->myType = theType; + if( myListener ) + myListener->sectionTypeChanged(theISection); + } + } +} + +//======================================================================= +// function: addSection +// purpose: +//======================================================================= +void CurveCreator_ICurve::addSection + (const std::string& theName, + const CurveCreator::Type theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints) +{ + CurveCreator_Section *aSection = new CurveCreator_Section; + + std::string aName = theName; + if( aName.empty() ){ + aName = getUnicSectionName(); + } + aSection->myName = aName; + aSection->myType = theType; + aSection->myIsClosed = theIsClosed; + aSection->myPoints = thePoints; + mySections.push_back(aSection); + if( myListener ) + myListener->sectionAdded( -1 ); +} + +//======================================================================= +// function: removeSection +// purpose: +//======================================================================= +void CurveCreator_ICurve::removeSection(const int theISection) +{ + if (theISection == -1) { + delete mySections.back(); + mySections.pop_back(); + } else { + Sections::iterator anIterRm = mySections.begin() + theISection; + + delete *anIterRm; + mySections.erase(anIterRm); + } + if( myListener ) + myListener->sectionRemoved(theISection); +} + +//======================================================================= +// function: insertPoints +// purpose: +//======================================================================= +void CurveCreator_ICurve::insertPoints + (const CurveCreator::Coordinates &thePoints, + const int theISection, + const int theIPnt) +{ + if (theIPnt == -1) { + // Add points to the end of section points. + addPoints(thePoints, theISection); + } else { + CurveCreator_Section *aSection = + (theISection == -1 ? mySections.back() : mySections.at(theISection)); + + aSection->myPoints.insert(aSection->myPoints.begin() + toICoord(theIPnt), + thePoints.begin(), thePoints.end()); + if( myListener ) + myListener->pointInserted( theISection, theIPnt ); + } +} + +void CurveCreator_ICurve::movePoint(const int theISection, const int theIPointFrom, const int theNewIndex) +{ + CurveCreator::Coordinates aCoords = getCoordinates(theISection, theIPointFrom ); + insertPoints(aCoords, theISection, theNewIndex+1); + int aRemPntIndx = theIPointFrom; + if( theNewIndex < theIPointFrom ) + aRemPntIndx++; + removePoints(theISection, aRemPntIndx, 1 ); +} + +//======================================================================= +// function: removePoints +// purpose: +//======================================================================= +void CurveCreator_ICurve::removePoints(const int theISection, + const int theIPnt, + const int theNbPoints) +{ + CurveCreator_Section *aSection = mySections.at(theISection); + CurveCreator::Coordinates::iterator anIterBegin = + aSection->myPoints.begin() + toICoord(theIPnt); + CurveCreator::Coordinates::iterator anIterEnd = + (theNbPoints == -1 ? + aSection->myPoints.end() : anIterBegin + toICoord(theNbPoints)); + + aSection->myPoints.erase(anIterBegin, anIterEnd); + if( myListener ) + myListener->pointRemoved(theISection, theIPnt, theNbPoints ); +} + +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_ICurve::clear() +{ + // Delete all allocated data. + int i = 0; + const int aNbSections = getNbSections(); + + for (; i < aNbSections; i++) { + delete mySections[i]; + } + + mySections.clear(); + if( myListener ) + myListener->curveChanged(); +} + +//======================================================================= +// function: setCoordinates +// purpose: +//======================================================================= +void CurveCreator_ICurve::setCoordinates + (const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt) +{ + if (theCoords.size() == myDimension) { + CurveCreator_Section *aSection = mySections.at(theISection); + int i; + + for (i = 0; i < myDimension; i++) { + aSection->myPoints.at(toICoord(theIPnt) + i) = theCoords[i]; + } + + if( myListener ) + myListener->pointChanged( theISection, theIPnt ); + } +} + +//======================================================================= +// function: setClosed +// purpose: +//======================================================================= +void CurveCreator_ICurve::setClosed(const bool theIsClosed, + const int theISection) +{ + if (theISection == -1) { + int aSize = mySections.size(); + int i; + + for (i = 0; i < aSize; i++) { + mySections[i]->myIsClosed = theIsClosed; + if( myListener ){ + myListener->sectionClosed( theISection, theIsClosed ); + } + } + } else { + mySections.at(theISection)->myIsClosed = theIsClosed; + if( myListener ){ + myListener->sectionClosed( theISection, theIsClosed ); + } + } +} + +/** Set name of the specified section. + */ +void CurveCreator_ICurve::setName( const std::string& theName, const int theISection ) +{ + if( ( theISection >= 0 ) && ( theISection < mySections.size() )){ + mySections.at(theISection)->myName = theName; + } +} + +//======================================================================= +// function: moveSection +// purpose: +//======================================================================= +void CurveCreator_ICurve::moveSection(const int theISection, + const int theNewIndex) +{ + if (theISection != theNewIndex) { + CurveCreator_Section *aSection = mySections.at(theISection); + + // Remove section + Sections::iterator anIter = mySections.begin() + theISection; + + mySections.erase(anIter); + + // Insert section. + anIter = mySections.begin() + theNewIndex; + mySections.insert(anIter, aSection); + } +} + +//======================================================================= +// function: join +// purpose: +//======================================================================= +void CurveCreator_ICurve::join(const int theISectionTo, + const int theISectionFrom) +{ + if (theISectionTo != theISectionFrom) { + CurveCreator_Section *aSection1 = mySections.at(theISectionTo); + CurveCreator_Section *aSection2 = mySections.at(theISectionFrom); + + aSection1->myPoints.insert(aSection1->myPoints.end(), + aSection2->myPoints.begin(), aSection2->myPoints.end()); + + removeSection(theISectionFrom); + if( myListener ) + myListener->curveChanged(); + } +} + +//======================================================================= +// function: join +// purpose: +//======================================================================= +void CurveCreator_ICurve::join() +{ + const int aSize = mySections.size(); + + if (aSize > 1) { + CurveCreator_Section *aSection1 = mySections[0]; + int i; + + for (i = 1; i < aSize; i++) { + CurveCreator_Section *aSection2 = mySections[i]; + + aSection1->myPoints.insert(aSection1->myPoints.end(), + aSection2->myPoints.begin(), aSection2->myPoints.end()); + delete aSection2; + } + + // Just erace section pointers as they were deleted before. + mySections.erase(mySections.begin() + 1, mySections.end()); + if( myListener ) + myListener->curveChanged(); + } +} + +//======================================================================= +// function: toICoord +// purpose: +//======================================================================= +int CurveCreator_ICurve::toICoord(const int theIPnt) const +{ + return theIPnt*myDimension; +} + +//======================================================================= +// function: getUnicSectionName +// purpose: return unic section name +//======================================================================= +std::string CurveCreator_ICurve::getUnicSectionName() +{ + for( int i = 0 ; i < 1000000 ; i++ ){ + char aBuffer[255]; + sprintf( aBuffer, "Section_%d", i+1 ); + std::string aName(aBuffer); + int j; + for( j = 0 ; j < mySections.size() ; j++ ){ + if( mySections[j]->myName == aName ) + break; + } + if( j == mySections.size() ) + return aName; + } + return ""; +} + +//======================================================================= +// function: setListener +// purpose: set curve changes listener +//======================================================================= +void CurveCreator_ICurve::setListener( CurveCreator_Listener* theListener ) +{ + myListener = theListener; +} + +//======================================================================= +// function: setListener +// purpose: set curve changes listener +//======================================================================= +void CurveCreator_ICurve::removeListener() +{ + myListener = NULL; +} diff --git a/src/CurveCreator/CurveCreator_ICurve.hxx b/src/CurveCreator/CurveCreator_ICurve.hxx new file mode 100644 index 000000000..7d0cac83b --- /dev/null +++ b/src/CurveCreator/CurveCreator_ICurve.hxx @@ -0,0 +1,189 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Curve.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_ICurve_HeaderFile +#define _CurveCreator_ICurve_HeaderFile + +#include "CurveCreator.hxx" +#include "CurveCreator_Macro.hxx" +#include "CurveCreator_Operation.hxx" + +#include + +class CurveCreator_Section; +class CurveCreator_Listener; + +/** + * The CurveCreator_ICurve object is represented as one or more sets of + * connected points; thus CurveCreator_ICurve object can contain several + * not connected curves (polylines or b-splines), each such curve has two + * only ends � start and end points � in other words non-manifold curves + * are not supported. + */ +class CURVECREATOR_EXPORT CurveCreator_ICurve +{ + + //! List of curves + typedef std::deque Sections; + +public: + //! Constructor of the curve. + /** The dimension is explicitly specified in the constructor + * and cannot be changed later. + */ + CurveCreator_ICurve(const CurveCreator::Dimension theDimension); + + //! Destructor. + virtual ~CurveCreator_ICurve(); + + //! Returns true if this curve is locked by a curve editor. + virtual bool isLocked() const; + + //! Get the dimension. + virtual CurveCreator::Dimension getDimension() const; + + //! Get number of sections. + virtual int getNbSections() const; + + /** Get number of points in specified section or (the total number of points + * in Curve if theISection is equal to -1). + */ + virtual int getNbPoints(const int theISection = -1) const; + + //! Get coordinates of specified point + virtual CurveCreator::Coordinates getCoordinates + (const int theISection, const int theIPnt) const; + + //! Get points of a section. + virtual const CurveCreator::Coordinates &getPoints(const int theISection) const; + + //! Get type of the specified section + virtual CurveCreator::Type getType(const int theISection) const; + + //! Get �closed� flag of the specified section + virtual bool isClosed(const int theISection) const; + + //! Returns specifyed section name + virtual std::string getSectionName(const int theISection) const; + + /** + * Return unic section name + */ + virtual std::string getUnicSectionName(); + + /** + * Set curve creator listener object + */ + virtual void setListener( CurveCreator_Listener* myWatcher ); + + /** + * Remove curve creator listener object + */ + virtual void removeListener(); + +protected: + + /** Set type of the specified section (or all sections + * if \a theISection is -1). + */ + virtual void setType(const CurveCreator::Type theType, const int theISection = -1); + + /** Add points to the specified section (or last section + * if \a theISection is -1). + */ + virtual void addPoints + (const CurveCreator::Coordinates &thePoints, const int theISection = -1) = 0; + + //! Add a new section. + virtual void addSection (const std::string &theName, const CurveCreator::Type theType, + const bool theIsClosed, + const CurveCreator::Coordinates &thePoints); + + //! Removes the section. If theISection equals -1, removes the last section. + virtual void removeSection(const int theISection = -1); + + /** Insert points in the given position (add to the end of list + * if \a theIPnt parameter is -1) of the specified section + * (or last section if \a theISection parameter is -1). + */ + virtual void insertPoints(const CurveCreator::Coordinates &thePoints, + const int theISection = -1, + const int theIPnt = -1); + + /** Remove \a nbPoints points from given \a theISection, + * starting from given \a theIPnt (of all points up to the end of + * section if \a theNbPoints is -1). + */ + virtual void removePoints(const int theISection, + const int theIPnt, + const int theNbPoints = -1); + + /** Move specified point within section to new position + */ + virtual void movePoint(const int theISection, + const int theIPointFrom, + const int theNewIndex); + + //! Remove all sections. + virtual void clear(); + + //! Set coordinates of specified point + virtual void setCoordinates(const CurveCreator::Coordinates &theCoords, + const int theISection, + const int theIPnt); + + /** Set �closed� flag of the specified section (all sections if + * \a theISection is -1). + */ + virtual void setClosed(const bool theIsClosed, const int theISection = -1); + + /** Set name of the specified section. + */ + virtual void setName( const std::string& theName, const int theISection ); + + /** Move specified \a theISection to the specified position + * in the sections list. + */ + virtual void moveSection(const int theISection, const int theNewIndex); + + //! Join two sections to one section + virtual void join(const int theISectionTo, const int theISectionFrom); + + //! Join all sections to the single curve + virtual void join(); + + /** + * This method converts the point index to the index in + * an array of coordinates. + */ + virtual int toICoord(const int theIPnt) const; + +public: + + bool myIsLocked; + Sections mySections; //!< curve data + CurveCreator::Dimension myDimension; //!< curve dimension + CurveCreator_Listener* myListener; //!< listener + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_Listener.hxx b/src/CurveCreator/CurveCreator_Listener.hxx new file mode 100755 index 000000000..c2ac6cd7a --- /dev/null +++ b/src/CurveCreator/CurveCreator_Listener.hxx @@ -0,0 +1,41 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef CURVE_CREATOR_LISTENER_HXX +#define CURVE_CREATOR_LISTENER_HXX + +class CurveCreator_Listener +{ +public: + CurveCreator_Listener(void){}; + virtual ~CurveCreator_Listener(void){}; + + virtual void pointChanged( int theSection, int thePoint ){} + virtual void pointRemoved( int theSection, int theFirstPoint, int thePointCnt ){} + virtual void pointInserted( int theSection, int theIndx ){} + + virtual void sectionClosed( int theSection, bool isClosed ){} + virtual void sectionAdded( int theSection ){} + virtual void sectionRemoved( int theSection ){} + virtual void sectionTypeChanged( int theSection ){} + + virtual void curveChanged(){} +}; + +#endif \ No newline at end of file diff --git a/src/CurveCreator/CurveCreator_Macro.hxx b/src/CurveCreator/CurveCreator_Macro.hxx new file mode 100644 index 000000000..ec814eb49 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Macro.hxx @@ -0,0 +1,44 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Macro.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Macro_HeaderFile +#define _CurveCreator_Macro_HeaderFile + +#ifdef WNT + #if defined CURVECREATOR_EXPORTS || defined CurveCreator_EXPORTS + #if defined WIN32 + #define CURVECREATOR_EXPORT __declspec( dllexport ) + #else + #define CURVECREATOR_EXPORT + #endif + #else + #if defined WIN32 + #define CURVECREATOR_EXPORT __declspec( dllimport ) + #else + #define CURVECREATOR_EXPORT + #endif + #endif +#else + #define CURVECREATOR_EXPORT +#endif + +#endif diff --git a/src/CurveCreator/CurveCreator_NewPointDlg.cxx b/src/CurveCreator/CurveCreator_NewPointDlg.cxx new file mode 100755 index 000000000..85e74f883 --- /dev/null +++ b/src/CurveCreator/CurveCreator_NewPointDlg.cxx @@ -0,0 +1,196 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "CurveCreator_NewPointDlg.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +CurveCreator_NewPointDlg::CurveCreator_NewPointDlg(CurveCreator::Dimension theDim, QWidget *parent) : + QWidget(parent), myX(NULL), myY(NULL), myZ(NULL), myIsEdit(false), myDim(theDim), + myIsInstantSketchingEnabled(false) +{ + QString aTitle = QString(tr("ADD_NEW_POINT")); + setWindowTitle(aTitle); + + QFrame* aFrame = new QFrame( this ); + QVBoxLayout* aLayout = new QVBoxLayout( aFrame ); + + QFrame* aCoordFrame = new QFrame( aFrame ); + QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame ); + + QLabel* aLbl = new QLabel( tr("X_COORD"), this); + myX = new QDoubleSpinBox(this); + aCoordLayout->addWidget(aLbl, 0, 0); + aCoordLayout->addWidget(myX, 0, 1 ); + + aLbl = new QLabel( tr("Y_COORD"), this); + myY = new QDoubleSpinBox(this); + aCoordLayout->addWidget(aLbl, 1, 0 ); + aCoordLayout->addWidget(myY, 1, 1 ); + + myZLabel = new QLabel( tr("Z_COORD"), this); + myZ = new QDoubleSpinBox(this); + aCoordLayout->addWidget(myZLabel, 2,0 ); + aCoordLayout->addWidget(myZ, 2,1 ); + + if( theDim != CurveCreator::Dim3d ){ + myZ->hide(); + myZLabel->hide(); + } + + myBtnFrame = new QFrame( aFrame ); + QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame ); + + myAddBtn = new QPushButton( tr( "ADD_BTN" ), myBtnFrame ); + myCancelBtn = new QPushButton( tr( "CANCEL" ), myBtnFrame ); + + connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelPoint() ) ); + + aBtnsLayout->addWidget( myAddBtn ); + aBtnsLayout->addStretch( 1 ); + aBtnsLayout->addWidget( myCancelBtn ); + + aLayout->addWidget( aCoordFrame, 0 ); + aLayout->addWidget( myBtnFrame, 1 ); + + clear(); + updateTitle(); +} + +void CurveCreator_NewPointDlg::setSectionName( const QString& theName ) +{ + mySectionName = theName; + updateTitle(); +} + +void CurveCreator_NewPointDlg::setEditMode( bool isEdit ) +{ + myIsEdit = isEdit; + if( myIsEdit ){ + myAddBtn->setText(tr("OK")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifyPoint() ) ); + } + else{ + myAddBtn->setText(tr("ADD_BTN")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addPoint() ) ); + } + updateTitle(); +} + +void CurveCreator_NewPointDlg::updateTitle() +{ + QString aTitle; + if( !myIsEdit ){ + if( mySectionName.isEmpty() ){ + aTitle = tr("ADD_NEW_POINT"); + } + else{ + aTitle = QString(tr("ADD_NEW_POINT_TO_%1")).arg(mySectionName); + } + } + else{ + aTitle = tr("SET_POINT_COORDINATES"); + } + setWindowTitle(aTitle); +} + +CurveCreator::Coordinates CurveCreator_NewPointDlg::getCoordinates() const +{ + CurveCreator::Coordinates aCoords; + double anX = myX->value(); + aCoords.push_back(anX); + double anY = myY->value(); + aCoords.push_back(anY); + if( myDim == CurveCreator::Dim3d ){ + double aZ = myZ->value(); + aCoords.push_back(aZ); + } + return aCoords; +} + +void CurveCreator_NewPointDlg::clear() +{ + initSpinBox(myX); + initSpinBox(myY); + initSpinBox(myZ); +} + +void CurveCreator_NewPointDlg::setDimension(CurveCreator::Dimension theDim) +{ + if( theDim == CurveCreator::Dim2d ){ + myZ->hide(); + myZLabel->hide(); + } + else{ + myZ->show(); + myZLabel->show(); + } +} + +void CurveCreator_NewPointDlg::setCoordinates( const CurveCreator::Coordinates& theCoords ) +{ + double anX = theCoords[0]; + myX->setValue(anX); + double anY = theCoords[1]; + myY->setValue(anY); + if( theCoords.size() == 3 ){ + double aZ = theCoords[2]; + myZ->setValue(aZ); + } + if( isInstantSketchingEnabled() ) + emit addPoint(); +} + +bool CurveCreator_NewPointDlg::isInstantSketchingEnabled() const +{ + return myIsInstantSketchingEnabled; +} + +void CurveCreator_NewPointDlg::setInstantSketchingEnabled( const bool theState ) +{ + myIsInstantSketchingEnabled = theState; +} + +//======================================================================= +// function: initSpinBox +// purpose: +//======================================================================= +void CurveCreator_NewPointDlg::initSpinBox(QDoubleSpinBox *theSpinBox) +{ + const double aCoordMin = -1.e+15; + const double aCoordMax = 1.e+15; + const double aStep = 10; + const int aPrecision = 6; + + theSpinBox->setDecimals( qAbs( aPrecision ) ); + theSpinBox->setRange(aCoordMin, aCoordMax); + theSpinBox->setSingleStep(aStep); + theSpinBox->setValue(0.0); +} diff --git a/src/CurveCreator/CurveCreator_NewPointDlg.h b/src/CurveCreator/CurveCreator_NewPointDlg.h new file mode 100755 index 000000000..ebc6edd92 --- /dev/null +++ b/src/CurveCreator/CurveCreator_NewPointDlg.h @@ -0,0 +1,70 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef CURVECREATOR_NEWPOINTDLG_H +#define CURVECREATOR_NEWPOINTDLG_H + +#include "CurveCreator.hxx" + +#include + +class QDoubleSpinBox; +class QDialogButtonBox; +class QAbstractButton; +class QPushButton; +class QLabel; +class QFrame; + +class CurveCreator_NewPointDlg : public QWidget +{ + Q_OBJECT +public: + explicit CurveCreator_NewPointDlg(CurveCreator::Dimension theDim, QWidget *parent = 0); + CurveCreator::Coordinates getCoordinates() const; + void clear(); + void setSectionName( const QString& theName ); + void setEditMode( bool isEdit ); + void setCoordinates( const CurveCreator::Coordinates& theCoords ); + void setDimension(CurveCreator::Dimension theDim); + bool isInstantSketchingEnabled() const; + void setInstantSketchingEnabled( const bool theState ); +signals: + void addPoint(); + void modifyPoint(); + void cancelPoint(); +public slots: +protected slots: +protected: + void updateTitle(); + void initSpinBox(QDoubleSpinBox *theSpinBox); +private: + QFrame* myBtnFrame; + CurveCreator::Dimension myDim; + QDoubleSpinBox* myX; + QDoubleSpinBox* myY; + QDoubleSpinBox* myZ; + QLabel* myZLabel; + QPushButton* myAddBtn; + QPushButton* myCancelBtn; + bool myIsEdit; + QString mySectionName; + bool myIsInstantSketchingEnabled; +}; + +#endif // CURVECREATOR_NEWPOINTDLG_H diff --git a/src/CurveCreator/CurveCreator_NewSectionDlg.cxx b/src/CurveCreator/CurveCreator_NewSectionDlg.cxx new file mode 100755 index 000000000..cb59f3230 --- /dev/null +++ b/src/CurveCreator/CurveCreator_NewSectionDlg.cxx @@ -0,0 +1,149 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "CurveCreator_NewSectionDlg.h" +#include "CurveCreator_Curve.hxx" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent ) : + QWidget(parent) +{ + QFrame* aFrame = new QFrame( this ); + QVBoxLayout* aLayout = new QVBoxLayout( aFrame ); + + QFrame* aCoordFrame = new QFrame( aFrame ); + QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame ); + + QLabel* aLbl = new QLabel(tr("NAME"), this); + myName = new QLineEdit(this); + aCoordLayout->addWidget(aLbl, 0, 0); + aCoordLayout->addWidget(myName, 0 , 1); + + aLbl = new QLabel(tr("LINE_TYPE")); + myLineType = new QComboBox(this); + + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); + QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); + +// QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE")); +// QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE")); + myLineType->addItem(aPolylinePixmap, tr("POLYLINE_TYPE")); + myLineType->addItem(aSplinePixmap, tr("SPLINE_TYPE")); + myLineType->setCurrentIndex(0); + aCoordLayout->addWidget(aLbl, 1, 0); + aCoordLayout->addWidget(myLineType, 1 , 1); + + aLbl = new QLabel(tr("LINE_CLOSED")); + myIsClosed = new QCheckBox(this); + aCoordLayout->addWidget(aLbl, 2, 0); + aCoordLayout->addWidget(myIsClosed, 2, 1); + + myBtnFrame = new QFrame( aFrame ); + QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame ); + + myAddBtn = new QPushButton( tr( "ADD_BTN" ), myBtnFrame ); + myCancelBtn = new QPushButton( tr( "CANCEL" ), myBtnFrame ); + + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelSection() ) ); + + aBtnsLayout->addWidget( myAddBtn ); + aBtnsLayout->addStretch( 1 ); + aBtnsLayout->addWidget( myCancelBtn ); + + aLayout->addWidget( aCoordFrame, 0 ); + aLayout->addWidget( myBtnFrame, 1 ); +} + +void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, bool isClosed, CurveCreator::Type theType ) +{ + myName->setText(theName); + myIsClosed->setChecked(isClosed); + if( theType == CurveCreator::Polyline ) + myLineType->setCurrentIndex(0); + else + myLineType->setCurrentIndex(1); +} + +void CurveCreator_NewSectionDlg::clear() +{ + myName->setText(""); + myIsClosed->setChecked(true); + myLineType->setCurrentIndex(0); +} + +void CurveCreator_NewSectionDlg::setEditMode( bool isEdit ) +{ + myIsEdit = isEdit; + if( myIsEdit ){ + myAddBtn->setText(tr("OK")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifySection() ) ); + } + else{ + myAddBtn->setText(tr("ADD_BTN")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) ); + } + updateTitle(); +} + +QString CurveCreator_NewSectionDlg::getName() const +{ + return myName->text(); +} + +bool CurveCreator_NewSectionDlg::isClosed() const +{ + return myIsClosed->isChecked(); +} + +CurveCreator::Type CurveCreator_NewSectionDlg::getSectionType() const +{ + if( myLineType->currentIndex() == 0 ) + return CurveCreator::Polyline; + else + return CurveCreator::BSpline; +} + +void CurveCreator_NewSectionDlg::updateTitle() +{ + QString aTitle; + if( !myIsEdit ) + aTitle = tr("ADD_NEW_SECTION"); + else + aTitle = QString(tr("SET_SECTION_PARAMETERS")); + setWindowTitle(aTitle); +} + +void CurveCreator_NewSectionDlg::setSectionName( const QString& theName ) +{ + myName->setText(theName); +} diff --git a/src/CurveCreator/CurveCreator_NewSectionDlg.h b/src/CurveCreator/CurveCreator_NewSectionDlg.h new file mode 100755 index 000000000..1b369429c --- /dev/null +++ b/src/CurveCreator/CurveCreator_NewSectionDlg.h @@ -0,0 +1,70 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef CURVECREATOR_NEWSECTION_H +#define CURVECREATOR_NEWSECTION_H + +#include "CurveCreator.hxx" + +#include + +class CurveCreator_Curve; + +class QLineEdit; +class QComboBox; +class QCheckBox; +class QPushButton; +class QAbstractButton; +class QDialogButtonBox; +class QFrame; + +class CurveCreator_NewSectionDlg : public QWidget +{ + Q_OBJECT +public: + explicit CurveCreator_NewSectionDlg(QWidget *parent = 0); + + QString getName() const; + bool isClosed() const; + CurveCreator::Type getSectionType() const; + + void setSectionParameters( const QString& theName, bool isClosed, CurveCreator::Type theType ); + void setSectionName(const QString& theName ); + void clear(); + void setEditMode( bool isEdit ); + +signals: + void addSection(); + void modifySection(); + void cancelSection(); +public slots: +protected slots: +protected: + void updateTitle(); +private: + QFrame* myBtnFrame; + QLineEdit* myName; + QComboBox* myLineType; + QCheckBox* myIsClosed; + bool myIsEdit; + QPushButton* myAddBtn; + QPushButton* myCancelBtn; +}; + +#endif // CURVECREATOR_NEWSECTION_H diff --git a/src/CurveCreator/CurveCreator_Operation.cxx b/src/CurveCreator/CurveCreator_Operation.cxx new file mode 100644 index 000000000..2019475d1 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Operation.cxx @@ -0,0 +1,402 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Operation.cxx +// Author: Sergey KHROMOV + +#include "CurveCreator_Operation.hxx" +#include "CurveCreator_Curve.hxx" + +#include +#include + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_Operation::CurveCreator_Operation() +: myType (CurveCreator_Operation::Unknown), + myPData (NULL) +{ +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_Operation::~CurveCreator_Operation() +{ + clear(); +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::Clear || + theType == CurveCreator_Operation::Join) { + clear(); + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const int theIntParam) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::RemoveSection) { + int *pData = (int *)allocate(sizeof(int)); + + pData[0] = theIntParam; + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::SetType || + theType == CurveCreator_Operation::SetClosed || + theType == CurveCreator_Operation::MoveSection || + theType == CurveCreator_Operation::Join) { + int *pData = (int *)allocate(2*sizeof(int)); + + pData[0] = theIntParam1; + pData[1] = theIntParam2; + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2, + const int theIntParam3) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::RemovePoints) { + int *pData = (int *)allocate(3*sizeof(int)); + + pData[0] = theIntParam1; + pData[1] = theIntParam2; + pData[2] = theIntParam3; + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::AddPoints) { + const int aNbCoords = theCoords.size(); + const size_t aSize = + 2*sizeof(theIntParam) + aNbCoords*sizeof(CurveCreator::TypeCoord); + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = theIntParam; + *pIntData++ = aNbCoords; + + CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; + int i = 0; + + for (; i < aNbCoords; i++) { + *pRealData++ = theCoords[i]; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::AddSection || + theType == CurveCreator_Operation::InsertPoints || + theType == CurveCreator_Operation::SetCoordinates) { + const int aNbCoords = theCoords.size(); + const size_t aSize = + 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord); + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = theIntParam1; + *pIntData++ = theIntParam2; + *pIntData++ = aNbCoords; + + CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; + int i = 0; + + for (; i < aNbCoords; i++) { + *pRealData++ = theCoords[i]; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const std::string& theName, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2) +{ + bool isOK = false; + if (theType == CurveCreator_Operation::AddSection ) { + const int aNbCoords = theCoords.size(); + const size_t aSize = + 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord) + theName.length() + 1; + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = theIntParam1; + *pIntData++ = theIntParam2; + char* aStrPtr = (char*)pIntData; + if( !theName.empty() ){ + strcpy( aStrPtr, theName.c_str() ); + aStrPtr += theName.length(); + } + else{ + *aStrPtr = 0; + } + aStrPtr++; + pIntData = (int*)aStrPtr; + *pIntData++ = aNbCoords; + + CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)aStrPtr; + int i = 0; + + for (; i < aNbCoords; i++) { + *pRealData++ = theCoords[i]; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const std::string &theName, + const int theIntParam1 ) +{ + if (theType == CurveCreator_Operation::RenameSection ) { + size_t aSize = sizeof(theIntParam1) + theName.length() + 1; + int *pIntData = (int *)allocate(aSize); + *pIntData = theIntParam1; + pIntData++; + if( !theName.empty() ){ + strcpy( (char*)pIntData, theName.c_str() ); + } + else{ + *((char*)pIntData) = 0; + } + myType = theType; + return true; + } + return false; +} + +//======================================================================= +// function: apply +// purpose: +//======================================================================= +void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) +{ + if (theCurve != NULL) { + int *pInt = (int *)myPData; + + switch (myType) { + case CurveCreator_Operation::AddPoints: + { + CurveCreator::Coordinates aCoords; + + getCoords(&pInt[1], aCoords); + theCurve->addPoints(aCoords, pInt[0]); + } + break; + case CurveCreator_Operation::RemovePoints: + theCurve->removePoints(pInt[0], pInt[1], pInt[2]); + break; + case CurveCreator_Operation::InsertPoints: + { + CurveCreator::Coordinates aCoords; + + getCoords(&pInt[2], aCoords); + theCurve->insertPoints(aCoords, pInt[0], pInt[1]); + } + break; + case CurveCreator_Operation::SetType: + { + const CurveCreator::Type aType = (CurveCreator::Type) pInt[0]; + + theCurve->setType(aType, pInt[1]); + } + break; + case CurveCreator_Operation::Clear: + theCurve->clear(); + break; + case CurveCreator_Operation::SetCoordinates: + { + CurveCreator::Coordinates aCoords; + + getCoords(&pInt[2], aCoords); + theCurve->setCoordinates(aCoords, pInt[0], pInt[1]); + } + break; + case CurveCreator_Operation::SetClosed: + theCurve->setClosed((pInt[0] != 0), pInt[1]); + break; + case CurveCreator_Operation::MoveSection: + theCurve->moveSection(pInt[0], pInt[1]); + break; + case CurveCreator_Operation::Join: + if (myPData == NULL) { + theCurve->join(); + } else { + theCurve->join(pInt[0], pInt[1]); + } + break; + case CurveCreator_Operation::AddSection: + { + const CurveCreator::Type aType = (CurveCreator::Type) pInt[0]; + + std::string aName = std::string((char*)&pInt[2]); + + CurveCreator::Coordinates aCoords; + + char* aPtr = ((char*)&pInt[2]); + aPtr += (aName.length()) + 1; + getCoords((int*)aPtr, aCoords); + theCurve->addSection(aName, aType, (pInt[1] != 0), aCoords); + } + break; + case CurveCreator_Operation::RemoveSection: + theCurve->removeSection(pInt[0]); + break; + case CurveCreator_Operation::RenameSection: + { + std::string aName = std::string((char*)&pInt[1]); + theCurve->setName(aName, pInt[0]); + } + break; + default: + break; + } + } +} + +//======================================================================= +// function: allocate +// purpose: +//======================================================================= +void *CurveCreator_Operation::allocate(const size_t theSize) +{ + if (myPData != NULL) { + clear(); + } + + myPData = malloc(theSize); + + return myPData; +} + +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_Operation::clear() +{ + myType = CurveCreator_Operation::Unknown; + + if (myPData != NULL) { + free(myPData); + myPData = NULL; + } +} + +//======================================================================= +// function: getCoords +// purpose: +//======================================================================= +void CurveCreator_Operation::getCoords + (int *thePInt, CurveCreator::Coordinates &theCoords) const +{ + const int aNbPnts = *thePInt; + CurveCreator::TypeCoord *pCoord = (CurveCreator::TypeCoord *)&thePInt[1]; + + for (int i = 0; i < aNbPnts; i++) { + theCoords.push_back(pCoord[i]); + } +} diff --git a/src/CurveCreator/CurveCreator_Operation.hxx b/src/CurveCreator/CurveCreator_Operation.hxx new file mode 100644 index 000000000..0c84c4689 --- /dev/null +++ b/src/CurveCreator/CurveCreator_Operation.hxx @@ -0,0 +1,205 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Operation.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Operation_HeaderFile +#define _CurveCreator_Operation_HeaderFile + +#include "CurveCreator.hxx" + +#include + +class CurveCreator_Curve; + + +/** + * This is the support class that describes a modification operation that + * can be applied to CurveCreator_Curve. + */ +class CurveCreator_Operation +{ + +public: + + /** + * This is a type of CurveCreator_Curve modification operation. + */ + enum Type + { + Unknown = 0, //!< Unknown method. + AddPoints, //!< Method CurveCreator_Curve::addPoints + RemovePoints, //!< Method CurveCreator_Curve::removePoints + InsertPoints, //!< Method CurveCreator_Curve::insertPoints + SetType, //!< Method CurveCreator_Curve::setType + Clear, //!< Method CurveCreator_Curve::clear + SetCoordinates, //!< Method CurveCreator_Curve::setCoordinates + SetClosed, //!< Method CurveCreator_Curve::setClosed + MoveSection, //!< Method CurveCreator_Curve::moveSection + Join, //!< Method CurveCreator_Curve::join + AddSection, //!< Method CurveCreator_Curve::addSection + RemoveSection, //!< Method CurveCreator_Curve::removeSection + RenameSection //!< Method CurveCreator_Curve::renameSection + }; + + /** + * Empty constructor. + */ + CurveCreator_Operation(); + + /** + * Destructor. + */ + ~CurveCreator_Operation(); + + /** + * This method initializes the object with an operation without parameters. + * It is applicable to the following operations: + *
    + *
  • Clear
  • + *
  • Join (without arguments)
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType); + + /** + * This method initializes the object with an operation with one integer + * parameter. It is applicable to the following operations: + *
    + *
  • RemoveSection
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const int theIntParam); + + /** + * This method initializes the object with an operation with two integer + * parameters. It is applicable to the following operations: + *
    + *
  • SetType
  • + *
  • SetClosed
  • + *
  • MoveSection
  • + *
  • Join (with 2 int arguments)
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const int theIntParam1, + const int theIntParam2); + + /** + * This method initializes the object with an operation with three integer + * parameters. It is applicable to the following operations: + *
    + *
  • RemovePoints
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const int theIntParam1, + const int theIntParam2, const int theIntParam3); + + /** + * This method initializes the object with an operation with one + * CurveCreator::Coordinates parameter and one integer parameter. + * It is applicable to the following operations: + *
    + *
  • AddPoints
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const CurveCreator::Coordinates &theCoords, + const int theIntParam); + + /** + * This method initializes the object with an operation with one + * CurveCreator::Coordinates parameter and two integer parameters. + * It is applicable to the following operations: + *
    + *
  • AddSection
  • + *
  • InsertPoints
  • + *
  • SetCoordinates
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, const CurveCreator::Coordinates &theCoords, + const int theIntParam1, const int theIntParam2); + + /** + * This method initializes the object with an operation with one + * string, one CurveCreator::Coordinates parameter and two integer parameters. + * It is applicable to the following operations: + *
    + *
  • AddSection
  • + *
  • InsertPoints
  • + *
  • SetCoordinates
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const CurveCreator_Operation::Type theType, + const std::string& theName, + const CurveCreator::Coordinates &theCoords, + const int theIntParam1, + const int theIntParam2); + + + /** + * This method initializes the object with an operation with one + * string parameter and one integer. + * It is applicable to the following operations: + *
    + *
  • RenameSection
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const CurveCreator_Operation::Type theType, + const std::string &theName, + const int theIntParam1 ); + + /** + * This method applies the current operation to theCurve. + */ + void apply(CurveCreator_Curve *theCurve); + +private: + + /** + * This method allocates required memory for the operation data. + * Returns myPData for convenience purpose. + */ + void *allocate(const size_t theSize); + + /** + * This method clears initialized data pointers. + */ + void clear(); + + /** + * This method returns the coordinates read from thePInt. + */ + void getCoords(int *thePInt, CurveCreator::Coordinates &theCoords) const; + +private: + + Type myType; + void *myPData; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_Section.hxx b/src/CurveCreator/CurveCreator_Section.hxx new file mode 100644 index 000000000..6543ffb6d --- /dev/null +++ b/src/CurveCreator/CurveCreator_Section.hxx @@ -0,0 +1,44 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_Section.hxx +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_Section_HeaderFile +#define _CurveCreator_Section_HeaderFile + +#include "CurveCreator.hxx" + +#include + +//! Structure to store sections representing the CurveCreator_Curve object +struct CurveCreator_Section +{ + //! Constructor. Initializes object with default values. + CurveCreator_Section() : myName("Section"),myType(CurveCreator::Polyline), myIsClosed(false) + { } + + std::string myName; //!< section name + CurveCreator::Coordinates myPoints; //!< points coordinates + CurveCreator::Type myType; //!< type of the section + bool myIsClosed; //!< closed or not + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_TreeView.cxx b/src/CurveCreator/CurveCreator_TreeView.cxx new file mode 100755 index 000000000..809da511a --- /dev/null +++ b/src/CurveCreator/CurveCreator_TreeView.cxx @@ -0,0 +1,485 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "CurveCreator_TreeView.h" +#include "CurveCreator_Curve.hxx" + +#include +#include + +#include +#include + +#define ID_SECTION -1 + +CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_Curve* theCurve, QObject* parent ) : + QAbstractItemModel(parent), myCurve(theCurve) +{ + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap aSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); + QPixmap aPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); + QPixmap aClosedSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_SPLINE"))); + QPixmap aClosedPolylineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_CLOSED_POLYLINE"))); + QPixmap aPointIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POINT"))); + +/* QPixmap aSplineIcon(tr(":images/ICON_SPLINE")); + QPixmap aPolylineIcon(tr(":images/ICON_POLYLINE")); + QPixmap aClosedPolylineIcon(tr(":images/ICON_CLOSED_POLYLINE")); + QPixmap aClosedSplineIcon(tr(":images/ICON_CLOSED_SPLINE")); + QPixmap aPointIcon(tr(":images/ICON_POINT")); */ + + if( !aSplineIcon.isNull() ) + myCachedIcons[ICON_SPLINE] = aSplineIcon; + + if( !aPolylineIcon.isNull() ) + myCachedIcons[ICON_POLYLINE] = aPolylineIcon; + + if( !aPolylineIcon.isNull() ) + myCachedIcons[ICON_CLOSED_POLYLINE] = aClosedPolylineIcon; + + if( !aPolylineIcon.isNull() ) + myCachedIcons[ICON_CLOSED_SPLINE] = aClosedSplineIcon; + + if( !aPointIcon.isNull() ) + myCachedIcons[ICON_POINT] = aPointIcon; + + setHeaderData(1, Qt::Horizontal, QVariant("Name"), Qt::DisplayRole); + setHeaderData(2, Qt::Horizontal, QVariant("Nb points"), Qt::DisplayRole); +} + +int CurveCreator_TreeViewModel::columnCount(const QModelIndex & parent ) const +{ + if( parent.internalId() == ID_SECTION ) + return 2; + else + return 2; +} + +QVariant CurveCreator_TreeViewModel::data(const QModelIndex & index, int role ) const +{ + int aRow = index.row(); + int aColumn = index.column(); + if( myCurve ){ + if( index.internalId() == ID_SECTION ){ + if( role == Qt::DisplayRole ){ + if( aColumn == 0 ) + return QString::fromStdString(myCurve->getSectionName(aRow)); + else if( aColumn == 1 ) + return QString::number(myCurve->getNbPoints(aRow)); + return QVariant(); + } + else if( role == Qt::DecorationRole ){ + if( aColumn == 0 ){ + CurveCreator::Type aSectionType = myCurve->getType(aRow); + if( aSectionType == CurveCreator::Polyline ){ + if( myCurve->isClosed(aRow) ){ + return myCachedIcons[ICON_CLOSED_POLYLINE]; + } + else{ + return myCachedIcons[ICON_POLYLINE]; + } + } + else{ + if( myCurve->isClosed(aRow) ){ + return myCachedIcons[ICON_CLOSED_SPLINE]; + } + else{ + return myCachedIcons[ICON_SPLINE]; + } + } + } + } + } +/* else{ + if( role == Qt::DisplayRole ){ + if( aColumn == 1 ) + return QVariant(); + // return "Point"; + else if( aColumn == 0 ){ + CurveCreator::Coordinates aCoords = myCurve->getCoordinates(index.internalId(),index.row() ); + QString anOut; + if( myCurve->getDimension() == CurveCreator::Dim2d ){ + anOut = QString(tr("X=%1, Y=%2")).arg(aCoords[0]).arg(aCoords[1]); + } + else{ + anOut = QString(tr("X=%1, Y=%2, Z=%3")).arg(aCoords[0]).arg(aCoords[1]).arg(aCoords[2]); + } + return anOut; + } + } + else if( role == Qt::DecorationRole ){ + if( aColumn == 0 ){ + return myCachedIcons[ICON_POINT]; + } + } + }*/ + } + return QVariant(); +} + +QModelIndex CurveCreator_TreeViewModel::index(int row, int column, const QModelIndex & parent ) const +{ + if( parent.isValid() ){ + return createIndex(row, column, parent.row() ); + } + else{ + QModelIndex aParent = createIndex(row, column, ID_SECTION ); + return aParent; + } + return QModelIndex(); +} + +QModelIndex CurveCreator_TreeViewModel::parent(const QModelIndex & theIndex) const +{ + if( !theIndex.isValid() ) + return QModelIndex(); + + if( theIndex.internalId() == ID_SECTION ){ + return QModelIndex(); + } + return createIndex( theIndex.internalId(), 0, ID_SECTION ); +} + +int CurveCreator_TreeViewModel::rowCount(const QModelIndex & parent ) const +{ + int aRowCnt = 0; + if( myCurve != NULL ){ + if( !parent.isValid() ){ + //Points level + aRowCnt = myCurve->getNbSections(); + } + else{ + //Section level + if( parent.internalId() == ID_SECTION ){ + aRowCnt = myCurve->getNbPoints(parent.row()); + } + } + } + return aRowCnt; +} + +QModelIndex CurveCreator_TreeViewModel::sectionIndex( int theSection ) const +{ + return createIndex( theSection, 0, ID_SECTION ); +} + +QModelIndex CurveCreator_TreeViewModel::nbPointsIndex( int theSection ) const +{ + return createIndex( theSection, 1, ID_SECTION ); +} + +QModelIndex CurveCreator_TreeViewModel::pointIndex( int theSection, int thePoint ) const +{ + return createIndex( thePoint, 0, theSection ); +} + +bool CurveCreator_TreeViewModel::isSection( const QModelIndex& theIndx ) const +{ + if( theIndx.internalId() == ID_SECTION ) + return true; + return false; +} + +int CurveCreator_TreeViewModel::getSection( const QModelIndex& theIndx ) const +{ + if( theIndx.internalId() == ID_SECTION ) + return theIndx.row(); + return theIndx.internalId(); +} + +int CurveCreator_TreeViewModel::getPoint( const QModelIndex& theIndx ) const +{ + if( theIndx.internalId() == ID_SECTION ) + return -1; + return theIndx.row(); +} + +void CurveCreator_TreeViewModel::setCurve( CurveCreator_Curve* theCurve ) +{ + myCurve = theCurve; + reset(); +} + +/*****************************************************************************************/ +CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_Curve* theCurve, QWidget *parent) : + QTreeView(parent) +{ + header()->hide(); + header()->setResizeMode(QHeaderView::ResizeToContents); + setUniformRowHeights(true); + setContextMenuPolicy( Qt::CustomContextMenu ); + CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this); + setModel(aModel); + setSelectionBehavior(SelectRows); + setSelectionMode(SingleSelection); + setRootIsDecorated(false); + setItemsExpandable(false); + setAllColumnsShowFocus(true); + connect( selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SIGNAL(selectionChanged()) ); + connect( this, SIGNAL(activated(QModelIndex)), this, SLOT(onActivated(QModelIndex))); +} + +QList CurveCreator_TreeView::getSelectedSections() const +{ + QList aSect; + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( !aModel ) + return aSect; +// QModelIndexList anIndxs = selectionModel()->selectedIndexes(); + QModelIndexList anIndxs = selectionModel()->selectedRows(); + for( int i = 0 ; i < anIndxs.size() ; i++ ){ + if( aModel->isSection(anIndxs[i]) ){ + aSect << aModel->getSection( anIndxs[i] ); + } + } + qSort(aSect.begin(), aSect.end()); + return aSect; +} + +void CurveCreator_TreeView::pointsAdded( int theSection, int thePoint, int thePointsCnt ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aSectIndx = aModel->sectionIndex( theSection ); + rowsInserted(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); +// expand( aSectIndx ); + update( aModel->nbPointsIndex( theSection ) ); + } +} + +void CurveCreator_TreeView::pointDataChanged( int theSection, int thePoint ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aPointIndx = aModel->pointIndex( theSection, thePoint ); + dataChanged( aPointIndx, aPointIndx ); + } +} + +void CurveCreator_TreeView::pointsRemoved( int theSection, int thePoint, int thePointsCnt ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + for( int i = 0 ; i < thePointsCnt ; i++ ){ + QModelIndex aSectIndx = aModel->pointIndex(theSection, thePoint + i); + selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect); + } + QModelIndex aSectIndx = aModel->sectionIndex( theSection ); + rowsRemoved(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); + } +} + +void CurveCreator_TreeView::sectionAdded( int theSection ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + rowsInserted(QModelIndex(), theSection, theSection ); + } +} + +void CurveCreator_TreeView::sectionChanged( int theSection, int aSectCnt ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aFirstSectIndx = aModel->sectionIndex( theSection ); + QModelIndex aLastSectIndx = aModel->sectionIndex( theSection + aSectCnt - 1); + dataChanged( aFirstSectIndx, aLastSectIndx ); + } +} + +void CurveCreator_TreeView::sectionsRemoved( int theSection, int theSectionCnt ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + for( int i = 0 ; i < theSectionCnt ; i++ ){ + QModelIndex aSectIndx = aModel->sectionIndex(theSection + i); + this->selectionModel()->select(aSectIndx,QItemSelectionModel::Deselect); + } + rowsRemoved( QModelIndex(), theSection, theSection+theSectionCnt-1 ); + } +} + +void CurveCreator_TreeView::setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ) +{ + setExpanded( theIndx, isExpanded ); + QItemSelectionModel::SelectionFlags aFlag = QItemSelectionModel::Select; + if( !isSelected ){ + aFlag = QItemSelectionModel::Deselect; + } + selectionModel()->select( theIndx, aFlag ); +} + +void CurveCreator_TreeView::getIndexInfo( const QModelIndex& theIndx, bool& isExpand, bool& isSelected, bool& isCurrent ) +{ + isExpand = isExpanded(theIndx); + isSelected = selectionModel()->isSelected(theIndx); + isCurrent = (theIndx == selectionModel()->currentIndex()); +} + +void CurveCreator_TreeView::swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond ) +{ + bool isFirstSelected; + bool isFirstExpanded; + bool isFirstCurrent; + getIndexInfo( theFirst, isFirstExpanded, isFirstSelected, isFirstCurrent ); + + bool isSecondSelected; + bool isSecondExpanded; + bool isSecondCurrent; + getIndexInfo( theSecond, isSecondExpanded, isSecondSelected, isSecondCurrent ); + + setIndexState( theFirst, isSecondExpanded, isSecondSelected, isSecondCurrent ); + setIndexState( theSecond, isFirstExpanded, isFirstSelected, isFirstCurrent ); + dataChanged(theFirst,theFirst); + dataChanged(theSecond,theSecond); +} + +void CurveCreator_TreeView::sectionsSwapped( int theSection, int theOffset ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aFirstIndex = aModel->sectionIndex( theSection ); + QModelIndex aSecondIndex = aModel->sectionIndex( theSection + theOffset ); + swapIndexes( aFirstIndex, aSecondIndex ); + } +} + +void CurveCreator_TreeView::pointsSwapped( int theSection, int thePointNum, int theOffset ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + QModelIndex aFirstIndex = aModel->pointIndex( theSection, thePointNum ); + QModelIndex aSecondIndex = aModel->pointIndex( theSection, thePointNum + theOffset ); + swapIndexes( aFirstIndex, aSecondIndex ); + } +} + +void CurveCreator_TreeView::setSelectedSections( const QList& theList ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + selectionModel()->clearSelection(); + for( int i = 0 ; i < theList.size() ; i++ ){ + QModelIndex aSectIndx = aModel->sectionIndex(theList[i]); + selectionModel()->select(aSectIndx, QItemSelectionModel::Select ); + } + } +} + +void CurveCreator_TreeView::setSelectedPoints( const QList< QPair >& thePointsList ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ){ + selectionModel()->clearSelection(); + for( int i = 0 ; i < thePointsList.size() ; i++ ){ + QModelIndex aSectIndx = aModel->pointIndex( thePointsList[i].first, thePointsList[i].second ); + selectionModel()->select(aSectIndx, QItemSelectionModel::Select ); + } + } +} + +bool pointLessThan(const QPair &s1, const QPair &s2) +{ + if( s1.first < s2.first ) + return true; + if( s1.first > s2.first ) + return false; + return s1.second < s2.second; +} + +QList< QPair< int, int > > CurveCreator_TreeView::getSelectedPoints() const +{ + QList< QPair< int, int > > aPoints; + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( !aModel ) + return aPoints; + QModelIndexList anIndxs = selectionModel()->selectedIndexes(); + for( int i = 0 ; i < anIndxs.size() ; i++ ){ + if( !aModel->isSection( anIndxs[i] ) ){ + int aSect = aModel->getSection(anIndxs[i]); + int aPointNum = aModel->getPoint(anIndxs[i]); + QPair< int, int > aPoint = QPair( aSect, aPointNum ); + aPoints.push_back( aPoint ); + } + } + qSort( aPoints.begin(), aPoints.end(), pointLessThan ); + return aPoints; +} + +CurveCreator_TreeView::SelectionType CurveCreator_TreeView::getSelectionType() const +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( !aModel ) + return ST_NOSEL; + bool isPointSel = false; + bool isSectSel = false; + bool isOneSection = true; + int aSectNum = -1; + QModelIndexList aLst = selectionModel()->selectedIndexes(); + for( int i = 0 ; i < aLst.size() ; i++ ){ + if( aModel->isSection( aLst[i] ) ){ + isSectSel = true; + } + else{ + isPointSel = true; + if( aSectNum == -1 ){ + aSectNum = aModel->getSection(aLst[i]); + } + else{ + if( aSectNum != aModel->getSection( aLst[i] ) ){ + isOneSection = false; + } + } + } + } + if( isSectSel && !isPointSel ) + return ST_SECTIONS; + if( isPointSel && !isSectSel ){ + if( isOneSection ){ + return ST_POINTS_ONE_SECTION; + } + return ST_POINTS; + } + if( isPointSel && isSectSel ) + return ST_MIXED; + return ST_NOSEL; +} + +void CurveCreator_TreeView::onActivated( QModelIndex theIndx ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( !aModel ) + return; + int aSect = aModel->getSection(theIndx); + if( aModel->isSection(theIndx) ){ + emit sectionEntered( aSect ); + return; + } + int aPointNum = aModel->getPoint( theIndx ); + emit pointEntered( aSect, aPointNum ); +} + +void CurveCreator_TreeView::setCurve( CurveCreator_Curve* theCurve ) +{ + CurveCreator_TreeViewModel* aModel = dynamic_cast(model()); + if( aModel ) + aModel->setCurve(theCurve); + reset(); +} diff --git a/src/CurveCreator/CurveCreator_TreeView.h b/src/CurveCreator/CurveCreator_TreeView.h new file mode 100755 index 000000000..e8449157a --- /dev/null +++ b/src/CurveCreator/CurveCreator_TreeView.h @@ -0,0 +1,96 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef CURVECREATOR_TREEVIEW_H +#define CURVECREATOR_TREEVIEW_H + +#include +#include + +class CurveCreator_Curve; + +class CurveCreator_TreeViewModel : public QAbstractItemModel +{ +public: + CurveCreator_TreeViewModel( CurveCreator_Curve* theCurve, QObject* parent ); + virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; + virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; + virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; + virtual QModelIndex parent(const QModelIndex & theIndex) const; +// virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole); + + QModelIndex sectionIndex( int theSection ) const; + QModelIndex nbPointsIndex( int theSection ) const; + QModelIndex pointIndex( int theSection, int thePoint ) const; + + bool isSection( const QModelIndex& theIndx ) const; + int getSection( const QModelIndex& theIndx ) const; + int getPoint( const QModelIndex& theIndx ) const; + + void setCurve( CurveCreator_Curve* theCurve ); + +private: + enum IconType{ ICON_POLYLINE, ICON_SPLINE, ICON_CLOSED_SPLINE, ICON_CLOSED_POLYLINE, ICON_POINT }; +private: + CurveCreator_Curve* myCurve; + QMap myCachedIcons; +}; + +class CurveCreator_TreeView : public QTreeView +{ + Q_OBJECT +public: + enum SelectionType{ ST_NOSEL, ST_POINTS, ST_POINTS_ONE_SECTION, ST_SECTIONS, ST_MIXED }; +public: + explicit CurveCreator_TreeView( CurveCreator_Curve* theCurve, QWidget *parent = 0); + SelectionType getSelectionType() const; + QList getSelectedSections() const; + QList< QPair< int, int > > getSelectedPoints() const; + + void pointsAdded( int theSection, int thePoint, int thePointsCnt=1 ); + void pointDataChanged( int theSection, int thePoint ); + void pointsRemoved(int theSection, int thePoint, int thePointsCnt=1 ); + void pointsSwapped( int theSection, int thePointNum, int theOffset ); + + void sectionAdded( int theSection ); + void sectionChanged(int theSection , int aSectCnt = 1); + void sectionsRemoved( int theSection, int theSectionCnt=1 ); + void sectionsSwapped( int theSection, int theOffset ); + + void setSelectedSections( const QList& theList ); + void setSelectedPoints( const QList< QPair >& thePointsList ); + + void setCurve( CurveCreator_Curve* theCurve ); + +signals: + void selectionChanged(); + void sectionEntered(int); + void pointEntered(int,int); +public slots: +protected slots: + void onActivated( QModelIndex theIndx ); +protected: + void setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ); + void swapIndexes( const QModelIndex& theFirst, const QModelIndex& theSecond ); + void getIndexInfo( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent ); + +}; + +#endif // CURVECREATOR_TREEVIEW_H diff --git a/src/CurveCreator/CurveCreator_UndoOptsDlg.cxx b/src/CurveCreator/CurveCreator_UndoOptsDlg.cxx new file mode 100644 index 000000000..8e38249a4 --- /dev/null +++ b/src/CurveCreator/CurveCreator_UndoOptsDlg.cxx @@ -0,0 +1,237 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_UndoOptsDlg.cxx +// Author: Sergey KHROMOV + +#include "CurveCreator_UndoOptsDlg.h" + +#include +#include +#include +#include +#include +#include +#include + +#define UNDO_DEPTH_UNLIMITED 0 +#define UNDO_DEPTH_DISABLED 1 +#define UNDO_DEPTH_FIX_SIZE 2 + +//======================================================================= +// function: Constructor +// purpose: +//======================================================================= +CurveCreator_UndoOptsDlg::CurveCreator_UndoOptsDlg(QWidget* parent) + : QDialog (parent), + myUndoDepth (UNDO_DEPTH_UNLIMITED), + myOptsBtnGrp (NULL), + myBufferSizeEdit (NULL), + myOkBtn (NULL), + myCancelBtn (NULL) +{ + setWindowTitle(tr("CC_UNDO_OPTIONS_TITLE")); + + // Set Undo/Redo options group + QGroupBox *anUndoOptsGrp = + new QGroupBox(tr("CC_UNDO_OPTIONS_MODIFY")); + QGridLayout *anUndoOptsLO = new QGridLayout(anUndoOptsGrp); + QRadioButton *aDisabledRdBtn = + new QRadioButton(tr("CC_UNDO_OPTIONS_DISABLED"), anUndoOptsGrp); + QRadioButton *aFixSizeRdBtn = + new QRadioButton(tr("CC_UNDO_OPTIONS_FIXED_SIZE"), anUndoOptsGrp); + QRadioButton *anUnlimRdBtn = + new QRadioButton(tr("CC_UNDO_OPTIONS_UNLIMITED"), anUndoOptsGrp); + + myOptsBtnGrp = new QButtonGroup(anUndoOptsGrp); + myBufferSizeEdit = new QLineEdit(anUndoOptsGrp); + anUndoOptsLO->setMargin(9); + anUndoOptsLO->setSpacing(6); + anUndoOptsLO->addWidget(aDisabledRdBtn, 0, 0); + anUndoOptsLO->addWidget(aFixSizeRdBtn, 1, 0); + anUndoOptsLO->addWidget(anUnlimRdBtn, 2, 0); + anUndoOptsLO->addWidget(myBufferSizeEdit, 1, 1); + myOptsBtnGrp->addButton(anUnlimRdBtn, UNDO_DEPTH_UNLIMITED); + myOptsBtnGrp->addButton(aDisabledRdBtn, UNDO_DEPTH_DISABLED); + myOptsBtnGrp->addButton(aFixSizeRdBtn, UNDO_DEPTH_FIX_SIZE); + + // Set OK/Cancel buttons group + QGroupBox *anOkCancelGrp = new QGroupBox; + QGridLayout *anOkCancelLO = new QGridLayout(anOkCancelGrp); + + myOkBtn = new QPushButton(tr("GEOM_BUT_OK"), anOkCancelGrp); + myCancelBtn = new QPushButton(tr("GEOM_BUT_CANCEL"), anOkCancelGrp); + anOkCancelLO->setMargin(9); + anOkCancelLO->setSpacing(6); + anOkCancelLO->addWidget(myOkBtn, 0, 0); + anOkCancelLO->addWidget(myCancelBtn, 0, 1); + + // Set main group + QGroupBox *aMainGrp = new QGroupBox; + QVBoxLayout *aMainLO = new QVBoxLayout(aMainGrp); + + aMainLO->addWidget(anUndoOptsGrp); + aMainLO->addWidget(anOkCancelGrp); + + setLayout(aMainLO); + + init(); +} + +//======================================================================= +// function: Destructor +// purpose: +//======================================================================= +CurveCreator_UndoOptsDlg::~CurveCreator_UndoOptsDlg() +{ +} + +//======================================================================= +// function: setUndoDepth +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::setUndoDepth(const int theDepth) +{ + myUndoDepth = theDepth; + + const int aDepthId = myUndoDepth + 1; + int anId = UNDO_DEPTH_FIX_SIZE; + + if (aDepthId == UNDO_DEPTH_UNLIMITED || + aDepthId == UNDO_DEPTH_DISABLED) { + anId = aDepthId; + } else if (myUndoDepth > 0) { + myBufferSizeEdit->setText(QString::number(myUndoDepth)); + } + + myOptsBtnGrp->button(anId)->setChecked(true); + optionChanged(anId); +} + +//======================================================================= +// function: getUndoDepth +// purpose: +//======================================================================= +int CurveCreator_UndoOptsDlg::getUndoDepth() const +{ + return myUndoDepth; +} + +//======================================================================= +// function: isEnabled +// purpose: +//======================================================================= +bool CurveCreator_UndoOptsDlg::isEnabled() const +{ + return (myUndoDepth + 1 != UNDO_DEPTH_DISABLED); +} + +//======================================================================= +// function: isUnlimited +// purpose: +//======================================================================= +bool CurveCreator_UndoOptsDlg::isUnlimited() const +{ + return (myUndoDepth + 1 == UNDO_DEPTH_UNLIMITED); +} + +//======================================================================= +// function: init +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::init() +{ + // Initialize sections group. + myOptsBtnGrp->setExclusive(true); + myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED)->setChecked(true); + connect(myOptsBtnGrp, SIGNAL(buttonClicked(int)), + this, SLOT(optionChanged(int))); + + // Initialize line edit. + QIntValidator *aValidator = new QIntValidator(myBufferSizeEdit); + + aValidator->setBottom(1); + myBufferSizeEdit->setValidator(aValidator); + optionChanged(UNDO_DEPTH_UNLIMITED); + + // Init buttons. + myOkBtn->setDefault(true); + + connect(myOkBtn, SIGNAL(clicked()), this, SLOT(accept())); + connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject())); + + setTabOrder(); +} + +//======================================================================= +// function: setTabOrder +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::setTabOrder() +{ + QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_DISABLED), + myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE)); + QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE), + myBufferSizeEdit); + QWidget::setTabOrder(myBufferSizeEdit, + myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED)); + QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED), myOkBtn); + QWidget::setTabOrder(myOkBtn, myCancelBtn); +} + +//======================================================================= +// function: optionChanged +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::optionChanged(int theId) +{ + switch (theId) { + case UNDO_DEPTH_FIX_SIZE: + myBufferSizeEdit->setEnabled(true); + break; + case UNDO_DEPTH_UNLIMITED: + case UNDO_DEPTH_DISABLED: + default: + myBufferSizeEdit->setEnabled(false); + break; + } +} + +//======================================================================= +// function: accept +// purpose: +//======================================================================= +void CurveCreator_UndoOptsDlg::accept() +{ + const int anId = myOptsBtnGrp->checkedId(); + + switch (anId) { + case UNDO_DEPTH_FIX_SIZE: + myUndoDepth = myBufferSizeEdit->text().toInt(); + break; + case UNDO_DEPTH_UNLIMITED: + case UNDO_DEPTH_DISABLED: + myUndoDepth = anId - 1; + break; + default: + break; + } + + QDialog::accept(); +} diff --git a/src/CurveCreator/CurveCreator_UndoOptsDlg.h b/src/CurveCreator/CurveCreator_UndoOptsDlg.h new file mode 100644 index 000000000..1d02bf631 --- /dev/null +++ b/src/CurveCreator/CurveCreator_UndoOptsDlg.h @@ -0,0 +1,73 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_UndoOptsDlg.h +// Author: Sergey KHROMOV + +#ifndef _CurveCreator_UndoOptsDlg_HeaderFile +#define _CurveCreator_UndoOptsDlg_HeaderFile + +#include + +class QButtonGroup; +class QLineEdit; +class QPushButton; + + +class CurveCreator_UndoOptsDlg : public QDialog +{ + Q_OBJECT + +public: + + CurveCreator_UndoOptsDlg(QWidget* parent); + + ~CurveCreator_UndoOptsDlg(); + + void setUndoDepth(const int theDepth); + + int getUndoDepth() const; + + bool isEnabled() const; + + bool isUnlimited() const; + +private: + + void init(); + + void setTabOrder(); + +private slots: + + void optionChanged(int theId); + + void accept(); + +protected: + + int myUndoDepth; + QButtonGroup *myOptsBtnGrp; + QLineEdit *myBufferSizeEdit; + QPushButton *myOkBtn; + QPushButton *myCancelBtn; + +}; + +#endif diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx new file mode 100644 index 000000000..b6e0e85cf --- /dev/null +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -0,0 +1,942 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "CurveCreator_Widget.h" +#include "CurveCreator_TreeView.h" +#include "CurveCreator_Curve.hxx" +#include "CurveCreator_CurveEditor.hxx" +#include "CurveCreator.hxx" +#include "CurveCreator_NewPointDlg.h" +#include "CurveCreator_NewSectionDlg.h" + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, + CurveCreator_Curve *theCurve, + Qt::WindowFlags fl) : + QWidget(parent), myNewPointEditor(NULL), myNewSectionEditor(NULL), myEdit(NULL), myCurve(theCurve) +{ + if( myCurve ) + myEdit = new CurveCreator_CurveEditor( myCurve ); + + CurveCreator::Dimension aDim = CurveCreator::Dim2d; + if( myCurve ) + aDim = myCurve->getDimension(); + myNewPointEditor = new CurveCreator_NewPointDlg( aDim, this ); + myNewPointEditor->hide(); +// connect( myNewPointEditor, SIGNAL(addPoint()), this, SLOT(onAddNewPoint()) ); + connect( myNewPointEditor, SIGNAL(modifyPoint()), this, SLOT(onModifyPoint()) ); + connect( myNewPointEditor, SIGNAL(cancelPoint()), this, SLOT(onCancelPoint()) ); + + myNewSectionEditor = new CurveCreator_NewSectionDlg( this ); + myNewSectionEditor->hide(); + connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) ); + connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) ); + connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) ); + + QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this); + + mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup); + connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) ); + connect( mySectionView, SIGNAL(pointEntered(int,int)), this, SLOT(onEditPoint(int,int)) ); + connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) ); + connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) ); + QToolBar* aTB = new QToolBar(tr("TOOL_BAR_TLT"), aSectionGroup); +// QToolButton* anUndoBtn = new QToolButton(aTB); + + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap anUndoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_UNDO"))); + QPixmap aRedoPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_REDO"))); + QPixmap aNewSectionPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_SECTION"))); + QPixmap aNewPointPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_NEW_POINT"))); + QPixmap anEditPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS"))); + QPixmap aDetectPointsPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_EDIT_POINTS"))); + QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE"))); + QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); + QPixmap aRemovePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_DELETE"))); + QPixmap aJoinPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_JOIN"))); + QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP"))); + QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN"))); + +/* QPixmap anUndoPixmap = QPixmap(tr(":images/ICON_UNDO")); + QPixmap aRedoPixmap = QPixmap(tr(":images/ICON_REDO")); + QPixmap aNewSectionPixmap = QPixmap(tr(":images/ICON_NEW_SECTION")); + QPixmap aNewPointPixmap = QPixmap(tr(":images/ICON_NEW_POINT")); + QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE")); + QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE")); + QPixmap aRemovePixmap = QPixmap(tr(":images/ICON_REMOVE")); + QPixmap aJoinPixmap = QPixmap(tr(":images/ICON_JOIN")); + QPixmap aStepUpPixmap = QPixmap(tr(":images/ICON_STEP_UP")); + QPixmap aStepDownPixmap = QPixmap(tr(":images/ICON_STEP_DOWN"));*/ + + QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Z) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onUndo()) ); + aTB->addAction(anAct); + + anAct = createAction( REDO_ID, tr("REDO"), aRedoPixmap, tr("REDO_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Y) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onRedo()) ); + aTB->addAction(anAct); + + aTB->addSeparator(); + + anAct = createAction( NEW_SECTION_ID, tr("NEW_SECTION"), aNewSectionPixmap, tr("NEW_SECTION_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_N) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onNewSection()) ); + aTB->addAction(anAct); + aTB->addSeparator(); + + anAct = createAction( INSERT_SECTION_BEFORE_ID, tr("INSERT_SECTION_BEFORE"), QPixmap(), + tr("INSERT_SECTION_BEFORE_TLT"), + QKeySequence(Qt::ControlModifier | Qt::Key_Insert ) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionBefore()) ); + + anAct = createAction( INSERT_SECTION_AFTER_ID, tr("INSERT_SECTION_AFTER"), QPixmap(), + tr("INSERT_SECTION_AFTER_TLT"), + QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Insert ) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertSectionAfter()) ); + + anAct = createAction( ADDITION_MODE_ID, tr("ADDITION_MODE"), aNewPointPixmap, tr("ADDITION_MODE_TLT"), + QKeySequence() ); + anAct->setCheckable(true); + connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onAdditionMode(bool)) ); + connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) ); + aTB->addAction(anAct); + + anAct = createAction( MODIFICATION_MODE_ID, tr("MODIFICATION_MODE"), anEditPointsPixmap, tr("MODIFICATION_MODE_TLT"), + QKeySequence() ); + anAct->setCheckable(true); + connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onModificationMode(bool)) ); + connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) ); + aTB->addAction(anAct); + + anAct = createAction( DETECTION_MODE_ID, tr("DETECTION_MODE"), aDetectPointsPixmap, tr("DETECTION_MODE_TLT"), + QKeySequence() ); + anAct->setCheckable(true); + connect(anAct, SIGNAL(triggered(bool)), this, SLOT(onDetectPoints(bool)) ); + connect(anAct, SIGNAL(toggled(bool)), this, SLOT(onModeChanged(bool)) ); + aTB->addAction(anAct); + + anAct = createAction( INSERT_POINT_BEFORE_ID, tr("INSERT_POINT_BEFORE"), QPixmap(), + tr("INSERT_POINT_BEFORE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_B) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointBefore()) ); + + anAct = createAction( INSERT_POINT_AFTER_ID, tr("INSERT_POINT_AFTER"), QPixmap(), + tr("INSERT_POINT_AFTER_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_M) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onInsertPointAfter()) ); + + anAct = createAction( CLOSE_SECTIONS_ID, tr("CLOSE_SECTIONS"), QPixmap(), tr("CLOSE_SECTIONS_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_W) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onCloseSections()) ); + + anAct = createAction( UNCLOSE_SECTIONS_ID, tr("UNCLOSE_SECTIONS"), QPixmap(), + tr("UNCLOSE_SECTIONS_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_S) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onUncloseSections()) ); + + anAct = createAction( SET_SECTIONS_POLYLINE_ID, tr("SET_SECTIONS_POLYLINE"), + aPolylinePixmap, tr("SET_POLYLINE_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_E) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onSetPolyline()) ); + + anAct = createAction( SET_SECTIONS_SPLINE_ID, tr("SET_SECTIONS_SPLINE"), aSplinePixmap, + tr("SET_SPLINE_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_R) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onSetSpline()) ); + + anAct = createAction( REMOVE_ID, tr("REMOVE"), aRemovePixmap, tr("REMOVE_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) ); + aTB->addAction(anAct); + aTB->addSeparator(); + + anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) ); + connect( anAct, SIGNAL(triggered()), this, SLOT(onJoin()) ); + aTB->addAction(anAct); + aTB->addSeparator(); + + anAct = createAction( UP_ID, tr("STEP_UP"), aStepUpPixmap, tr("STEP_UP_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_Up ) ); + connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveUp()) ); + + anAct = createAction( DOWN_ID, tr("STEP_DOWN"), aStepDownPixmap, tr("STEP_DOWN"), + QKeySequence(Qt::ControlModifier|Qt::Key_Down ) ); + connect( anAct, SIGNAL(triggered()), this, SLOT(onMoveDown()) ); + + anAct = createAction( CLEAR_ALL_ID, tr("CLEAR_ALL"), QPixmap(), tr("CLEAR_ALL_TLT"), + QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Delete ) ); + connect( anAct, SIGNAL(triggered()), this, SLOT( onClearAll()) ); + + anAct = createAction( JOIN_ALL_ID, tr("JOIN_ALL"), QPixmap(), tr("JOIN_ALL_TLT"), + QKeySequence(Qt::ControlModifier | Qt::ShiftModifier | Qt::Key_Plus ) ); + connect( anAct, SIGNAL(triggered()), this, SLOT(onJoinAll()) ); + + QVBoxLayout* aSectLayout = new QVBoxLayout(); + aSectLayout->setMargin( 5 ); + aSectLayout->setSpacing( 5 ); + aSectLayout->addWidget(aTB); + aSectLayout->addWidget(mySectionView); + aSectionGroup->setLayout(aSectLayout); + QVBoxLayout* aLay = new QVBoxLayout(); + aLay->setMargin( 0 ); + aLay->setSpacing( 5 ); +// aLay->addLayout(aNameLayout); + aLay->addWidget(aSectionGroup); + setLayout(aLay); + onSelectionChanged(); +} + +void CurveCreator_Widget::setCurve( CurveCreator_Curve* theCurve ) +{ + if( myEdit != NULL ){ + delete myEdit; + myEdit = NULL; + } + myCurve = theCurve; + mySectionView->setCurve(myCurve); + if( myCurve != NULL ){ + myEdit = new CurveCreator_CurveEditor(myCurve); + } + onSelectionChanged(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onSelectionChanged() +{ + QList anEnabledAct; + if( myCurve ){ + anEnabledAct << NEW_SECTION_ID; + QList aSelSections = mySectionView->getSelectedSections(); + QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints(); + CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType(); + switch( aSelType ){ + case CurveCreator_TreeView::ST_NOSEL:{ + break; + } + case CurveCreator_TreeView::ST_SECTIONS:{ + /*if( aSelSections[0] > 0 ){ + anEnabledAct << UP_ID; + }*/ + if( aSelSections.size() == 1 ){ + anEnabledAct << ADDITION_MODE_ID << MODIFICATION_MODE_ID << DETECTION_MODE_ID; + } + if (myActionMap[ADDITION_MODE_ID]->isChecked()) { + mySection = -1; + myPointNum = -1; + QList aSelSection = mySectionView->getSelectedSections(); + if( aSelSection.size() > 0 ){ + mySection = aSelSection[0]; + myPointNum = myCurve->getNbPoints(mySection); + } + } else if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) { + anEnabledAct << REMOVE_ID; + anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID; + int aSectCnt = myCurve->getNbSections(); + if( aSectCnt > 0 ) + anEnabledAct << CLEAR_ALL_ID; + if( aSectCnt > 1 ) + anEnabledAct << JOIN_ALL_ID; + if( aSelSections.size() > 1 ){ + anEnabledAct << JOIN_ID; + } + } else if (myActionMap[DETECTION_MODE_ID]->isChecked()) { + } else { //no active mode + } + /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){ + anEnabledAct << DOWN_ID; + }*/ + break; + } + /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{ + if( aSelPoints[0].second > 0 ){ + anEnabledAct << UP_ID; + } + int aLastIndex = aSelPoints.size()-1; + int aSect = aSelPoints[0].first; + if( aSelPoints[aLastIndex].second < (myCurve->getNbPoints(aSect) - 1)){ + anEnabledAct << DOWN_ID; + } + if( aSelPoints.size() == 1){ + anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID; + } + break; + }*/ + + } + + /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size(); + if( aSelObjsCnt > 0 ){ + anEnabledAct << REMOVE_ID; + } + if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){ + anEnabledAct << REMOVE_ALL_ID; + }*/ + if( myCurve->getNbSections() > 1 ){ + anEnabledAct << JOIN_ALL_ID; + } + } + QList anIds = myActionMap.keys(); + for( int i = 0 ; i < anIds.size() ; i++ ){ + if( myActionMap.contains(anIds[i]) ){ + if( anEnabledAct.contains(anIds[i]) ){ + myActionMap[anIds[i]]->setEnabled(true); + } + else{ + myActionMap[anIds[i]]->setEnabled(false); + } + } + } + emit selectionChanged(); +} + +void CurveCreator_Widget::onAdditionMode(bool checked) +{ + if( !myEdit ) + return; + + SUIT_ViewWindow* aViewWindow = 0; + SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy(); + if ( activeStudy ) + aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + if ( aViewWindow == 0 ) + return; + SUIT_ViewManager* aViewManager = aViewWindow->getViewManager(); + + if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) { + if (checked) { + connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onGetPointByClick( SUIT_ViewWindow*, QMouseEvent* ) ) ); + } else { + disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onGetPointByClick( SUIT_ViewWindow*, QMouseEvent* ) ) ); + return; + } + } + + mySection= -1; + myPointNum = -1; + QList aSelSection = mySectionView->getSelectedSections(); + if( aSelSection.size() > 0 ){ + mySection = aSelSection[0]; + } + else{ + QList< QPair > aSelPoints = mySectionView->getSelectedPoints(); + if( aSelPoints.size() > 0 ){ + mySection = aSelPoints[0].first; + myPointNum = aSelPoints[0].second + 1; + } + } +/* + QString aSectName; + if( mySection < 0 ){ + mySection = myCurve->getNbSections() - 1; + } + aSectName = QString::fromStdString( myCurve->getSectionName(mySection)); + if( myPointNum < 0 ){ + myPointNum = myCurve->getNbPoints(mySection); + } + myNewPointEditor->clear(); + myNewPointEditor->setEditMode(false); + myNewPointEditor->setSectionName(aSectName); + myNewPointEditor->setDimension(myCurve->getDimension()); +*/ +// emit subOperationStarted( myNewPointEditor ); +} + +void CurveCreator_Widget::onModificationMode(bool checked) +{ + SUIT_ViewWindow* aViewWindow = 0; + SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy(); + if ( activeStudy ) + aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + if ( aViewWindow == 0 ) + return; + SUIT_ViewManager* aViewManager = aViewWindow->getViewManager(); + if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) { + if (checked) { +// connect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ), +// this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) ); + connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) ); + } + else { +// disconnect( aViewManager, SIGNAL( mouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ), +// this, SLOT( onPointSelect( SUIT_ViewWindow*, QMouseEvent* ) ) ); + disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onPointDrag( SUIT_ViewWindow*, QMouseEvent* ) ) ); + return; + } + } +} + +void CurveCreator_Widget::onDetectPoints(bool checked) +{ +} + +void CurveCreator_Widget::onModeChanged(bool checked) +{ + if (checked) { + QAction* anAction = (QAction*)sender(); + switch(myActionMap.key(anAction)) { + case ADDITION_MODE_ID: + if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) + myActionMap[MODIFICATION_MODE_ID]->trigger(); + else if (myActionMap[DETECTION_MODE_ID]->isChecked()) + myActionMap[DETECTION_MODE_ID]->trigger(); + break; + case MODIFICATION_MODE_ID: + if (myActionMap[ADDITION_MODE_ID]->isChecked()) + myActionMap[ADDITION_MODE_ID]->trigger(); + else if (myActionMap[DETECTION_MODE_ID]->isChecked()) + myActionMap[DETECTION_MODE_ID]->trigger(); + break; + case DETECTION_MODE_ID: + if (myActionMap[ADDITION_MODE_ID]->isChecked()) + myActionMap[ADDITION_MODE_ID]->trigger(); + else if (myActionMap[MODIFICATION_MODE_ID]->isChecked()) + myActionMap[MODIFICATION_MODE_ID]->trigger(); + break; + } + } + onSelectionChanged(); +} + +void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords) +{ + if( !myEdit ) + return; +// CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates(); + myEdit->insertPoints(theCoords, mySection, myPointNum ); + mySectionView->pointsAdded( mySection, myPointNum ); +// myNewPointEditor->clear(); + myPointNum++; + onSelectionChanged(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onNewSection() +{ + if( !myEdit ) + return; + myNewSectionEditor->clear(); + myNewSectionEditor->setEditMode(false); + QString aSectName = QString( myCurve->getUnicSectionName().c_str() ); + myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline ); + emit subOperationStarted( myNewSectionEditor ); +} + +void CurveCreator_Widget::onAddNewSection() +{ + if( !myEdit ) + return; + CurveCreator::Coordinates aCoords; + myEdit->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(), + myNewSectionEditor->isClosed(), aCoords ); + mySectionView->sectionAdded( mySection ); + QString aNewName = QString(myCurve->getUnicSectionName().c_str()); + myNewSectionEditor->setSectionName(aNewName); + mySection++; + onSelectionChanged(); + updateUndoRedo(); + onCancelSection(); +} + +void CurveCreator_Widget::onCancelPoint() +{ + emit subOperationFinished( myNewPointEditor ); +} + +void CurveCreator_Widget::onCancelSection() +{ + emit subOperationFinished( myNewSectionEditor ); +} + +QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage, + const QString& theToolTip, const QKeySequence& theShortcut ) +{ + QAction* anAct = new QAction(theName,this); + if( !theImage.isNull() ){ + anAct->setIcon(theImage); + } + anAct->setShortcut(theShortcut); + anAct->setToolTip(theToolTip); + myActionMap[theId] = anAct; + return anAct; +} + +QAction* CurveCreator_Widget::getAction(ActionId theId) +{ + if( myActionMap.contains(theId) ) + return myActionMap[theId]; + return NULL; +} + +void CurveCreator_Widget::onEditSection( int theSection ) +{ + if( !myEdit ) + return; + mySection = theSection; + QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection)); + bool isClosed = myCurve->isClosed(theSection); + CurveCreator::Type aType = myCurve->getType(theSection); + myNewSectionEditor->setEditMode(true); + myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType ); + + emit subOperationStarted( myNewSectionEditor ); +} + +void CurveCreator_Widget::onModifySection() +{ + if( !myEdit ) + return; + QString aName = myNewSectionEditor->getName(); + bool isClosed = myNewSectionEditor->isClosed(); + CurveCreator::Type aSectType = myNewSectionEditor->getSectionType(); + myEdit->startOperation(); + myEdit->setClosed( isClosed, mySection ); + myEdit->setName( aName.toStdString(), mySection ); + myEdit->setType( aSectType, mySection ); + myEdit->finishOperation(); + mySectionView->sectionChanged(mySection); + updateUndoRedo(); + onCancelSection(); +} + +void CurveCreator_Widget::onEditPoint( int theSection, int thePoint ) +{ + if( !myNewPointEditor || !myEdit ) + return; + mySection = theSection; + myPointNum = thePoint; + QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection)); + myNewPointEditor->setEditMode(true); + myNewPointEditor->setSectionName(aSectName); + myNewPointEditor->setDimension( myCurve->getDimension() ); + CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint); + myNewPointEditor->setCoordinates(aCoords); + emit subOperationStarted( myNewPointEditor ); +} + +void CurveCreator_Widget::onModifyPoint() +{ + if( !myEdit ) + return; + CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates(); + myEdit->setCoordinates( aCoords, mySection, myPointNum ); + mySectionView->pointDataChanged( mySection, myPointNum ); + updateUndoRedo(); + onCancelPoint(); +} + +void CurveCreator_Widget::onJoin() +{ + if( !myEdit ) + return; + QList aSections = mySectionView->getSelectedSections(); + if( aSections.size() == 0 ){ + return; + } + int aMainSect = aSections[0]; + int aMainSectSize = myCurve->getNbPoints(aMainSect); + myEdit->startOperation(); + for( int i = 1 ; i < aSections.size() ; i++ ){ + int aSectNum = aSections[i] - (i-1); + myEdit->join( aMainSect, aSectNum ); + mySectionView->sectionsRemoved( aSectNum ); + } + myEdit->finishOperation(); + int aNewSectSize = myCurve->getNbPoints(aMainSect); + if( aNewSectSize != aMainSectSize ) + mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize ); + updateUndoRedo(); +} + +void CurveCreator_Widget::onRemove() +{ + if( !myEdit ) + return; + QList< QPair > aSelPoints = mySectionView->getSelectedPoints(); + int aCurrSect=-1; + int aRemoveCnt = 0; + myEdit->startOperation(); + for( int i = 0 ; i < aSelPoints.size() ; i++ ){ + if( aCurrSect != aSelPoints[i].first ){ + aRemoveCnt = 0; + aCurrSect = aSelPoints[i].first; + } + int aPntIndx = aSelPoints[i].second - aRemoveCnt; + myEdit->removePoints(aCurrSect,aPntIndx, 1); + mySectionView->pointsRemoved( aCurrSect, aPntIndx ); + aRemoveCnt++; + } + QList aSections = mySectionView->getSelectedSections(); + for( int i = 0 ; i < aSections.size() ; i++ ){ + int aSectNum = aSections[i] - (i); + myEdit->removeSection( aSectNum ); + mySectionView->sectionsRemoved( aSectNum ); + } + myEdit->finishOperation(); + mySectionView->clearSelection(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onMoveUp() +{ + if( !myEdit ) + return; + if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){ + //Move sections + QList aSections = mySectionView->getSelectedSections(); + for( int i = 0 ; i < aSections.size() ; i++ ){ + int anIndx = aSections[i]; + myEdit->moveSection( anIndx, anIndx-1); + mySectionView->sectionsSwapped( anIndx, -1 ); + } + } + else{ + //Move points + QList< QPair > aPoints = mySectionView->getSelectedPoints(); + for( int i = 0 ; i < aPoints.size() ; i++ ){ + int aSection = aPoints[i].first; + int aPoint = aPoints[i].second; + myEdit->movePoint(aSection, aPoint, aPoint-2); + mySectionView->pointsSwapped( aSection, aPoint, -1 ); + } + } + updateUndoRedo(); +} + +void CurveCreator_Widget::onMoveDown() +{ + if( !myEdit ) + return; + if( mySectionView->getSelectionType() == CurveCreator_TreeView::ST_SECTIONS ){ + //Move sections + QList aSections = mySectionView->getSelectedSections(); + for( int i = aSections.size()-1 ; i >=0 ; i-- ){ + int anIndx = aSections[i]; + myEdit->moveSection( anIndx, anIndx+1); + mySectionView->sectionsSwapped( anIndx, 1 ); + } + } + else{ + //Move points + QList< QPair > aPoints = mySectionView->getSelectedPoints(); + for( int i = aPoints.size() - 1; i >= 0 ; i-- ){ + int aSection = aPoints[i].first; + int aPoint = aPoints[i].second; + myEdit->movePoint(aSection, aPoint, aPoint+1); + mySectionView->pointsSwapped( aSection, aPoint, 1 ); + } + } + updateUndoRedo(); +} + +void CurveCreator_Widget::onClearAll() +{ + if( !myEdit ) + return; + myEdit->clear(); + mySectionView->reset(); + onSelectionChanged(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onJoinAll() +{ + if( !myEdit ) + return; + myEdit->join(); + mySectionView->reset(); + onSelectionChanged(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onInsertSectionBefore() +{ + +} + +void CurveCreator_Widget::onInsertSectionAfter() +{ + +} + +void CurveCreator_Widget::onInsertPointBefore() +{ + +} + +void CurveCreator_Widget::onInsertPointAfter() +{ + +} + +void CurveCreator_Widget::onUndoSettings() +{ + +} + +void CurveCreator_Widget::onSetSpline() +{ + if( !myEdit ) + return; + QList aSelSections = mySectionView->getSelectedSections(); + myEdit->startOperation(); + for( int i = 0 ; i < aSelSections.size() ; i++ ){ + myEdit->setType(CurveCreator::BSpline, aSelSections[i]); + mySectionView->sectionChanged(aSelSections[i]); + } + myEdit->finishOperation(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onSetPolyline() +{ + if( !myEdit ) + return; + myEdit->startOperation(); + QList aSelSections = mySectionView->getSelectedSections(); + for( int i = 0 ; i < aSelSections.size() ; i++ ){ + myEdit->setType(CurveCreator::Polyline, aSelSections[i]); + mySectionView->sectionChanged(aSelSections[i]); + } + myEdit->finishOperation(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onCloseSections() +{ + if( !myEdit ) + return; + myEdit->startOperation(); + QList aSelSections = mySectionView->getSelectedSections(); + for( int i = 0 ; i < aSelSections.size() ; i++ ){ + myEdit->setClosed(true, aSelSections[i]); + mySectionView->sectionChanged(aSelSections[i]); + } + myEdit->finishOperation(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onUncloseSections() +{ + if( !myEdit ) + return; + myEdit->startOperation(); + QList aSelSections = mySectionView->getSelectedSections(); + for( int i = 0 ; i < aSelSections.size() ; i++ ){ + myEdit->setClosed(false, aSelSections[i]); + mySectionView->sectionChanged(aSelSections[i]); + } + myEdit->finishOperation(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onUndo() +{ + if( !myEdit ) + return; + myEdit->undo(); + mySectionView->reset(); + updateUndoRedo(); +} + +void CurveCreator_Widget::onRedo() +{ + if( !myEdit ) + return; + myEdit->redo(); + mySectionView->reset(); + updateUndoRedo(); +} + +void CurveCreator_Widget::updateUndoRedo() +{ + QAction* anAct = myActionMap[UNDO_ID]; + if( anAct != 0 ){ + if( myEdit->getNbUndo() != 0 ){ + anAct->setEnabled(true); + } + else{ + anAct->setDisabled(true); + } + } + anAct = myActionMap[REDO_ID]; + if( anAct != 0 ){ + if( myEdit->getNbRedo() != 0 ){ + anAct->setEnabled(true); + } + else{ + anAct->setDisabled(true); + } + } +} + +void CurveCreator_Widget::onContextMenu( QPoint thePoint ) +{ + QList aContextActions; + aContextActions << CLEAR_ALL_ID << JOIN_ALL_ID << SEPARATOR_ID << + CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << + SET_SECTIONS_SPLINE_ID; + QPoint aGlPoint = mySectionView->mapToGlobal(thePoint); + bool isVis = false; + QList aResAct; + for( int i = 0 ; i < aContextActions.size() ; i++ ){ + if( aContextActions[i] != SEPARATOR_ID ){ + if( myActionMap.contains(aContextActions[i]) ){ + QAction* anAct = myActionMap[aContextActions[i]]; + if( anAct->isEnabled() ){ + aResAct << aContextActions[i]; + isVis = true; + } + } + } + else{ + aResAct << SEPARATOR_ID; + } + } + if( !isVis ) + return; + + QMenu* aMenu = new QMenu(this); + for( int i = 0 ; i < aResAct.size() ; i++ ){ + if( aResAct[i] == SEPARATOR_ID ){ + aMenu->addSeparator(); + } + else{ + QAction* anAct = myActionMap[aResAct[i]]; + aMenu->insertAction(NULL, anAct); + } + } + aMenu->exec(aGlPoint); +} + +QList CurveCreator_Widget::getSelectedSections() +{ + return mySectionView->getSelectedSections(); +} + +QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints() +{ + return mySectionView->getSelectedPoints(); +} + +bool CurveCreator_Widget::isInstantSketchingEnabled() const +{ + if( myNewPointEditor ) + return myNewPointEditor->isInstantSketchingEnabled(); + return false; +} + +void CurveCreator_Widget::setInstantSketchingEnabled( const bool theState ) +{ + if( myNewPointEditor ) + myNewPointEditor->setInstantSketchingEnabled( theState ); +} + +//================================================================================= +// function : GeometryGUI::onGetPointByClick() +// purpose : Manage mouse press events in Additon mode +//================================================================================= +void CurveCreator_Widget::onGetPointByClick( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe ) +{ + if ( myNewPointEditor && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && + pe->modifiers() != Qt::ControlModifier ) { + OCCViewer_Viewer* anOCCViewer = + ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); + + gp_Pnt aPnt; + + ic->InitSelected(); + if ( pe->modifiers() == Qt::ShiftModifier ) + ic->ShiftSelect(); // Append selection + else + ic->Select(); // New selection + + /*TopoDS_Shape aShape; + + ic->InitSelected(); + if ( ic->MoreSelected() ) + aShape = ic->SelectedShape(); + + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); + else*/ + { + OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); + aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + } + // set the coordinates into dialog + CurveCreator::Coordinates aCoords; + aCoords.push_back( aPnt.X() ); + aCoords.push_back( aPnt.Y() ); + if ( myCurve->getDimension() == 3 ) { + aCoords.push_back( aPnt.Z() ); + } + onAddNewPoint(aCoords); +// myNewPointEditor->setCoordinates( aCoords ); + } +} + +//================================================================================= +// function : GeometryGUI::onPointDrag() +// purpose : Manage mouse move events in Modification mode +//================================================================================= +void CurveCreator_Widget::onPointDrag( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe ) +{ + if ( !(pe->buttons() & Qt::LeftButton) ) + return; + if ( (pe->pos() - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() ) + return; +/* + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setData(mimeType, data); + drag->setMimeData(mimeData); + + Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction); + */ +} diff --git a/src/CurveCreator/CurveCreator_Widget.h b/src/CurveCreator/CurveCreator_Widget.h new file mode 100644 index 000000000..b91e8691b --- /dev/null +++ b/src/CurveCreator/CurveCreator_Widget.h @@ -0,0 +1,120 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef CURVECREATOR_WIDGET_H +#define CURVECREATOR_WIDGET_H + +#include "CurveCreator_Curve.hxx" +#include "CurveCreator.hxx" + +#include +#include + +#include + +class QAction; +class QPixmap; +class CurveCreator_CurveEditor; +class CurveCreator_TreeView; +class CurveCreator_NewPointDlg; +class CurveCreator_NewSectionDlg; + +class CURVECREATOR_EXPORT CurveCreator_Widget : public QWidget +{ + Q_OBJECT +public: + explicit CurveCreator_Widget( QWidget* parent, + CurveCreator_Curve *theCurve, + Qt::WindowFlags fl=0 ); + + void setCurve( CurveCreator_Curve* theCurve ); + + QList getSelectedSections(); + QList< QPair< int, int > > getSelectedPoints(); + + bool isInstantSketchingEnabled() const; + void setInstantSketchingEnabled( const bool theState ); + +signals: + void selectionChanged(); + void subOperationStarted( QWidget* ); + void subOperationFinished( QWidget* ); + +public slots: + +protected slots: + void onAdditionMode(bool checked); + void onModificationMode(bool checked); + void onDetectPoints(bool checked); + void onModeChanged(bool checked); + void onNewSection(); + void onSelectionChanged(); + void onAddNewPoint(const CurveCreator::Coordinates& theCoords); + void onAddNewSection(); + void onEditSection( int theSection ); + void onEditPoint( int theSection, int thePoint ); + void onModifyPoint(); + void onModifySection(); + void onCancelPoint(); + void onCancelSection(); + void onJoin(); + void onRemove(); + void onMoveUp(); + void onMoveDown(); + void onClearAll(); + void onJoinAll(); + void onInsertSectionBefore(); + void onInsertSectionAfter(); + void onSetSpline(); + void onSetPolyline(); + void onCloseSections(); + void onUncloseSections(); + void onInsertPointBefore(); + void onInsertPointAfter(); + void onUndo(); + void onRedo(); + void onUndoSettings(); + void onContextMenu(QPoint thePoint); + void onGetPointByClick( SUIT_ViewWindow*, QMouseEvent* ); +// void onPointSelect( SUIT_ViewWindow*, QMouseEvent* ); + void onPointDrag( SUIT_ViewWindow*, QMouseEvent* ); +protected: + enum ActionId{ UNDO_ID, REDO_ID, NEW_SECTION_ID, ADDITION_MODE_ID, REMOVE_ID, REMOVE_ALL_ID, JOIN_ID, + JOIN_ALL_ID, UP_ID, DOWN_ID, INSERT_SECTION_BEFORE_ID, INSERT_SECTION_AFTER_ID, + INSERT_POINT_BEFORE_ID, INSERT_POINT_AFTER_ID, CLOSE_SECTIONS_ID, UNCLOSE_SECTIONS_ID, + SET_SECTIONS_POLYLINE_ID, SET_SECTIONS_SPLINE_ID, CLEAR_ALL_ID, SEPARATOR_ID, + MODIFICATION_MODE_ID, DETECTION_MODE_ID }; +private: + QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage, + const QString& theToolTip, const QKeySequence& theShortcut ); + QAction* getAction(ActionId theId); + void updateUndoRedo(); +private: + QMap myActionMap; + CurveCreator_Curve* myCurve; + CurveCreator_CurveEditor* myEdit; + CurveCreator_TreeView* mySectionView; + CurveCreator_NewPointDlg* myNewPointEditor; + CurveCreator_NewSectionDlg* myNewSectionEditor; + int mySection; + int myPointNum; + QPoint myDragStartPosition; +}; + +#endif // CURVECREATOR_WIDGET_H diff --git a/src/EntityGUI/CMakeLists.txt b/src/EntityGUI/CMakeLists.txt index 27ccc7bd2..510546716 100755 --- a/src/EntityGUI/CMakeLists.txt +++ b/src/EntityGUI/CMakeLists.txt @@ -35,6 +35,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src/OBJECT ${PROJECT_SOURCE_DIR}/src/GEOMClient + ${PROJECT_SOURCE_DIR}/src/GEOMUtils ${PROJECT_SOURCE_DIR}/src/GEOMImpl ${PROJECT_SOURCE_DIR}/src/GEOMGUI ${PROJECT_SOURCE_DIR}/src/GEOMBase @@ -58,6 +59,7 @@ ADD_DEFINITIONS( SET(_link_LIBRARIES GEOMObject GEOMClient + GEOMUtils GEOMImpl GEOMBase GEOM diff --git a/src/EntityGUI/EntityGUI.cxx b/src/EntityGUI/EntityGUI.cxx index 8962ed0d6..b45d42774 100644 --- a/src/EntityGUI/EntityGUI.cxx +++ b/src/EntityGUI/EntityGUI.cxx @@ -28,6 +28,7 @@ #include "GeometryGUI.h" #include "GeometryGUI_Operations.h" +#include "GEOMUtils.hxx" #include #include @@ -231,7 +232,7 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi } else { OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); - aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); } Qt::KeyboardModifiers modifiers = pe->modifiers(); @@ -259,7 +260,7 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi else { OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); - aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); } // aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog @@ -296,7 +297,7 @@ bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_View { // QPoint end = QPoint(pe->x(),pe->y()); OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); - aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); aCornerDlg->setEndPnt( aPnt ); } } @@ -319,7 +320,7 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin if ( aSketcherDlg->acceptMouseEvent() ) { OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); - gp_Pnt aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); Qt::KeyboardModifiers modifiers = pe->modifiers(); if (QApplication::mouseButtons() == Qt::LeftButton ) @@ -330,32 +331,6 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin return false; } -//======================================================================= -// function : ConvertClickToPoint() -// purpose : Returns the point clicked in 3D view -//======================================================================= -gp_Pnt EntityGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) -{ - V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; - aView->Eye( XEye, YEye, ZEye ); - - aView->At( XAt, YAt, ZAt ); - gp_Pnt EyePoint( XEye, YEye, ZEye ); - gp_Pnt AtPoint( XAt, YAt, ZAt ); - - gp_Vec EyeVector( EyePoint, AtPoint ); - gp_Dir EyeDir( EyeVector ); - - gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir ); - Standard_Real X, Y, Z; - aView->Convert( x, y, X, Y, Z ); - gp_Pnt ConvertedPoint( X, Y, Z ); - - gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint ); - gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView ); - return ResultPoint; -} - //===================================================================================== // function : DisplaySimulationShape() // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape diff --git a/src/EntityGUI/EntityGUI.h b/src/EntityGUI/EntityGUI.h index 1b84b2901..ccf336999 100644 --- a/src/EntityGUI/EntityGUI.h +++ b/src/EntityGUI/EntityGUI.h @@ -32,7 +32,6 @@ #include #include -#include class TopoDS_Shape; @@ -52,8 +51,6 @@ public : bool OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow ); bool OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow ); - static gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ); - void DisplaySimulationShape( const TopoDS_Shape&, const TopoDS_Shape& ); void EraseSimulationShape(); diff --git a/src/GEOMBase/GEOMBase_Helper.cxx b/src/GEOMBase/GEOMBase_Helper.cxx index 28179f5a2..bd4a57f02 100755 --- a/src/GEOMBase/GEOMBase_Helper.cxx +++ b/src/GEOMBase/GEOMBase_Helper.cxx @@ -64,7 +64,7 @@ // Function : getActiveView // Purpose : Get active view window, returns 0 if no open study frame //================================================================ -static SUIT_ViewWindow* getActiveView() +SUIT_ViewWindow* GEOMBase_Helper::getActiveView() { SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy(); if ( activeStudy ) diff --git a/src/GEOMBase/GEOMBase_Helper.h b/src/GEOMBase/GEOMBase_Helper.h index 6b8fe6e04..5bafde6ff 100755 --- a/src/GEOMBase/GEOMBase_Helper.h +++ b/src/GEOMBase/GEOMBase_Helper.h @@ -61,6 +61,7 @@ class GEOMBASE_EXPORT GEOMBase_Helper public: GEOMBase_Helper( SUIT_Desktop* ); virtual ~GEOMBase_Helper(); + static SUIT_ViewWindow* getActiveView(); protected: static GEOM::GEOM_Gen_ptr getGeomEngine(); diff --git a/src/GEOMGUI/GEOM_images.ts b/src/GEOMGUI/GEOM_images.ts index 90d8f28ee..409484017 100644 --- a/src/GEOMGUI/GEOM_images.ts +++ b/src/GEOMGUI/GEOM_images.ts @@ -3,6 +3,62 @@ @default + + ICON_CC_ARROW_UP + arrow_up.png + + + ICON_CC_ARROW_DOWN + arrow_down.png + + + ICON_CC_CLOSED_POLYLINE + closedpolyline.png + + + ICON_CC_CLOSED_SPLINE + closedspline.png + + + ICON_CC_DELETE + delete.png + + + ICON_CC_JOIN + join2.png + + + ICON_CC_NEW_POINT + new_point.png + + + ICON_CC_NEW_SECTION + new_section.png + + + ICON_CC_EDIT_POINTS + edit_points.png + + + ICON_CC_POINT + point2.png + + + ICON_CC_POLYLINE + polyline.png + + + ICON_CC_REDO + redo.png + + + ICON_CC_SPLINE + spline.png + + + ICON_CC_UNDO + undo.png + ICON_FOLDER folder.png diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 2a878f5ba..d8efb145b 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -2348,6 +2348,10 @@ Please, select face, shell or solid and try again LIMIT_TOLERANCE_NEW_OBJ_NAME Limit_tolerance + + MEN_CURVE_CREATOR + Curve creator + MEN_ALL_SEL_ONLY Select All @@ -5014,6 +5018,14 @@ Ignoring units will cause model scaling (as dimensions are supposed to be specif TOOLS_IMPORTEXPORT Import / Export + + CC_PNT_ITEM_X_Y + X=%1, Y=%2 + + + CC_PNT_ITEM_X_Y_Z + X=%1, Y=%2, Z=%3 + BasicGUI_CurveDlg @@ -5255,6 +5267,262 @@ Ignoring units will cause model scaling (as dimensions are supposed to be specif Face 2 V + + CurveCreator_NewPointDlg + + ADD_NEW_POINT + Add new points + + + X_COORD + X + + + Y_COORD + Y + + + Z_COORD + Z + + + ADD_BTN + Add + + + ADD_CONTINUE_BTN + Add and continue + + + ADD_NEW_POINT_TO_%1 + Add new point to %1 + + + SET_POINT_COORDINATES + Set point coordinates + + + + CurveCreator_NewSectionDlg + + NAME + Name + + + LINE_TYPE + Type + + + POLYLINE_TYPE + Polyline + + + SPLINE_TYPE + Spline + + + LINE_CLOSED + Closed + + + OK + Ok + + + ADD_BTN + Add + + + ADD_CONTINUE_BTN + Add and continue + + + ADD_NEW_SECTION + Add new section + + + SET_SECTION_PARAMETERS + Set section parameters + + + + CurveCreator_TreeViewModel + + X=%1, Y=%2 + X=%1, Y=%2 + + + X=%1, Y=%2, Z=%3 + X=%1, Y=%2, Z=%3 + + + + CurveCreator_Widget + + CURVE_NAME_TLT + Name + + + SECTION_GROUP_TLT + Sections + + + UNDO + Undo + + + UNDO_TLT + Undo + + + REDO + Redo + + + REDO_TLT + Redo + + + NEW_SECTION + New section + + + NEW_SECTION_TLT + Insert new section + + + INSERT_SECTION_BEFORE + Insert section before + + + INSERT_SECTION_BEFORE_TLT + Insert section before + + + INSERT_SECTION_AFTER + Insert section after + + + INSERT_SECTION_AFTER_TLT + Insert section after + + + ADDITION_MODE + Addition mode + + + ADDITION_MODE_TLT + Addition mode + + + MODIFICATION_MODE + Modification mode + + + MODIFICATION_MODE_TLT + Modification mode + + + DETECTION_MODE + Detection mode + + + DETECTION_MODE_TLT + Detection mode + + + INSERT_POINT_BEFORE + Insert point before + + + INSERT_POINT_BEFORE_TLT + Insert point before + + + INSERT_POINT_AFTER + Insert point after + + + CLOSE_SECTIONS + Set closed + + + CLOSE_SECTIONS_TLT + Set selected sections closed + + + UNCLOSE_SECTIONS + Set open + + + UNCLOSE_SECTIONS_TLT + Set selected sections open + + + SET_SECTIONS_POLYLINE + Set polyline + + + SET_SECTIONS_POLYLINE_TLT + Set selected section type to polyline + + + SET_SECTIONS_SPLINE + Set spline + + + SET_SECTIONS_SPLINE_TLT + Set selected section type to spline + + + REMOVE + Remove + + + REMOVE_TLT + Remove + + + JOIN + Join + + + JOIN_TLT + Join selected sections + + + STEP_UP + Move up + + + STEP_UP_TLT + Move selected objects up + + + STEP_DOWN + Move down + + + STEP_DOWN_TLT + Move selected objects down + + + CLEAR_ALL + Clear all + + + CLEAR_ALL_TLT + Remove all objects + + + JOIN_ALL + Join all sections + + + JOIN_ALL_TLT + Join all sections + + EntityGUI_SketcherDlg diff --git a/src/GEOMGUI/GEOM_msg_fr.ts b/src/GEOMGUI/GEOM_msg_fr.ts index edcad8e0a..b2f9569f2 100644 --- a/src/GEOMGUI/GEOM_msg_fr.ts +++ b/src/GEOMGUI/GEOM_msg_fr.ts @@ -2354,6 +2354,10 @@ Choisissez une face, une coque ou un solide et essayez de nouveau LIMIT_TOLERANCE_NEW_OBJ_NAME Tolérance_limite + + MEN_CURVE_CREATOR + Curve creator + MEN_ALL_SEL_ONLY Sélectionner tout @@ -4951,6 +4955,14 @@ le paramètre '%1' aux préférences du module Géométrie.TOOLS_IMPORTEXPORT Import / Export + + CC_PNT_ITEM_X_Y + X=%1, Y=%2 + + + CC_PNT_ITEM_X_Y_Z + X=%1, Y=%2, Z=%3 + BasicGUI_CurveDlg @@ -5192,6 +5204,262 @@ le paramètre '%1' aux préférences du module Géométrie.Face 2 V + + CurveCreator_NewPointDlg + + ADD_NEW_POINT + Add new points + + + X_COORD + X + + + Y_COORD + Y + + + Z_COORD + Z + + + ADD_BTN + Add + + + ADD_CONTINUE_BTN + Add and continue + + + ADD_NEW_POINT_TO_%1 + Add new point to %1 + + + SET_POINT_COORDINATES + Set point coordinates + + + + CurveCreator_NewSectionDlg + + NAME + Name + + + LINE_TYPE + Type + + + POLYLINE_TYPE + Polyline + + + SPLINE_TYPE + Spline + + + LINE_CLOSED + Closed + + + OK + Ok + + + ADD_BTN + Add + + + ADD_CONTINUE_BTN + Add and continue + + + ADD_NEW_SECTION + Add new section + + + SET_SECTION_PARAMETERS + Set section parameters + + + + CurveCreator_TreeViewModel + + X=%1, Y=%2 + X=%1, Y=%2 + + + X=%1, Y=%2, Z=%3 + X=%1, Y=%2, Z=%3 + + + + CurveCreator_Widget + + CURVE_NAME_TLT + Name + + + SECTION_GROUP_TLT + Sections + + + UNDO + Undo + + + UNDO_TLT + Undo + + + REDO + Redo + + + REDO_TLT + Redo + + + NEW_SECTION + New section + + + NEW_SECTION_TLT + Insert new section + + + INSERT_SECTION_BEFORE + Insert section before + + + INSERT_SECTION_BEFORE_TLT + Insert section before + + + INSERT_SECTION_AFTER + Insert section after + + + INSERT_SECTION_AFTER_TLT + Insert section after + + + ADDITION_MODE + Addition mode + + + ADDITION_MODE_TLT + Addition mode + + + MODIFICATION_MODE + Modification mode + + + MODIFICATION_MODE_TLT + Modification mode + + + DETECTION_MODE + Detection mode + + + DETECTION_MODE_TLT + Detection mode + + + INSERT_POINT_BEFORE + Insert point before + + + INSERT_POINT_BEFORE_TLT + Insert point before + + + INSERT_POINT_AFTER + Insert point after + + + CLOSE_SECTIONS + Set closed + + + CLOSE_SECTIONS_TLT + Set selected sections closed + + + UNCLOSE_SECTIONS + Set open + + + UNCLOSE_SECTIONS_TLT + Set selected sections open + + + SET_SECTIONS_POLYLINE + Set polyline + + + SET_SECTIONS_POLYLINE_TLT + Set selected section type to polyline + + + SET_SECTIONS_SPLINE + Set spline + + + SET_SECTIONS_SPLINE_TLT + Set selected section type to spline + + + REMOVE + Remove + + + REMOVE_TLT + Remove + + + JOIN + Join + + + JOIN_TLT + Join selected sections + + + STEP_UP + Move up + + + STEP_UP_TLT + Move selected objects up + + + STEP_DOWN + Move down + + + STEP_DOWN_TLT + Move selected objects down + + + CLEAR_ALL + Clear all + + + CLEAR_ALL_TLT + Remove all objects + + + JOIN_ALL + Join all sections + + + JOIN_ALL_TLT + Join all sections + + EntityGUI_SketcherDlg diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index df17cd484..242524eb1 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -592,6 +592,10 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam ) case GEOMOp::OpSharedShapes: // MENU OPERATION - GET SHARED SHAPES case GEOMOp::OpExtrudedBoss: // MENU OPERATION - EXTRUDED BOSS case GEOMOp::OpExtrudedCut: // MENU OPERATION - EXTRUDED CUT +#ifdef DEBUG_CURVE_CREATOR + // for debug purposes, to be removed + case GEOMOp::OpCurveCreator: // MENU OPERATION - CURVE CREATOR +#endif libName = "OperationGUI"; break; case GEOMOp::OpSewing: // MENU REPAIR - SEWING @@ -958,6 +962,10 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpSharedShapes, "GET_SHARED_SHAPES" ); createGeomAction( GEOMOp::OpExtrudedCut, "EXTRUDED_CUT" ); createGeomAction( GEOMOp::OpExtrudedBoss, "EXTRUDED_BOSS" ); +#ifdef DEBUG_CURVE_CREATOR + // for debug purposes, to be removed + createGeomAction( GEOMOp::OpCurveCreator, "CURVE_CREATOR" ); +#endif createGeomAction( GEOMOp::OpFillet1d, "FILLET_1D" ); createGeomAction( GEOMOp::OpFillet2d, "FILLET_2D" ); @@ -1210,6 +1218,11 @@ void GeometryGUI::initialize( CAM_Application* app ) createMenu( GEOMOp::OpChamfer, operId, -1 ); createMenu( GEOMOp::OpExtrudedBoss, operId, -1 ); createMenu( GEOMOp::OpExtrudedCut, operId, -1 ); +#ifdef DEBUG_CURVE_CREATOR + // for debug purposes, to be removed + createMenu( separator(), operId, -1 ); + createMenu( GEOMOp::OpCurveCreator, operId, -1 ); +#endif //createMenu( GEOMOp::OpClipping, operId, -1 ); int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 ); @@ -1369,6 +1382,10 @@ void GeometryGUI::initialize( CAM_Application* app ) createTool( GEOMOp::OpChamfer, featTbId ); createTool( GEOMOp::OpExtrudedBoss, featTbId ); createTool( GEOMOp::OpExtrudedCut, featTbId ); +#ifdef DEBUG_CURVE_CREATOR + // for debug purposes, to be removed + createTool( GEOMOp::OpCurveCreator, featTbId ); +#endif int buildTbId = createTool( tr( "TOOL_BUILD" ) ); createTool( GEOMOp::OpEdge, buildTbId ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index 3deee9fe3..40c0e38cd 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -150,6 +150,10 @@ namespace GEOMOp { OpSharedShapes = 3708, // MENU OPERATION - GET SHARED SHAPES OpExtrudedBoss = 3709, // MENU OPERATION - ETRUDED BOSS OpExtrudedCut = 3710, // MENU OPERATION - ETRUDED CUT +#ifdef DEBUG_CURVE_CREATOR + OpCurveCreator = 3799, // MENU OPERATION - CURVE CREATOR +#endif + // for debug purposes, to be removed // RepairGUI -------------------//-------------------------------- OpSewing = 4000, // MENU REPAIR - SEWING OpSuppressFaces = 4001, // MENU REPAIR - SUPPRESS FACES diff --git a/src/GEOMUtils/CMakeLists.txt b/src/GEOMUtils/CMakeLists.txt index bc8b144d1..1b46c16a7 100755 --- a/src/GEOMUtils/CMakeLists.txt +++ b/src/GEOMUtils/CMakeLists.txt @@ -38,6 +38,7 @@ SET(_link_LIBRARIES ${CAS_TKTopAlgo} ${CAS_TKG2d} ${CAS_TKG3d} + ${CAS_TKV3d} ${KERNEL_SALOMELocalTrace} ) diff --git a/src/GEOMUtils/GEOMUtils.cxx b/src/GEOMUtils/GEOMUtils.cxx index 54a7467f6..4992b8752 100644 --- a/src/GEOMUtils/GEOMUtils.cxx +++ b/src/GEOMUtils/GEOMUtils.cxx @@ -83,6 +83,9 @@ #include #include +#include +#include + #include #include @@ -951,3 +954,29 @@ Standard_Real GEOMUtils::GetMinDistance return aResult; } + +//======================================================================= +// function : ConvertClickToPoint() +// purpose : Returns the point clicked in 3D view +//======================================================================= +gp_Pnt GEOMUtils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) +{ + V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; + aView->Eye( XEye, YEye, ZEye ); + + aView->At( XAt, YAt, ZAt ); + gp_Pnt EyePoint( XEye, YEye, ZEye ); + gp_Pnt AtPoint( XAt, YAt, ZAt ); + + gp_Vec EyeVector( EyePoint, AtPoint ); + gp_Dir EyeDir( EyeVector ); + + gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir ); + Standard_Real X, Y, Z; + aView->Convert( x, y, X, Y, Z ); + gp_Pnt ConvertedPoint( X, Y, Z ); + + gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint ); + gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView ); + return ResultPoint; +} diff --git a/src/GEOMUtils/GEOMUtils.hxx b/src/GEOMUtils/GEOMUtils.hxx index 1b0327e46..2c3f5f1af 100644 --- a/src/GEOMUtils/GEOMUtils.hxx +++ b/src/GEOMUtils/GEOMUtils.hxx @@ -34,6 +34,8 @@ #include #include +#include + #include #include @@ -174,6 +176,16 @@ class GEOMUtils { const TopoDS_Shape& theShape2, gp_Pnt& thePnt1, gp_Pnt& thePnt2); + /*! + * \brief Returns the point clicked in 3D view. + * + * \param x The X coordinate in the view. + * \param y The Y coordinate in the view. + * \param theView View where the given point takes place. + * \retval gp_Pnt Returns the point clicked in 3D view + */ + Standard_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) theView ); + }; #endif diff --git a/src/OperationGUI/CMakeLists.txt b/src/OperationGUI/CMakeLists.txt index 059c54a08..e525a8658 100755 --- a/src/OperationGUI/CMakeLists.txt +++ b/src/OperationGUI/CMakeLists.txt @@ -45,6 +45,11 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ) +IF(SALOME_GEOM_DEBUG_CC) + # for debug purposes, to be removed + INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/CurveCreator) +ENDIF() + # additional preprocessor / compiler flags ADD_DEFINITIONS( ${CAS_DEFINITIONS} @@ -56,6 +61,10 @@ ADD_DEFINITIONS( SET(_link_LIBRARIES GEOMBase ) +IF(SALOME_GEOM_DEBUG_CC) + # for debug purposes, to be removed + LIST(APPEND _link_LIBRARIES CurveCreator) +ENDIF() # --- resources --- diff --git a/src/OperationGUI/OperationGUI.cxx b/src/OperationGUI/OperationGUI.cxx index 84a1c427c..e172789db 100644 --- a/src/OperationGUI/OperationGUI.cxx +++ b/src/OperationGUI/OperationGUI.cxx @@ -29,7 +29,9 @@ #include #include +#include #include +#include #include #include @@ -45,6 +47,13 @@ #include "OperationGUI_GetSharedShapesDlg.h" #include "OperationGUI_ExtrudedFeatureDlg.h" // Methods EXTRUDED BOSS / CUT +#ifdef DEBUG_CURVE_CREATOR +// for debug purposes, to be removed +#include "CurveCreator_Widget.h" +#include +#include +#endif + //======================================================================= // function : OperationGUI() // purpose : Constructor @@ -86,6 +95,36 @@ bool OperationGUI::OnGUIEvent (int theCommandID, SUIT_Desktop* parent) case GEOMOp::OpExtrudedCut: (new OperationGUI_ExtrudedFeatureDlg (CUT, getGeometryGUI(), parent))->show(); break; case GEOMOp::OpFillet1d: (new OperationGUI_Fillet1d2dDlg (getGeometryGUI(), parent, true))->show(); break; case GEOMOp::OpFillet2d: (new OperationGUI_Fillet1d2dDlg (getGeometryGUI(), parent, false))->show(); break; +#ifdef DEBUG_CURVE_CREATOR + // for debug purposes, to be removed + case GEOMOp::OpCurveCreator: + { + static CurveCreator_Curve *aStaticCurve = NULL; + + if (aStaticCurve == NULL) { + aStaticCurve = new CurveCreator_Curve(CurveCreator::Dim2d); + } + if (CurveCreator::Dim2d == aStaticCurve->getDimension()) { + OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)getGeometryGUI()->getApp()->activeViewManager()->getActiveView(); + vw->onTopView(); + } + + QDialog *aDialog = new QDialog(parent); + QVBoxLayout *aMainLO = new QVBoxLayout; + QPushButton *aQuitButton = new QPushButton(tr("Close")); + CurveCreator_Widget *aWidget = + new CurveCreator_Widget (aDialog, aStaticCurve); + + connect(aQuitButton, SIGNAL(clicked()), aDialog, SLOT(close())); + aMainLO->addWidget(aWidget); + aMainLO->addWidget(aQuitButton); + + aDialog->setLayout(aMainLO); + aDialog->setAttribute(Qt::WA_DeleteOnClose); + aDialog->show(); + } + break; +#endif default: app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID)); } -- 2.30.2