Merge from BR_hydro 30/10/2013

This commit is contained in:
vsr 2013-10-30 16:50:50 +00:00
parent fade4fd38a
commit d0f9dcaf72
56 changed files with 6330 additions and 68 deletions

View File

@ -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

View File

@ -169,3 +169,4 @@ SET(GEOM_RepairGUI RepairGUI)
SET(GEOM_TransformationGUI TransformationGUI)
SET(GEOM_ImportExportGUI ImportExportGUI)
SET(GEOM_GEOMShapeRec GEOMShapeRec)
SET(GEOM_CurveCreator CurveCreator)

View File

@ -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)
FIND_LIBRARY(GEOM_GEOMShapeRec GEOMShapeRec ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_CurveCreator CurveCreator ${GEOM_ROOT_DIR}/lib/salome)

View File

@ -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

BIN
resources/arrow_down.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

BIN
resources/arrow_up.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

BIN
resources/closedpolyline.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 430 B

BIN
resources/closedspline.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

BIN
resources/edit_points.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

BIN
resources/join2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

BIN
resources/new_point.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

BIN
resources/new_section.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

View File

@ -36,8 +36,9 @@
#include "BasicGUI_PlaneDlg.h" // Method PLANE
#include "BasicGUI_MarkerDlg.h" // Method LOCAL COORDINATE SYSTEM
#include <GeometryGUI.h>
#include "GeometryGUI.h"
#include "GeometryGUI_Operations.h"
#include "GEOMUtils.hxx"
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
@ -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
//=====================================================================================

View File

@ -28,7 +28,6 @@
#define BASICGUI_H
#include <GEOMGUI.h>
#include <V3d_View.hxx>
//=================================================================================
// 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

View File

@ -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

View File

@ -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()

View File

@ -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})

View File

@ -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 <deque>
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<TypeCoord> Coordinates;
};
#endif

View File

@ -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 <stdio.h>
//=======================================================================
// 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 );
}

View File

@ -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 <QString>
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 <EFBFBD> start and end points <EFBFBD> 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

View File

@ -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--;
}

View File

@ -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 <list>
/**
* The CurveCreator_CurveEditor is designed to manage of
* editing operations of CurveCreator_Curve class.
*/
class CURVECREATOR_EXPORT CurveCreator_CurveEditor
{
private:
typedef std::list<CurveCreator_Diff> 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 <20>undoed<65> 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

View File

@ -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 <list>
//=======================================================================
// 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<int> 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<int>::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;
}

View File

@ -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:
* <UL>
* <LI>Clear</LI>
* <LI>Join (without arguments)</LI>
* </UL>
*/
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:
* <UL>
* <LI>RemoveSection</LI>
* </UL>
*/
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:
* <UL>
* <LI>SetType</LI>
* <LI>SetClosed</LI>
* <LI>MoveSection</LI>
* <LI>Join (with 2 int arguments)</LI>
* </UL>
*/
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:
* <UL>
* <LI>RemovePoints</LI>
* </UL>
*/
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:
* <UL>
* <LI>AddPoints</LI>
* </UL>
*/
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:
* <UL>
* <LI>InsertPoints</LI>
* <LI>SetCoordinates</LI>
* </UL>
*/
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:
* <UL>
* <LI>AddSection</LI>
* </UL>
*/
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:
* <UL>
* <LI>RenameSection</LI>
* </UL>
*/
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

View File

@ -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 <stdio.h>
//=======================================================================
// 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;
}

View File

@ -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 <QString>
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 <EFBFBD> start and end points <EFBFBD> in other words non-manifold curves
* are not supported.
*/
class CURVECREATOR_EXPORT CurveCreator_ICurve
{
//! List of curves
typedef std::deque<CurveCreator_Section *> 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 <20>closed<65> 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 <20>closed<65> 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

View File

@ -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

View File

@ -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

View File

@ -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 <QGridLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QDoubleSpinBox>
#include <QDialogButtonBox>
#include <QDoubleValidator>
#include <QRegExpValidator>
#include <QAbstractButton>
#include <QPushButton>
#include <QLocale>
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);
}

View File

@ -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 <QDockWidget>
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

View File

@ -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 <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QPushButton>
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);
}

View File

@ -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 <QDockWidget>
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

View File

@ -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 <string>
#include <stdlib.h>
//=======================================================================
// 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]);
}
}

View File

@ -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 <string>
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:
* <UL>
* <LI>Clear</LI>
* <LI>Join (without arguments)</LI>
* </UL>
* @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:
* <UL>
* <LI>RemoveSection</LI>
* </UL>
* @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:
* <UL>
* <LI>SetType</LI>
* <LI>SetClosed</LI>
* <LI>MoveSection</LI>
* <LI>Join (with 2 int arguments)</LI>
* </UL>
* @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:
* <UL>
* <LI>RemovePoints</LI>
* </UL>
* @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:
* <UL>
* <LI>AddPoints</LI>
* </UL>
* @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:
* <UL>
* <LI>AddSection</LI>
* <LI>InsertPoints</LI>
* <LI>SetCoordinates</LI>
* </UL>
* @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:
* <UL>
* <LI>AddSection</LI>
* <LI>InsertPoints</LI>
* <LI>SetCoordinates</LI>
* </UL>
* @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:
* <UL>
* <LI>RenameSection</LI>
* </UL>
* @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

View File

@ -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 <string>
//! 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

View File

@ -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 <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <QHeaderView>
#include <QtAlgorithms>
#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<int> CurveCreator_TreeView::getSelectedSections() const
{
QList<int> aSect;
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(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<CurveCreator_TreeViewModel*>(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<CurveCreator_TreeViewModel*>(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<CurveCreator_TreeViewModel*>(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<CurveCreator_TreeViewModel*>(model());
if( aModel ){
rowsInserted(QModelIndex(), theSection, theSection );
}
}
void CurveCreator_TreeView::sectionChanged( int theSection, int aSectCnt )
{
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(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<CurveCreator_TreeViewModel*>(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<CurveCreator_TreeViewModel*>(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<CurveCreator_TreeViewModel*>(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<int>& theList )
{
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(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<int, int> >& thePointsList )
{
CurveCreator_TreeViewModel* aModel = dynamic_cast<CurveCreator_TreeViewModel*>(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<int,int> &s1, const QPair<int,int> &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<CurveCreator_TreeViewModel*>(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<int,int>( 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<CurveCreator_TreeViewModel*>(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<CurveCreator_TreeViewModel*>(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<CurveCreator_TreeViewModel*>(model());
if( aModel )
aModel->setCurve(theCurve);
reset();
}

View File

@ -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 <QTreeView>
#include <QAbstractItemModel>
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<IconType, QPixmap> 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<int> 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<int>& theList );
void setSelectedPoints( const QList< QPair<int, int> >& 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

View File

@ -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 <QButtonGroup>
#include <QGridLayout>
#include <QGroupBox>
#include <QIntValidator>
#include <QLineEdit>
#include <QPushButton>
#include <QRadioButton>
#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();
}

View File

@ -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 <QDialog>
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

View File

@ -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 <GEOMUtils.hxx>
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_ViewManager.h>
#include <OCCViewer_ViewWindow.h>
#include <OCCViewer_ViewManager.h>
#include <OCCViewer_ViewPort3d.h>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QGroupBox>
#include <QToolButton>
#include <QToolBar>
#include <QAction>
#include <QMenu>
#include <QMouseEvent>
#include <QApplication>
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<ActionId> anEnabledAct;
if( myCurve ){
anEnabledAct << NEW_SECTION_ID;
QList<int> 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<int> 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<ActionId> 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<int> aSelSection = mySectionView->getSelectedSections();
if( aSelSection.size() > 0 ){
mySection = aSelSection[0];
}
else{
QList< QPair<int,int> > 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<int> 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<int,int> > 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<int> 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<int> 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<int,int> > 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<int> 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<int,int> > 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<int> 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<int> 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<int> 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<int> 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<ActionId> 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<ActionId> 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<int> 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);
*/
}

View File

@ -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 <QWidget>
#include <QMap>
#include <SUIT_ViewWindow.h>
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<int> 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<ActionId, QAction*> 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

View File

@ -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

View File

@ -28,6 +28,7 @@
#include "GeometryGUI.h"
#include "GeometryGUI_Operations.h"
#include "GEOMUtils.hxx"
#include <LightApp_SelectionMgr.h>
#include <OCCViewer_ViewManager.h>
@ -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

View File

@ -32,7 +32,6 @@
#include <SALOMEDSClient.hxx>
#include <AIS_Shape.hxx>
#include <V3d_View.hxx>
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();

View File

@ -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 )

View File

@ -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();

View File

@ -3,6 +3,62 @@
<TS version="2.0" language="en_US">
<context>
<name>@default</name>
<message>
<source>ICON_CC_ARROW_UP</source>
<translation>arrow_up.png</translation>
</message>
<message>
<source>ICON_CC_ARROW_DOWN</source>
<translation>arrow_down.png</translation>
</message>
<message>
<source>ICON_CC_CLOSED_POLYLINE</source>
<translation>closedpolyline.png</translation>
</message>
<message>
<source>ICON_CC_CLOSED_SPLINE</source>
<translation>closedspline.png</translation>
</message>
<message>
<source>ICON_CC_DELETE</source>
<translation>delete.png</translation>
</message>
<message>
<source>ICON_CC_JOIN</source>
<translation>join2.png</translation>
</message>
<message>
<source>ICON_CC_NEW_POINT</source>
<translation>new_point.png</translation>
</message>
<message>
<source>ICON_CC_NEW_SECTION</source>
<translation>new_section.png</translation>
</message>
<message>
<source>ICON_CC_EDIT_POINTS</source>
<translation>edit_points.png</translation>
</message>
<message>
<source>ICON_CC_POINT</source>
<translation>point2.png</translation>
</message>
<message>
<source>ICON_CC_POLYLINE</source>
<translation>polyline.png</translation>
</message>
<message>
<source>ICON_CC_REDO</source>
<translation>redo.png</translation>
</message>
<message>
<source>ICON_CC_SPLINE</source>
<translation>spline.png</translation>
</message>
<message>
<source>ICON_CC_UNDO</source>
<translation>undo.png</translation>
</message>
<message>
<source>ICON_FOLDER</source>
<translation>folder.png</translation>

View File

@ -2348,6 +2348,10 @@ Please, select face, shell or solid and try again</translation>
<source>LIMIT_TOLERANCE_NEW_OBJ_NAME</source>
<translation>Limit_tolerance</translation>
</message>
<message>
<source>MEN_CURVE_CREATOR</source>
<translation>Curve creator</translation>
</message>
<message>
<source>MEN_ALL_SEL_ONLY</source>
<translation>Select All</translation>
@ -5014,6 +5018,14 @@ Ignoring units will cause model scaling (as dimensions are supposed to be specif
<source>TOOLS_IMPORTEXPORT</source>
<translation>Import / Export</translation>
</message>
<message>
<source>CC_PNT_ITEM_X_Y</source>
<translation>X=%1, Y=%2</translation>
</message>
<message>
<source>CC_PNT_ITEM_X_Y_Z</source>
<translation>X=%1, Y=%2, Z=%3</translation>
</message>
</context>
<context>
<name>BasicGUI_CurveDlg</name>
@ -5255,6 +5267,262 @@ Ignoring units will cause model scaling (as dimensions are supposed to be specif
<translation>Face 2 V</translation>
</message>
</context>
<context>
<name>CurveCreator_NewPointDlg</name>
<message>
<source>ADD_NEW_POINT</source>
<translation>Add new points</translation>
</message>
<message>
<source>X_COORD</source>
<translation>X</translation>
</message>
<message>
<source>Y_COORD</source>
<translation>Y</translation>
</message>
<message>
<source>Z_COORD</source>
<translation>Z</translation>
</message>
<message>
<source>ADD_BTN</source>
<translation>Add</translation>
</message>
<message>
<source>ADD_CONTINUE_BTN</source>
<translation>Add and continue</translation>
</message>
<message>
<source>ADD_NEW_POINT_TO_%1</source>
<translation>Add new point to %1</translation>
</message>
<message>
<source>SET_POINT_COORDINATES</source>
<translation>Set point coordinates</translation>
</message>
</context>
<context>
<name>CurveCreator_NewSectionDlg</name>
<message>
<source>NAME</source>
<translation>Name</translation>
</message>
<message>
<source>LINE_TYPE</source>
<translation>Type</translation>
</message>
<message>
<source>POLYLINE_TYPE</source>
<translation>Polyline</translation>
</message>
<message>
<source>SPLINE_TYPE</source>
<translation>Spline</translation>
</message>
<message>
<source>LINE_CLOSED</source>
<translation>Closed</translation>
</message>
<message>
<source>OK</source>
<translation>Ok</translation>
</message>
<message>
<source>ADD_BTN</source>
<translation>Add</translation>
</message>
<message>
<source>ADD_CONTINUE_BTN</source>
<translation>Add and continue</translation>
</message>
<message>
<source>ADD_NEW_SECTION</source>
<translation>Add new section</translation>
</message>
<message>
<source>SET_SECTION_PARAMETERS</source>
<translation>Set section parameters</translation>
</message>
</context>
<context>
<name>CurveCreator_TreeViewModel</name>
<message>
<source>X=%1, Y=%2</source>
<translation>X=%1, Y=%2</translation>
</message>
<message>
<source>X=%1, Y=%2, Z=%3</source>
<translation>X=%1, Y=%2, Z=%3</translation>
</message>
</context>
<context>
<name>CurveCreator_Widget</name>
<message>
<source>CURVE_NAME_TLT</source>
<translation>Name</translation>
</message>
<message>
<source>SECTION_GROUP_TLT</source>
<translation>Sections</translation>
</message>
<message>
<source>UNDO</source>
<translation>Undo</translation>
</message>
<message>
<source>UNDO_TLT</source>
<translation>Undo</translation>
</message>
<message>
<source>REDO</source>
<translation>Redo</translation>
</message>
<message>
<source>REDO_TLT</source>
<translation>Redo</translation>
</message>
<message>
<source>NEW_SECTION</source>
<translation>New section</translation>
</message>
<message>
<source>NEW_SECTION_TLT</source>
<translation>Insert new section</translation>
</message>
<message>
<source>INSERT_SECTION_BEFORE</source>
<translation>Insert section before</translation>
</message>
<message>
<source>INSERT_SECTION_BEFORE_TLT</source>
<translation>Insert section before</translation>
</message>
<message>
<source>INSERT_SECTION_AFTER</source>
<translation>Insert section after</translation>
</message>
<message>
<source>INSERT_SECTION_AFTER_TLT</source>
<translation>Insert section after</translation>
</message>
<message>
<source>ADDITION_MODE</source>
<translation>Addition mode</translation>
</message>
<message>
<source>ADDITION_MODE_TLT</source>
<translation>Addition mode</translation>
</message>
<message>
<source>MODIFICATION_MODE</source>
<translation>Modification mode</translation>
</message>
<message>
<source>MODIFICATION_MODE_TLT</source>
<translation>Modification mode</translation>
</message>
<message>
<source>DETECTION_MODE</source>
<translation>Detection mode</translation>
</message>
<message>
<source>DETECTION_MODE_TLT</source>
<translation>Detection mode</translation>
</message>
<message>
<source>INSERT_POINT_BEFORE</source>
<translation>Insert point before</translation>
</message>
<message>
<source>INSERT_POINT_BEFORE_TLT</source>
<translation>Insert point before</translation>
</message>
<message>
<source>INSERT_POINT_AFTER</source>
<translation>Insert point after</translation>
</message>
<message>
<source>CLOSE_SECTIONS</source>
<translation>Set closed</translation>
</message>
<message>
<source>CLOSE_SECTIONS_TLT</source>
<translation>Set selected sections closed</translation>
</message>
<message>
<source>UNCLOSE_SECTIONS</source>
<translation>Set open</translation>
</message>
<message>
<source>UNCLOSE_SECTIONS_TLT</source>
<translation>Set selected sections open</translation>
</message>
<message>
<source>SET_SECTIONS_POLYLINE</source>
<translation>Set polyline</translation>
</message>
<message>
<source>SET_SECTIONS_POLYLINE_TLT</source>
<translation>Set selected section type to polyline</translation>
</message>
<message>
<source>SET_SECTIONS_SPLINE</source>
<translation>Set spline</translation>
</message>
<message>
<source>SET_SECTIONS_SPLINE_TLT</source>
<translation>Set selected section type to spline</translation>
</message>
<message>
<source>REMOVE</source>
<translation>Remove</translation>
</message>
<message>
<source>REMOVE_TLT</source>
<translation>Remove</translation>
</message>
<message>
<source>JOIN</source>
<translation>Join</translation>
</message>
<message>
<source>JOIN_TLT</source>
<translation>Join selected sections</translation>
</message>
<message>
<source>STEP_UP</source>
<translation>Move up</translation>
</message>
<message>
<source>STEP_UP_TLT</source>
<translation>Move selected objects up</translation>
</message>
<message>
<source>STEP_DOWN</source>
<translation>Move down</translation>
</message>
<message>
<source>STEP_DOWN_TLT</source>
<translation>Move selected objects down</translation>
</message>
<message>
<source>CLEAR_ALL</source>
<translation>Clear all</translation>
</message>
<message>
<source>CLEAR_ALL_TLT</source>
<translation>Remove all objects</translation>
</message>
<message>
<source>JOIN_ALL</source>
<translation>Join all sections</translation>
</message>
<message>
<source>JOIN_ALL_TLT</source>
<translation>Join all sections</translation>
</message>
</context>
<context>
<name>EntityGUI_SketcherDlg</name>
<message>

View File

@ -2354,6 +2354,10 @@ Choisissez une face, une coque ou un solide et essayez de nouveau</translation>
<source>LIMIT_TOLERANCE_NEW_OBJ_NAME</source>
<translation>Tolérance_limite</translation>
</message>
<message>
<source>MEN_CURVE_CREATOR</source>
<translation type="unfinished">Curve creator</translation>
</message>
<message>
<source>MEN_ALL_SEL_ONLY</source>
<translation>Sélectionner tout</translation>
@ -4951,6 +4955,14 @@ le paramètre &apos;%1&apos; aux préférences du module Géométrie.</translati
<source>TOOLS_IMPORTEXPORT</source>
<translation>Import / Export</translation>
</message>
<message>
<source>CC_PNT_ITEM_X_Y</source>
<translation>X=%1, Y=%2</translation>
</message>
<message>
<source>CC_PNT_ITEM_X_Y_Z</source>
<translation>X=%1, Y=%2, Z=%3</translation>
</message>
</context>
<context>
<name>BasicGUI_CurveDlg</name>
@ -5192,6 +5204,262 @@ le paramètre &apos;%1&apos; aux préférences du module Géométrie.</translati
<translation>Face 2 V</translation>
</message>
</context>
<context>
<name>CurveCreator_NewPointDlg</name>
<message>
<source>ADD_NEW_POINT</source>
<translation>Add new points</translation>
</message>
<message>
<source>X_COORD</source>
<translation>X</translation>
</message>
<message>
<source>Y_COORD</source>
<translation>Y</translation>
</message>
<message>
<source>Z_COORD</source>
<translation>Z</translation>
</message>
<message>
<source>ADD_BTN</source>
<translation>Add</translation>
</message>
<message>
<source>ADD_CONTINUE_BTN</source>
<translation>Add and continue</translation>
</message>
<message>
<source>ADD_NEW_POINT_TO_%1</source>
<translation>Add new point to %1</translation>
</message>
<message>
<source>SET_POINT_COORDINATES</source>
<translation>Set point coordinates</translation>
</message>
</context>
<context>
<name>CurveCreator_NewSectionDlg</name>
<message>
<source>NAME</source>
<translation>Name</translation>
</message>
<message>
<source>LINE_TYPE</source>
<translation>Type</translation>
</message>
<message>
<source>POLYLINE_TYPE</source>
<translation>Polyline</translation>
</message>
<message>
<source>SPLINE_TYPE</source>
<translation>Spline</translation>
</message>
<message>
<source>LINE_CLOSED</source>
<translation>Closed</translation>
</message>
<message>
<source>OK</source>
<translation>Ok</translation>
</message>
<message>
<source>ADD_BTN</source>
<translation>Add</translation>
</message>
<message>
<source>ADD_CONTINUE_BTN</source>
<translation>Add and continue</translation>
</message>
<message>
<source>ADD_NEW_SECTION</source>
<translation>Add new section</translation>
</message>
<message>
<source>SET_SECTION_PARAMETERS</source>
<translation>Set section parameters</translation>
</message>
</context>
<context>
<name>CurveCreator_TreeViewModel</name>
<message>
<source>X=%1, Y=%2</source>
<translation>X=%1, Y=%2</translation>
</message>
<message>
<source>X=%1, Y=%2, Z=%3</source>
<translation>X=%1, Y=%2, Z=%3</translation>
</message>
</context>
<context>
<name>CurveCreator_Widget</name>
<message>
<source>CURVE_NAME_TLT</source>
<translation type="unfinished">Name</translation>
</message>
<message>
<source>SECTION_GROUP_TLT</source>
<translation type="unfinished">Sections</translation>
</message>
<message>
<source>UNDO</source>
<translation type="unfinished">Undo</translation>
</message>
<message>
<source>UNDO_TLT</source>
<translation type="unfinished">Undo</translation>
</message>
<message>
<source>REDO</source>
<translation type="unfinished">Redo</translation>
</message>
<message>
<source>REDO_TLT</source>
<translation type="unfinished">Redo</translation>
</message>
<message>
<source>NEW_SECTION</source>
<translation type="unfinished">New section</translation>
</message>
<message>
<source>NEW_SECTION_TLT</source>
<translation type="unfinished">Insert new section</translation>
</message>
<message>
<source>INSERT_SECTION_BEFORE</source>
<translation type="unfinished">Insert section before</translation>
</message>
<message>
<source>INSERT_SECTION_BEFORE_TLT</source>
<translation type="unfinished">Insert section before</translation>
</message>
<message>
<source>INSERT_SECTION_AFTER</source>
<translation type="unfinished">Insert section after</translation>
</message>
<message>
<source>INSERT_SECTION_AFTER_TLT</source>
<translation type="unfinished">Insert section after</translation>
</message>
<message>
<source>ADDITION_MODE</source>
<translation type="unfinished">Addition mode</translation>
</message>
<message>
<source>ADDITION_MODE_TLT</source>
<translation type="unfinished">Addition mode</translation>
</message>
<message>
<source>MODIFICATION_MODE</source>
<translation type="unfinished">Modification mode</translation>
</message>
<message>
<source>MODIFICATION_MODE_TLT</source>
<translation type="unfinished">Modification mode</translation>
</message>
<message>
<source>DETECTION_MODE</source>
<translation type="unfinished">Detection mode</translation>
</message>
<message>
<source>DETECTION_MODE_TLT</source>
<translation type="unfinished">Detection mode</translation>
</message>
<message>
<source>INSERT_POINT_BEFORE</source>
<translation type="unfinished">Insert point before</translation>
</message>
<message>
<source>INSERT_POINT_BEFORE_TLT</source>
<translation type="unfinished">Insert point before</translation>
</message>
<message>
<source>INSERT_POINT_AFTER</source>
<translation type="unfinished">Insert point after</translation>
</message>
<message>
<source>CLOSE_SECTIONS</source>
<translation type="unfinished">Set closed</translation>
</message>
<message>
<source>CLOSE_SECTIONS_TLT</source>
<translation type="unfinished">Set selected sections closed</translation>
</message>
<message>
<source>UNCLOSE_SECTIONS</source>
<translation type="unfinished">Set open</translation>
</message>
<message>
<source>UNCLOSE_SECTIONS_TLT</source>
<translation type="unfinished">Set selected sections open</translation>
</message>
<message>
<source>SET_SECTIONS_POLYLINE</source>
<translation type="unfinished">Set polyline</translation>
</message>
<message>
<source>SET_SECTIONS_POLYLINE_TLT</source>
<translation type="unfinished">Set selected section type to polyline</translation>
</message>
<message>
<source>SET_SECTIONS_SPLINE</source>
<translation type="unfinished">Set spline</translation>
</message>
<message>
<source>SET_SECTIONS_SPLINE_TLT</source>
<translation type="unfinished">Set selected section type to spline</translation>
</message>
<message>
<source>REMOVE</source>
<translation type="unfinished">Remove</translation>
</message>
<message>
<source>REMOVE_TLT</source>
<translation type="unfinished">Remove</translation>
</message>
<message>
<source>JOIN</source>
<translation type="unfinished">Join</translation>
</message>
<message>
<source>JOIN_TLT</source>
<translation type="unfinished">Join selected sections</translation>
</message>
<message>
<source>STEP_UP</source>
<translation type="unfinished">Move up</translation>
</message>
<message>
<source>STEP_UP_TLT</source>
<translation type="unfinished">Move selected objects up</translation>
</message>
<message>
<source>STEP_DOWN</source>
<translation type="unfinished">Move down</translation>
</message>
<message>
<source>STEP_DOWN_TLT</source>
<translation type="unfinished">Move selected objects down</translation>
</message>
<message>
<source>CLEAR_ALL</source>
<translation type="unfinished">Clear all</translation>
</message>
<message>
<source>CLEAR_ALL_TLT</source>
<translation type="unfinished">Remove all objects</translation>
</message>
<message>
<source>JOIN_ALL</source>
<translation type="unfinished">Join all sections</translation>
</message>
<message>
<source>JOIN_ALL_TLT</source>
<translation type="unfinished">Join all sections</translation>
</message>
</context>
<context>
<name>EntityGUI_SketcherDlg</name>
<message>

View File

@ -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 );

View File

@ -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

View File

@ -38,6 +38,7 @@ SET(_link_LIBRARIES
${CAS_TKTopAlgo}
${CAS_TKG2d}
${CAS_TKG3d}
${CAS_TKV3d}
${KERNEL_SALOMELocalTrace}
)

View File

@ -83,6 +83,9 @@
#include <ShapeAnalysis.hxx>
#include <ShapeFix_Shape.hxx>
#include <ProjLib.hxx>
#include <ElSLib.hxx>
#include <vector>
#include <Standard_Failure.hxx>
@ -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;
}

View File

@ -34,6 +34,8 @@
#include <gp_Ax3.hxx>
#include <gp_Vec.hxx>
#include <V3d_View.hxx>
#include <NCollection_DataMap.hxx>
#include <functional>
@ -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

View File

@ -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 ---

View File

@ -29,7 +29,9 @@
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ViewManager.h>
#include <SalomeApp_Application.h>
#include <OCCViewer_ViewWindow.h>
#include <TopTools_MapOfShape.hxx>
#include <TopExp_Explorer.hxx>
@ -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 <QVBoxLayout>
#include <QPushButton>
#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));
}