summaryrefslogtreecommitdiff
path: root/QCSXCAD
diff options
context:
space:
mode:
Diffstat (limited to 'QCSXCAD')
-rw-r--r--QCSXCAD/CMakeLists.txt199
-rw-r--r--QCSXCAD/COPYING165
-rw-r--r--QCSXCAD/INSTALL21
-rw-r--r--QCSXCAD/NEWS6
-rw-r--r--QCSXCAD/QCSGridEditor.cpp640
-rw-r--r--QCSXCAD/QCSGridEditor.h87
-rw-r--r--QCSXCAD/QCSPrimEditor.cpp746
-rw-r--r--QCSXCAD/QCSPrimEditor.h237
-rw-r--r--QCSXCAD/QCSPropEditor.cpp623
-rw-r--r--QCSXCAD/QCSPropEditor.h248
-rw-r--r--QCSXCAD/QCSTreeWidget.cpp242
-rw-r--r--QCSXCAD/QCSTreeWidget.h92
-rw-r--r--QCSXCAD/QCSXCAD.cpp999
-rw-r--r--QCSXCAD/QCSXCAD.h180
-rw-r--r--QCSXCAD/QCSXCAD_Global.cpp58
-rw-r--r--QCSXCAD/QCSXCAD_Global.h58
-rw-r--r--QCSXCAD/QParameterGui.cpp401
-rw-r--r--QCSXCAD/QParameterGui.h107
-rw-r--r--QCSXCAD/QVTKStructure.cpp873
-rw-r--r--QCSXCAD/QVTKStructure.h143
-rw-r--r--QCSXCAD/README7
-rw-r--r--QCSXCAD/VTKPrimitives.cpp1019
-rw-r--r--QCSXCAD/VTKPrimitives.h143
-rw-r--r--QCSXCAD/cmake/Modules/FindTinyXML.cmake74
-rw-r--r--QCSXCAD/export_pov.cpp267
-rw-r--r--QCSXCAD/export_pov.h49
-rw-r--r--QCSXCAD/export_x3d.cpp201
-rw-r--r--QCSXCAD/export_x3d.h42
-rw-r--r--QCSXCAD/images/Arrows/Arrows.odgbin0 -> 10791 bytes
-rw-r--r--QCSXCAD/images/Arrows/ArrowsXY.pngbin0 -> 7245 bytes
-rw-r--r--QCSXCAD/images/Arrows/ArrowsXZ.odgbin0 -> 10515 bytes
-rw-r--r--QCSXCAD/images/Arrows/ArrowsXZ.pngbin0 -> 7203 bytes
-rw-r--r--QCSXCAD/images/Arrows/ArrowsYZ.odgbin0 -> 10425 bytes
-rw-r--r--QCSXCAD/images/Arrows/ArrowsYZ.pngbin0 -> 6371 bytes
-rw-r--r--QCSXCAD/images/ArrowsXY.pngbin0 -> 7245 bytes
-rw-r--r--QCSXCAD/images/ArrowsXZ.pngbin0 -> 7203 bytes
-rw-r--r--QCSXCAD/images/ArrowsYZ.pngbin0 -> 6371 bytes
-rw-r--r--QCSXCAD/images/CVS/Entries40
-rw-r--r--QCSXCAD/images/CVS/Repository1
-rw-r--r--QCSXCAD/images/CVS/Root1
-rw-r--r--QCSXCAD/images/GeoEdit.pngbin0 -> 13320 bytes
-rw-r--r--QCSXCAD/images/ParaSetup.pngbin0 -> 20660 bytes
-rw-r--r--QCSXCAD/images/QCSXCAD_Icon.pngbin0 -> 14030 bytes
-rw-r--r--QCSXCAD/images/accept.pngbin0 -> 917 bytes
-rw-r--r--QCSXCAD/images/bulb.pngbin0 -> 829 bytes
-rw-r--r--QCSXCAD/images/bulb_off.pngbin0 -> 672 bytes
-rw-r--r--QCSXCAD/images/cancel.pngbin0 -> 1821 bytes
-rw-r--r--QCSXCAD/images/close.pngbin0 -> 1560 bytes
-rw-r--r--QCSXCAD/images/configure.pngbin0 -> 943 bytes
-rw-r--r--QCSXCAD/images/down.pngbin0 -> 1991 bytes
-rw-r--r--QCSXCAD/images/edit.pngbin0 -> 1627 bytes
-rw-r--r--QCSXCAD/images/edit_add.pngbin0 -> 1438 bytes
-rw-r--r--QCSXCAD/images/edit_remove.pngbin0 -> 783 bytes
-rw-r--r--QCSXCAD/images/editcopy.pngbin0 -> 3781 bytes
-rw-r--r--QCSXCAD/images/exit.pngbin0 -> 2017 bytes
-rw-r--r--QCSXCAD/images/failed.pngbin0 -> 821 bytes
-rw-r--r--QCSXCAD/images/filenew.pngbin0 -> 1177 bytes
-rw-r--r--QCSXCAD/images/fileopen.pngbin0 -> 2232 bytes
-rw-r--r--QCSXCAD/images/filesave.pngbin0 -> 1348 bytes
-rw-r--r--QCSXCAD/images/filesaveas.pngbin0 -> 2069 bytes
-rw-r--r--QCSXCAD/images/folder.pngbin0 -> 2355 bytes
-rw-r--r--QCSXCAD/images/funct.pngbin0 -> 1792 bytes
-rw-r--r--QCSXCAD/images/hourglass.pngbin0 -> 945 bytes
-rw-r--r--QCSXCAD/images/icon.gifbin0 -> 263 bytes
-rw-r--r--QCSXCAD/images/launch.pngbin0 -> 2288 bytes
-rw-r--r--QCSXCAD/images/launch2.pngbin0 -> 2297 bytes
-rw-r--r--QCSXCAD/images/launch3.pngbin0 -> 2302 bytes
-rw-r--r--QCSXCAD/images/opening.pngbin0 -> 186733 bytes
-rw-r--r--QCSXCAD/images/qt-logo.pngbin0 -> 3696 bytes
-rw-r--r--QCSXCAD/images/reload.pngbin0 -> 1996 bytes
-rw-r--r--QCSXCAD/images/result_small.pngbin0 -> 1345 bytes
-rw-r--r--QCSXCAD/images/results.pngbin0 -> 7776 bytes
-rw-r--r--QCSXCAD/images/setup.pngbin0 -> 11471 bytes
-rw-r--r--QCSXCAD/images/simulation.pngbin0 -> 114512 bytes
-rw-r--r--QCSXCAD/images/simulation_icon.pngbin0 -> 1411 bytes
-rw-r--r--QCSXCAD/images/simulation_small.pngbin0 -> 10267 bytes
-rw-r--r--QCSXCAD/images/simulation_tr.pngbin0 -> 80895 bytes
-rw-r--r--QCSXCAD/images/up.pngbin0 -> 1992 bytes
-rw-r--r--QCSXCAD/images/viewmag+.pngbin0 -> 2025 bytes
-rw-r--r--QCSXCAD/images/viewmag-.pngbin0 -> 1998 bytes
-rw-r--r--QCSXCAD/images/viewmagfit.pngbin0 -> 2011 bytes
-rw-r--r--QCSXCAD/images/vtk-logo.pngbin0 -> 1193 bytes
-rw-r--r--QCSXCAD/images/window_icon2.pngbin0 -> 917 bytes
-rw-r--r--QCSXCAD/images/work.pngbin0 -> 13178 bytes
-rw-r--r--QCSXCAD/linux/QCSXCAD.dsc9
-rw-r--r--QCSXCAD/linux/QCSXCAD.spec115
-rw-r--r--QCSXCAD/linux/debian.changelog9
-rw-r--r--QCSXCAD/linux/debian.control17
-rw-r--r--QCSXCAD/linux/debian.rules7
-rw-r--r--QCSXCAD/linux/fedora17.diff13
-rw-r--r--QCSXCAD/resources.qrc49
-rw-r--r--QCSXCAD/vtkInteractorStyleRubberBand2DPlane.cpp73
-rw-r--r--QCSXCAD/vtkInteractorStyleRubberBand2DPlane.h35
93 files changed, 8296 insertions, 0 deletions
diff --git a/QCSXCAD/CMakeLists.txt b/QCSXCAD/CMakeLists.txt
new file mode 100644
index 0000000..32c80cd
--- /dev/null
+++ b/QCSXCAD/CMakeLists.txt
@@ -0,0 +1,199 @@
+
+# define build type
+IF( DEFINED CMAKE_BUILD_TYPE )
+ SET( CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Set to either \"Release\" or \"Debug\"" )
+ELSE()
+ SET( CMAKE_BUILD_TYPE Release CACHE STRING "Set to either \"Release\" or \"Debug\"" )
+ENDIF()
+
+PROJECT( QCSXCAD CXX)
+
+cmake_minimum_required(VERSION 2.8)
+
+# https://cmake.org/cmake/help/v3.0/policy/CMP0020.html
+if(POLICY CMP0020)
+ cmake_policy(SET CMP0020 OLD)
+endif()
+
+IF(EXISTS ${PROJECT_SOURCE_DIR}/localConfig.cmake)
+ include(${PROJECT_SOURCE_DIR}/localConfig.cmake)
+ENDIF()
+
+# default
+set(LIB_VERSION_MAJOR 0)
+set(LIB_VERSION_MINOR 6)
+set(LIB_VERSION_PATCH 1)
+set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
+
+set(VERSION "v${LIB_VERSION_STRING}")
+
+# add git revision
+# add git revision
+IF(EXISTS ${PROJECT_SOURCE_DIR}/.git )
+ FIND_PACKAGE(Git)
+ # Get the latest abbreviated commit hash of the working branch
+ execute_process(
+ COMMAND ${GIT_EXECUTABLE} describe --tags
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ OUTPUT_VARIABLE GITREV
+ )
+ set(VERSION ${GITREV})
+ string(STRIP ${VERSION} VERSION)
+ message(STATUS "Found Git repository, ${PROJECT_NAME} version tag: ${VERSION}")
+ENDIF()
+
+ADD_DEFINITIONS(-DGIT_VERSION=\"${VERSION}\")
+
+if (WIN32)
+ ADD_DEFINITIONS( -DBUILD_QCSXCAD_LIB )
+endif (WIN32)
+
+
+#
+# Set up RPATH for the project
+#
+option(ENABLE_RPATH "Enable rpath support on Linux and Mac" ON)
+if(NOT CMAKE_INSTALL_RPATH)
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
+endif()
+if(APPLE AND NOT CMAKE_INSTALL_NAME_DIR)
+ set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
+endif()
+if(UNIX AND ENABLE_RPATH)
+ set(CMAKE_SKIP_BUILD_RPATH FALSE)
+ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
+ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+endif()
+
+# Set locations of extra CMake modules
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${openEMS_SOURCE_DIR}/cmake/Modules/")
+
+# CSXCAD
+# $ cmake -DCSXCAD_ROOT_DIR=~/opt/openEMS .
+# SET(CSXCAD_ROOT_DIR ~/opt/openEMS)
+find_library(CSXCAD_LIBRARIES
+ NAMES CSXCAD
+ HINTS ${CSXCAD_ROOT_DIR}/lib${LIB_SUFFIX}
+ NO_CMAKE_FIND_ROOT_PATH
+)
+message(STATUS "CSXCAD_LIBRARIES: ${CSXCAD_LIBRARIES}" )
+#TODO test if CSXCADs was found
+find_path(CSXCAD_INCLUDE_DIR
+ NAMES ContinuousStructure.h
+ HINTS ${CSXCAD_ROOT_DIR}/include
+ PATH_SUFFIXES "CSXCAD" ${CSXCAD_INCLUDE_DIR}
+ NO_CMAKE_FIND_ROOT_PATH
+)
+message(STATUS "CSXCAD_INCLUDE_DIR: ${CSXCAD_INCLUDE_DIR}" )
+INCLUDE_DIRECTORIES( ${CSXCAD_INCLUDE_DIR} )
+
+# Set locations of CMake modules
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${QCSXCAD_SOURCE_DIR}/cmake/Modules/")
+
+# TinyXML module from https://github.com/ros/cmake_modules
+find_package(TinyXML REQUIRED)
+ADD_DEFINITIONS( -DTIXML_USE_STL )
+
+# vtk
+if (WIN32)
+ find_package(VTK 6.1 REQUIRED)
+else()
+ # prefer >=6.1, fallback to >=5.4
+ find_package(VTK 6.1 COMPONENTS vtkGUISupportQt vtkRenderingLOD vtkRenderingOpenGL vtkIOXML vtkIOPLY vtkIOImage vtkInteractionWidgets NO_MODULE)
+ IF (NOT ${VTK_FOUND})
+ find_package(VTK REQUIRED)
+ endif()
+endif()
+
+message(STATUS "Found package VTK. Using version " ${VTK_VERSION})
+include(${VTK_USE_FILE})
+INCLUDE_DIRECTORIES (${VTK_INCLUDE_DIR})
+
+# Qt
+SET(RESOURCES resources.qrc)
+set(CMAKE_AUTOMOC ON)
+if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
+ find_package(Qt5Widgets REQUIRED)
+ include_directories(${Qt5Widgets_INCLUDE_DIRS})
+ find_package(Qt5Xml REQUIRED)
+ include_directories(${Qt5Xml_INCLUDE_DIRS})
+ INCLUDE_DIRECTORIES(${Qt5_INCLUDE_DIRS})
+ set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
+ QT5_ADD_RESOURCES(RESOURCES_SRCS ${RESOURCES})
+else()
+ FIND_PACKAGE(Qt4 REQUIRED QtCore QtGui QtXml)
+ INCLUDE( ${QT_USE_FILE} )
+ QT4_ADD_RESOURCES(RESOURCES_SRCS ${RESOURCES})
+endif()
+
+if("${VTK_MAJOR_VERSION}" GREATER 5)
+ set( vtk_LIBS ${VTK_LIBRARIES} )
+else()
+ set( vtk_LIBS
+ vtkCommon
+ vtkFiltering
+ vtkGraphics
+ vtkHybrid
+ vtkIO
+ vtkRendering
+ vtkWidgets
+ QVTK
+ )
+endif()
+message(STATUS "vtk libraries " ${vtk_LIBS})
+
+set( SOURCES
+ QCSXCAD.cpp
+ QCSGridEditor.cpp
+ QCSPrimEditor.cpp
+ QCSPropEditor.cpp
+ QCSTreeWidget.cpp
+ QParameterGui.cpp
+ QVTKStructure.cpp
+ VTKPrimitives.cpp
+ export_x3d.cpp
+ export_pov.cpp
+ QCSXCAD_Global.cpp
+ vtkInteractorStyleRubberBand2DPlane.cpp
+)
+
+set(PUB_HEADERS
+ QCSXCAD.h
+ QCSGridEditor.h
+ QCSPrimEditor.h
+ QCSPropEditor.h
+ QCSTreeWidget.h
+ QParameterGui.h
+ QVTKStructure.h
+ VTKPrimitives.h
+ QCSXCAD_Global.h
+ export_x3d.h
+ export_pov.h
+ vtkInteractorStyleRubberBand2DPlane.h
+)
+
+# CSXCAD library
+add_library( QCSXCAD SHARED
+ ${SOURCES}
+ ${MOC_SRCS}
+ ${RESOURCES_SRCS}
+)
+
+if(Qt5Widgets_FOUND)
+ qt5_use_modules(QCSXCAD Widgets Xml)
+endif()
+
+TARGET_LINK_LIBRARIES( QCSXCAD
+ ${CSXCAD_LIBRARIES}
+ tinyxml
+ ${vtk_LIBS}
+ ${QT_LIBRARIES}
+)
+
+set_target_properties(QCSXCAD PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_MAJOR})
+
+INSTALL(TARGETS QCSXCAD DESTINATION lib${LIB_SUFFIX})
+
+INSTALL(FILES ${PUB_HEADERS} DESTINATION include/QCSXCAD)
+
+#TODO tarball, debug, release
diff --git a/QCSXCAD/COPYING b/QCSXCAD/COPYING
new file mode 100644
index 0000000..cca7fc2
--- /dev/null
+++ b/QCSXCAD/COPYING
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/QCSXCAD/INSTALL b/QCSXCAD/INSTALL
new file mode 100644
index 0000000..b878959
--- /dev/null
+++ b/QCSXCAD/INSTALL
@@ -0,0 +1,21 @@
+Install instructions for the QCSXCAD library:
+---------------------------------------------
+
+1) Prerequirements:
+ QCSXCAD relies on a number of libraries:
+ - CSXCAD (http://openEMS.de)
+ - Qt (http://qt-project.org/)
+
+2) Build:
+ - change directory to QCSXCAD
+ - build:
+ mkdir build
+ cd build
+ cmake .. -DCMAKE_INSTALL_PREFIX=<path/to/install/> -DCSXCAD_ROOT_DIR=<path/to/CSXCAD>
+ make
+ make install (may require root)
+
+ Note:
+ - all path informations may be stored in a localConfig.cmake
+ - the default "prefix" is /usr/local
+
diff --git a/QCSXCAD/NEWS b/QCSXCAD/NEWS
new file mode 100644
index 0000000..19519af
--- /dev/null
+++ b/QCSXCAD/NEWS
@@ -0,0 +1,6 @@
+Changes in v0.5.0
+-------------------------------
+- use a level of detail actor for faster rendering
+- new and rewritten 2D view mode, now based on vtk as well
+- render discrete material models
+- code cleanup
diff --git a/QCSXCAD/QCSGridEditor.cpp b/QCSXCAD/QCSGridEditor.cpp
new file mode 100644
index 0000000..4e2210c
--- /dev/null
+++ b/QCSXCAD/QCSGridEditor.cpp
@@ -0,0 +1,640 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QGridLayout>
+#include <QPushButton>
+#include <QDialog>
+#include <QHBoxLayout>
+#include <QCheckBox>
+#include <QSpinBox>
+#include <QMessageBox>
+#include <QTextEdit>
+
+#include "QCSGridEditor.h"
+#include "CSRectGrid.h"
+#include "QCSXCAD_Global.h"
+
+QCSGridEditor::QCSGridEditor(CSRectGrid* grid, QWidget* parent) : QWidget(parent)
+{
+ clGrid=grid;
+ QGridLayout* lay = new QGridLayout();
+ setLayout(lay);
+
+ //lay->addWidget(new QLabel(tr("Direction")),0,0);
+ lay->addWidget(new QLabel(tr("Min")),0,1);
+ lay->addWidget(new QLabel(tr("Max")),0,2);
+ lay->addWidget(new QLabel(tr("Lines")),0,3);
+
+ for (int n=0;n<3;++n)
+ {
+ m_DirNames[n] = new QLabel(GetDirName(n));
+ lay->addWidget(m_DirNames[n],n+1,0);
+ }
+
+ QLabel* label=NULL;
+ for (unsigned int i=0;i<6;++i)
+ {
+ label=new QLabel("0");
+ lay->addWidget(label,i/2+1,i%2+1);
+ lay->setAlignment(label,Qt::AlignCenter);
+ SimBox.append(label);
+ }
+
+ for (unsigned int i=0;i<3;++i)
+ {
+ label=new QLabel("0");
+ lay->addWidget(label,i+1,3);
+ lay->setAlignment(label,Qt::AlignCenter);
+ NodeQty.append(label);
+ }
+
+ QString EditText = tr("Edit");
+ if (QCSX_Settings.GetEdit()==false)
+ EditText = tr("View");
+ QPushButton* PB = new QPushButton(QIcon(":/images/edit.png"),EditText);
+ QObject::connect(PB,SIGNAL(clicked()),this,SLOT(EditX()));
+ lay->addWidget(PB,1,4);
+
+ PB = new QPushButton(QIcon(":/images/edit.png"),EditText);
+ QObject::connect(PB,SIGNAL(clicked()),this,SLOT(EditY()));
+ lay->addWidget(PB,2,4);
+
+ PB = new QPushButton(QIcon(":/images/edit.png"),EditText);
+ QObject::connect(PB,SIGNAL(clicked()),this,SLOT(EditZ()));
+ lay->addWidget(PB,3,4);
+
+ lay->addWidget(new QLabel(tr("Drawing unit [m]:")),4,0,1,2);
+ UnitLength = new QLineEdit("1");
+ UnitLength->setEnabled(QCSX_Settings.GetEdit());
+ QObject::connect(UnitLength,SIGNAL(textEdited(QString)),this,SLOT(SetDeltaUnit(QString)));
+ lay->addWidget(UnitLength,4,2,1,3);
+
+ OpacitySlider = new QSlider(Qt::Horizontal);
+ OpacitySlider->setRange(0,255);
+ QObject::connect(OpacitySlider,SIGNAL(valueChanged(int)),this,SIGNAL(OpacityChange(int)));
+ lay->addWidget(new QLabel(tr("Grid opacity")),5,0,1,3);
+ lay->addWidget(OpacitySlider,5,2,1,3);
+
+ lay->setRowStretch(6,1);
+ lay->setColumnStretch(5,1);
+}
+
+QCSGridEditor::~QCSGridEditor()
+{
+}
+
+QToolBar* QCSGridEditor::BuildToolbar()
+{
+ QToolBar *TB = new QToolBar(tr("Discretisation"));
+ TB->setObjectName("Discretisation_ToolBar");
+ TB->addAction(tr("homo\nDisc"),this,SLOT(BuildHomogenDisc()));
+ TB->addAction(tr("inhomo\nDisc"),this,SLOT(BuildInHomogenDisc()));
+ TB->addAction(tr("increase \nDisc"),this,SLOT(IncreaseResolution()));
+ TB->addAction(tr("detect \nedges"),this,SLOT(DetectEdges()));
+ return TB;
+}
+
+QWidget* QCSGridEditor::BuildPlanePosWidget()
+{
+ QWidget* PPWid = new QWidget();
+ QGridLayout* lay = new QGridLayout();
+
+ for (int n=0;n<3;++n)
+ {
+ m_NormNames[n] = new QLabel(GetNormName(n)+ tr(" plane:"));
+ lay->addWidget( m_NormNames[n] ,n,0);
+ m_PlanePos[n] = new QSlider();
+ m_PlanePos[n]->setOrientation(Qt::Horizontal);
+ lay->addWidget(m_PlanePos[n],n,1);
+ m_PlanePosValue[n] = new QLabel();
+ lay->addWidget(m_PlanePosValue[n],n,2);
+ }
+ QObject::connect(m_PlanePos[0],SIGNAL(valueChanged(int)),this,SIGNAL(GridPlaneXChanged(int)));
+ QObject::connect(m_PlanePos[1],SIGNAL(valueChanged(int)),this,SIGNAL(GridPlaneYChanged(int)));
+ QObject::connect(m_PlanePos[2],SIGNAL(valueChanged(int)),this,SIGNAL(GridPlaneZChanged(int)));
+
+ QObject::connect(m_PlanePos[0],SIGNAL(valueChanged(int)),this,SLOT(SetGridPlaneX(int)));
+ QObject::connect(m_PlanePos[1],SIGNAL(valueChanged(int)),this,SLOT(SetGridPlaneY(int)));
+ QObject::connect(m_PlanePos[2],SIGNAL(valueChanged(int)),this,SLOT(SetGridPlaneZ(int)));
+
+ PPWid->setLayout(lay);
+ return PPWid;
+}
+
+void QCSGridEditor::SetGridPlaneX(int pos)
+{
+ m_PlanePosValue[0]->setText(QString("%1 = %2").arg(GetDirName(0)).arg(clGrid->GetLine(0,pos)));
+}
+
+void QCSGridEditor::SetGridPlaneY(int pos)
+{
+ m_PlanePosValue[1]->setText(QString("%1 = %2").arg(GetDirName(1)).arg(clGrid->GetLine(1,pos)));
+}
+
+void QCSGridEditor::SetGridPlaneZ(int pos)
+{
+ m_PlanePosValue[2]->setText(QString("%1 = %2").arg(GetDirName(2)).arg(clGrid->GetLine(2,pos)));
+}
+
+void QCSGridEditor::BuildInHomogenDisc()
+{
+ QDialog* HomogenDisc = new QDialog();
+ QGridLayout* lay = new QGridLayout();
+
+ lay->addWidget(new QLabel(tr("Create inhomogenous discretisation:")),0,0,1,3);
+
+ QCheckBox* DelOldGrid = new QCheckBox(tr("Clear old mesh"));
+ DelOldGrid->setChecked(true);
+ lay->addWidget(DelOldGrid,0,5);
+
+ lay->addWidget(new QLabel(tr("min")),1,1);
+ lay->addWidget(new QLabel(tr("max")),1,2);
+ lay->addWidget(new QLabel(tr("lines")),1,3);
+ lay->addWidget(new QLabel(tr("grid distribution function:")),1,4,1,2);
+// lay->addWidget(new QLabel(tr("X")),2,0);
+// lay->addWidget(new QLabel(tr("Y")),3,0);
+// lay->addWidget(new QLabel(tr("Z")),4,0);
+ QLineEdit* function[3];
+ function[0] = new QLineEdit(GetDirName(0));
+ function[1] = new QLineEdit(GetDirName(1));
+ function[2] = new QLineEdit(GetDirName(2));
+ lay->addWidget(new QLabel("X:"),2,0);
+ lay->addWidget(new QLabel("f(x)="),2,4);
+ lay->addWidget(function[0],2,5);
+ lay->addWidget(new QLabel("Y:"),3,0);
+ lay->addWidget(new QLabel("f(y)="),3,4);
+ lay->addWidget(function[1],3,5);
+ lay->addWidget(new QLabel("Z:"),4,0);
+ lay->addWidget(new QLabel("f(z)="),4,4);
+ lay->addWidget(function[2],4,5);
+ QLineEdit* BoxLine[6];
+ QSpinBox* Nodes[3];
+ for (int i=0;i<3;++i)
+ {
+ BoxLine[2*i]= new QLineEdit(QString("0"));
+ lay->addWidget(BoxLine[2*i],i+2,1);
+ BoxLine[2*i+1]= new QLineEdit(QString("1"));
+ lay->addWidget(BoxLine[2*i+1],i+2,2);
+ Nodes[i] = new QSpinBox();
+ Nodes[i]->setRange(0,9999);
+ Nodes[i]->setValue(0);
+ lay->addWidget(Nodes[i],i+2,3);
+ }
+
+ QPushButton* PB = new QPushButton(tr("Ok"));
+ QObject::connect(PB,SIGNAL(clicked()),HomogenDisc,SLOT(accept()));
+ QPushButton* PBcancel = new QPushButton(tr("Cancel"));
+ QObject::connect(PBcancel,SIGNAL(clicked()),HomogenDisc,SLOT(reject()));
+
+ QHBoxLayout* hLay = new QHBoxLayout();
+ hLay->addStretch(1);
+ hLay->addWidget(PB);
+ hLay->addWidget(PBcancel);
+ hLay->addStretch(1);
+
+ lay->addLayout(hLay,5,0,1,6);
+
+ HomogenDisc->setLayout(lay);
+ if (HomogenDisc->exec()==QDialog::Accepted)
+ {
+ double dSimBox[6];
+ for (int i=0;i<6;++i) dSimBox[i]=BoxLine[i]->text().toDouble();
+ for (int i=0;i<3;++i)
+ {
+// if ((Check[i]->checkState()==Qt::Checked))// && (dSimBox[2*i+1]>dSimBox[2*i]))
+// {
+// FunctionParser fParse;
+// fParse.AddConstant("pi", 3.1415926535897932);
+// fParse.Parse(function[i]->text().toStdString(),coordVars.at(i).toStdString());
+// if (fParse.GetParseErrorType()!=FunctionParser::FP_NO_ERROR)
+// QMessageBox::warning(HomogenDisc,tr("Error reading grid function!"),QString(tr("fparser error message:\n%1").arg(fParse.ErrorMsg())));
+// else
+// {
+// double dStep=0;
+// if (Nodes[i]->value()>1) dStep=(dSimBox[2*i+1]-dSimBox[2*i])/(Nodes[i]->value()-1);
+// if (DelOldGrid->isChecked()) clGrid->ClearLines(i);
+// double dValue=0;
+// double dPos=0;
+// bool error=false;
+// for (int n=0;n<Nodes[i]->value();++n)
+// {
+// dPos=dSimBox[2*i]+n*dStep;
+// dValue=fParse.Eval(&dPos);
+// if (fParse.EvalError()!=0) error=true;
+// clGrid->AddDiscLine(i,dValue);
+// }
+// if (error) QMessageBox::warning(HomogenDisc,tr("Error evaluation grid function!"),QString(tr("An error occured evaluation the grid function f(%1)!").arg(coordVars.at(i))));
+// }
+// clGrid->Sort(i);
+// }
+ if (Nodes[i]->value()>0)// && (dSimBox[2*i+1]>dSimBox[2*i]))
+ {
+ double dStep=0;
+ if (Nodes[i]->value()>1) dStep=(dSimBox[2*i+1]-dSimBox[2*i])/(Nodes[i]->value()-1);
+ if (DelOldGrid->isChecked()) clGrid->ClearLines(i);
+ double* dValue=new double[Nodes[i]->value()];
+ for (int n=0;n<Nodes[i]->value();++n)
+ dValue[n]=dSimBox[2*i]+n*dStep;
+ std::string error = clGrid->AddDiscLines(i,Nodes[i]->value(),dValue,function[i]->text().toStdString());
+ delete[] dValue;
+ if (error.empty()==false) QMessageBox::warning(HomogenDisc,tr("Error evaluation grid function!"),QString(error.c_str()));
+ }
+ clGrid->Sort(i);
+ }
+ }
+ delete HomogenDisc;
+ Update();
+}
+
+void QCSGridEditor::BuildHomogenDisc()
+{
+ QDialog* HomogenDisc = new QDialog();
+ QGridLayout* lay = new QGridLayout();
+
+ lay->addWidget(new QLabel(tr("Create homogenous discretisation:")),0,0,1,3);
+ QCheckBox* DelOldGrid = new QCheckBox(tr("Clear old mesh"));
+ DelOldGrid->setChecked(true);
+ lay->addWidget(DelOldGrid,0,3);
+
+ lay->addWidget(new QLabel(tr("Min")),1,1);
+ lay->addWidget(new QLabel(tr("Max")),1,2);
+ lay->addWidget(new QLabel(tr("Lines")),1,3);
+// lay->addWidget(new QLabel(tr("X")),2,0);
+// lay->addWidget(new QLabel(tr("Y")),3,0);
+// lay->addWidget(new QLabel(tr("Z")),4,0);
+ QCheckBox* Check[3];
+ Check[0] = new QCheckBox(GetDirName(0));
+ lay->addWidget(Check[0],2,0);
+ Check[1] = new QCheckBox(GetDirName(1));
+ lay->addWidget(Check[1],3,0);
+ Check[2] = new QCheckBox(GetDirName(2));
+ lay->addWidget(Check[2],4,0);
+ QLineEdit* BoxLine[6];
+ QSpinBox* Nodes[3];
+ for (int i=0;i<3;++i)
+ {
+ BoxLine[2*i]= new QLineEdit(QString("%1").arg(clGrid->GetLine(i,0)));
+ lay->addWidget(BoxLine[2*i],i+2,1);
+ BoxLine[2*i+1]= new QLineEdit(QString("%1").arg(clGrid->GetLine(i,clGrid->GetQtyLines(i)-1)));
+ lay->addWidget(BoxLine[2*i+1],i+2,2);
+ Nodes[i] = new QSpinBox();
+ Nodes[i]->setRange(1,9999);
+ Nodes[i]->setValue(clGrid->GetQtyLines(i));
+ lay->addWidget(Nodes[i],i+2,3);
+ Check[i]->setChecked(true);
+ }
+ QPushButton* PB = new QPushButton(tr("Ok"));
+ QObject::connect(PB,SIGNAL(clicked()),HomogenDisc,SLOT(accept()));
+ QPushButton* PBcancel = new QPushButton(tr("Cancel"));
+ QObject::connect(PBcancel,SIGNAL(clicked()),HomogenDisc,SLOT(reject()));
+
+ QHBoxLayout* hLay = new QHBoxLayout();
+ hLay->addStretch(1);
+ hLay->addWidget(PB);
+ hLay->addWidget(PBcancel);
+ hLay->addStretch(1);
+
+ lay->addLayout(hLay,5,0,1,4);
+
+ HomogenDisc->setLayout(lay);
+ if (HomogenDisc->exec()==QDialog::Accepted)
+ {
+ double dSimBox[6];
+ for (int i=0;i<6;++i) dSimBox[i]=BoxLine[i]->text().toDouble();
+ for (int i=0;i<3;++i)
+ {
+ if ((Check[i]->checkState()==Qt::Checked))// && (dSimBox[2*i+1]>dSimBox[2*i]))
+ {
+ double dStep=0;
+ if (Nodes[i]->value()>1) dStep=(dSimBox[2*i+1]-dSimBox[2*i])/(Nodes[i]->value()-1);
+ if (DelOldGrid->isChecked()) clGrid->ClearLines(i);
+ for (int n=0;n<Nodes[i]->value();++n) clGrid->AddDiscLine(i,dSimBox[2*i]+n*dStep);
+ clGrid->Sort(i);
+ }
+// else if (Check[i]->checkState()==Qt::Checked)
+// {
+// clGrid->ClearLines(i);
+// if (Nodes[i]->value()>0) clGrid->AddDiscLine(i,dSimBox[2*i]);
+// }
+ }
+ }
+ delete HomogenDisc;
+ Update();
+}
+
+void QCSGridEditor::IncreaseResolution()
+{
+ QDialog* DiscInc = new QDialog();
+ QGridLayout* lay = new QGridLayout();
+
+ lay->addWidget(new QLabel(tr("Increase Resolution of Discretisation:")),0,0,1,2);
+
+ QCheckBox* Check[3];
+ QSpinBox* Spin[3];
+ Check[0] = new QCheckBox(tr("X - Factor: "));
+ Check[0]->setChecked(true);
+ Spin[0]=new QSpinBox();Spin[0]->setRange(2,9);
+ lay->addWidget(Check[0],2,0);
+ lay->addWidget(Spin[0],2,1);
+ Check[1] = new QCheckBox(tr("Y - Factor: "));
+ Check[1]->setChecked(true);
+ Spin[1]=new QSpinBox();Spin[1]->setRange(2,9);
+ lay->addWidget(Check[1],3,0);
+ lay->addWidget(Spin[1],3,1);
+ Check[2] = new QCheckBox(tr("Z - Factor: "));
+ Check[2]->setChecked(true);
+ Spin[2]=new QSpinBox();Spin[2]->setRange(2,9);
+ lay->addWidget(Check[2],4,0);
+ lay->addWidget(Spin[2],4,1);
+
+ QPushButton* PB = new QPushButton(tr("Ok"));
+ QObject::connect(PB,SIGNAL(clicked()),DiscInc,SLOT(accept()));
+ QPushButton* PBcancel = new QPushButton(tr("Cancel"));
+ QObject::connect(PBcancel,SIGNAL(clicked()),DiscInc,SLOT(reject()));
+
+ QHBoxLayout* hLay = new QHBoxLayout();
+ hLay->addStretch(1);
+ hLay->addWidget(PB);
+ hLay->addWidget(PBcancel);
+ hLay->addStretch(1);
+
+ lay->addLayout(hLay,5,0,1,2);
+
+ DiscInc->setLayout(lay);
+
+ if (DiscInc->exec()==QDialog::Accepted)
+ {
+ for (int i=0;i<3;++i)
+ if (Check[i]->checkState()==Qt::Checked)
+ {
+ clGrid->IncreaseResolution(i,Spin[i]->value());
+ }
+ }
+ Update();
+}
+
+void QCSGridEditor::EditX()
+{
+ Edit(0);
+}
+
+void QCSGridEditor::EditY()
+{
+ Edit(1);
+}
+
+void QCSGridEditor::EditZ()
+{
+ Edit(2);
+}
+
+double* QCSGridEditor::GetDoubleArrayFromString(int *count, QString qsValue)
+{
+ double* values=NULL;
+ *count = 0;
+ QStringList seq = qsValue.split(":");
+ if (seq.size()==3)
+ {
+ double start,step,stop;
+ bool ok;
+ start = seq.at(0).toDouble(&ok);
+ if (ok) step = seq.at(1).toDouble(&ok);
+ if (ok) stop = seq.at(2).toDouble(&ok);
+ if (ok)
+ {
+ int NrSteps = (int)((stop-start)/step);
+ if ((NrSteps>=0) && (NrSteps<1000))
+ {
+ values = new double[NrSteps+1];
+ *count = NrSteps+1;
+ for (int n=0;n<=NrSteps;++n)
+ values[n]=start+n*step;
+ }
+ }
+ }
+ return values;
+}
+
+void QCSGridEditor::Edit(int direct)
+{
+ QTextEdit *Line = new QTextEdit(clGrid->GetLinesAsString(direct).c_str());
+ Line->setReadOnly(QCSX_Settings.GetEdit()==false);
+ QDialog* EditDisc = new QDialog(this);
+
+ if (QCSX_Settings.GetEdit())
+ EditDisc->setWindowTitle(tr("Edit Discratisation"));
+ else
+ EditDisc->setWindowTitle(tr("View Discratisation"));
+ QGridLayout* lay = new QGridLayout();
+
+ lay->addWidget(Line,0,0,1,4);
+
+ if (QCSX_Settings.GetEdit())
+ lay->addWidget(new QLabel(tr("Allowed syntax example: 0,10, 20, 30:1.5e1:100, 50 , sqrt(1000:-10:200)")),1,0,1,4);
+ QPushButton* PB = new QPushButton(tr("Ok"));
+ QObject::connect(PB,SIGNAL(clicked()),EditDisc,SLOT(accept()));
+ lay->addWidget(PB,2,1);
+ if (QCSX_Settings.GetEdit())
+ {
+ PB = new QPushButton(tr("Cancel"));
+ QObject::connect(PB,SIGNAL(clicked()),EditDisc,SLOT(reject()));
+ lay->addWidget(PB,2,2);
+ }
+
+ lay->setRowStretch(0,1);
+ lay->setColumnStretch(0,1);
+ lay->setColumnStretch(3,1);
+
+ EditDisc->setLayout(lay);
+ if (EditDisc->exec()==QDialog::Accepted && QCSX_Settings.GetEdit())
+ {
+ clGrid->ClearLines(direct);
+ QStringList gridValues = Line->toPlainText().split(",");
+ for (int n=0;n<gridValues.size();++n)
+ {
+ QString qsValue = gridValues.at(n);
+ double val;
+ bool ok;
+ val = qsValue.toDouble(&ok);
+ if (ok) clGrid->AddDiscLine(direct,val);
+ else
+ {
+ QString FloatExp("-?\\d+(.\\d+)?(e-?\\d+)?");
+ QRegExp qre(FloatExp + ":" + FloatExp + ":" + FloatExp);
+ if (qre.exactMatch(qsValue))
+ {
+ int count=0;
+ double* values = GetDoubleArrayFromString(&count,qsValue);
+ if (values) clGrid->AddDiscLines(direct,count,values);
+ }
+ else if (qsValue.contains(QRegExp(FloatExp + ":" + FloatExp + ":" + FloatExp)))
+ {
+ qre.indexIn(qsValue);
+ QString seq = qre.cap();
+// cerr << "found-->" << seq.toStdString() << endl;
+ QString function = qsValue.replace(QRegExp(FloatExp + ":" + FloatExp + ":" + FloatExp),GetDirName(direct));
+// cerr << function.toStdString() << endl;
+ int count=0;
+ double* values = GetDoubleArrayFromString(&count,seq);
+ if (values) clGrid->AddDiscLines(direct,count,values,function.toStdString());
+ }
+ }
+ }
+ }
+ Update();
+}
+
+
+void QCSGridEditor::DetectEdges()
+{
+ QDialog* Edges = new QDialog();
+ QGridLayout* lay = new QGridLayout();
+
+ lay->addWidget(new QLabel(tr("Detect Edges for Discretisation:")),0,0,1,1);
+
+ QCheckBox* Check[3];
+ Check[0] = new QCheckBox(tr("X - Active "));
+ Check[0]->setChecked(true);
+ lay->addWidget(Check[0],2,0);
+ Check[1] = new QCheckBox(tr("Y - Active "));
+ Check[1]->setChecked(true);
+ lay->addWidget(Check[1],3,0);
+ Check[2] = new QCheckBox(tr("Z - Active "));
+ Check[2]->setChecked(true);
+ lay->addWidget(Check[2],4,0);
+
+ QPushButton* PB = new QPushButton(tr("Ok"));
+ QObject::connect(PB,SIGNAL(clicked()),Edges,SLOT(accept()));
+ QPushButton* PBcancel = new QPushButton(tr("Cancel"));
+ QObject::connect(PBcancel,SIGNAL(clicked()),Edges,SLOT(reject()));
+
+ QHBoxLayout* hLay = new QHBoxLayout();
+ hLay->addStretch(1);
+ hLay->addWidget(PB);
+ hLay->addWidget(PBcancel);
+ hLay->addStretch(1);
+
+ lay->addLayout(hLay,5,0,1,1);
+
+ Edges->setLayout(lay);
+
+ if (Edges->exec()==QDialog::Accepted)
+ {
+ for (int i=0;i<3;++i)
+ if (Check[i]->checkState()==Qt::Checked)
+ {
+ emit signalDetectEdges(i);
+ }
+ }
+ Update();
+}
+
+void QCSGridEditor::SetDeltaUnit(QString val)
+{
+ bool succ=false;
+ double dDal=val.toDouble(&succ);
+ if ((val>0) && succ) clGrid->SetDeltaUnit(dDal);
+}
+
+void QCSGridEditor::Update()
+{
+ clGrid->Sort(0);
+ clGrid->Sort(1);
+ clGrid->Sort(2);
+ for (size_t i=0;i<3;++i)
+ {
+ SimBox.at(2*i)->setText(QString("%1").arg(clGrid->GetLine(i,0)));
+ SimBox.at(2*i+1)->setText(QString("%1").arg(clGrid->GetLine(i,clGrid->GetQtyLines(i)-1)));
+ NodeQty.at(i)->setText(QString("%1").arg(clGrid->GetQtyLines(i)));
+ m_DirNames[i]->setText(GetDirName(i));
+ m_PlanePos[i]->setRange(0,clGrid->GetQtyLines(i)-1);
+ m_NormNames[i]->setText(GetNormName(i)+ tr(" plane: "));
+ }
+ SetGridPlaneX(m_PlanePos[0]->value());
+ SetGridPlaneY(m_PlanePos[0]->value());
+ SetGridPlaneZ(m_PlanePos[0]->value());
+ UnitLength->setText(QString("%1").arg(clGrid->GetDeltaUnit()));
+ emit GridChanged();
+}
+
+void QCSGridEditor::SetOpacity(int val)
+{
+ OpacitySlider->setValue(val);
+}
+
+int QCSGridEditor::GetOpacity()
+{
+ return OpacitySlider->value();
+}
+
+QString QCSGridEditor::GetDirName(int ny)
+{
+ if (clGrid->GetMeshType()==0)
+ {
+ switch (ny)
+ {
+ case 0:
+ return "x";
+ case 1:
+ return "y";
+ case 2:
+ return "z";
+ }
+ }
+ if (clGrid->GetMeshType()==1)
+ {
+ switch (ny)
+ {
+ case 0:
+ return "r";
+ case 1:
+ return QChar(0xb1, 0x03);
+ case 2:
+ return "z";
+ }
+ }
+ return "";
+}
+
+QString QCSGridEditor::GetNormName(int ny)
+{
+ if (clGrid->GetMeshType()==0)
+ {
+ switch (ny)
+ {
+ case 0:
+ return "yz";
+ case 1:
+ return "zx";
+ case 2:
+ return "xy";
+ }
+ }
+ if (clGrid->GetMeshType()==1)
+ {
+ switch (ny)
+ {
+ case 0:
+ return QString(QChar(0xb1, 0x03)) + "z";
+ case 1:
+ return "zr";
+ case 2:
+ return "r" + QString(QChar(0xb1, 0x03));
+ }
+ }
+ return "";
+}
diff --git a/QCSXCAD/QCSGridEditor.h b/QCSXCAD/QCSGridEditor.h
new file mode 100644
index 0000000..f54bf42
--- /dev/null
+++ b/QCSXCAD/QCSGridEditor.h
@@ -0,0 +1,87 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _QCSGRIDEDITOR_H_
+#define _QCSGRIDEDITOR_H_
+
+#include <QWidget>
+#include <QToolBar>
+#include <QString>
+#include <QVector>
+#include <QSlider>
+#include <QLabel>
+#include <QLineEdit>
+
+class CSRectGrid;
+
+class QCSGridEditor : public QWidget
+{
+ Q_OBJECT
+public:
+ QCSGridEditor(CSRectGrid* grid, QWidget* parent = 0);
+ virtual ~QCSGridEditor();
+
+ QToolBar* BuildToolbar();
+ QWidget* BuildPlanePosWidget();
+
+ QString GetDirName(int ny);
+ QString GetNormName(int ny);
+
+ int GetOpacity();
+
+signals:
+ void OpacityChange(int);
+ void signalDetectEdges(int);
+ void GridChanged();
+ void GridPlaneXChanged(int);
+ void GridPlaneYChanged(int);
+ void GridPlaneZChanged(int);
+
+public slots:
+ void Update();
+ void SetOpacity(int val);
+ void EditX();
+ void EditY();
+ void EditZ();
+ void Edit(int direct);
+ void SetGridPlaneX(int pos);
+ void SetGridPlaneY(int pos);
+ void SetGridPlaneZ(int pos);
+
+protected slots:
+ void BuildHomogenDisc();
+ void BuildInHomogenDisc();
+ void IncreaseResolution();
+ void DetectEdges();
+ void SetDeltaUnit(QString val);
+
+protected:
+ CSRectGrid* clGrid;
+ QVector<QLabel*> SimBox;
+ QVector<QLabel*> NodeQty;
+ //QComboBox* UnitLength;
+ QLineEdit* UnitLength;
+ QSlider* OpacitySlider;
+ QLabel* m_DirNames[3];
+ QSlider* m_PlanePos[3];
+ QLabel* m_NormNames[3];
+ QLabel* m_PlanePosValue[3];
+
+ double* GetDoubleArrayFromString(int *count, QString qsValue);
+};
+
+#endif //_QCSGRIDEDITOR_H_
diff --git a/QCSXCAD/QCSPrimEditor.cpp b/QCSXCAD/QCSPrimEditor.cpp
new file mode 100644
index 0000000..63b4896
--- /dev/null
+++ b/QCSXCAD/QCSPrimEditor.cpp
@@ -0,0 +1,746 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QLabel>
+#include <QPushButton>
+#include <QHBoxLayout>
+#include <QLineEdit>
+#include <QFormLayout>
+
+#include "QCSPrimEditor.h"
+#include "QCSXCAD_Global.h"
+
+#include "CSPrimPoint.h"
+#include "CSPrimBox.h"
+#include "CSPrimMultiBox.h"
+#include "CSPrimSphere.h"
+#include "CSPrimSphericalShell.h"
+#include "CSPrimCylinder.h"
+#include "CSPrimCylindricalShell.h"
+#include "CSPrimPolygon.h"
+#include "CSPrimLinPoly.h"
+#include "CSPrimRotPoly.h"
+#include "CSPrimCurve.h"
+#include "CSPrimWire.h"
+#include "CSPrimUserDefined.h"
+
+QCSPrimEditor::QCSPrimEditor(ContinuousStructure *CS, CSPrimitives* prim, QWidget* parent) : QDialog(parent)
+{
+ clCS=CS;
+ CSPrim=prim;
+
+ MainLayout = new QVBoxLayout();
+
+ switch (CSPrim->GetType())
+ {
+ case CSPrimitives::BOX:
+ CSPrimEdit = new QCSPrimBoxLayout(CSPrim->ToBox());
+ setWindowTitle(tr("Box Editor"));
+ break;
+ case CSPrimitives::MULTIBOX:
+ CSPrimEdit = new QCSPrimMultiBoxLayout(CSPrim->ToMultiBox());
+ setWindowTitle(tr("Multi-Box Editor"));
+ break;
+ case CSPrimitives::SPHERE:
+ CSPrimEdit = new QCSPrimSphereLayout(CSPrim->ToSphere());
+ setWindowTitle(tr("Sphere Editor"));
+ break;
+ case CSPrimitives::CYLINDER:
+ CSPrimEdit = new QCSPrimCylinderLayout(CSPrim->ToCylinder());
+ setWindowTitle(tr("Cylinder Editor"));
+ break;
+ case CSPrimitives::CYLINDRICALSHELL:
+ CSPrimEdit = new QCSPrimCylindricalShellLayout(CSPrim->ToCylindricalShell());
+ setWindowTitle(tr("CylindricalShell Editor"));
+ break;
+ case CSPrimitives::POLYGON:
+ CSPrimEdit = new QCSPrimPolygonLayout(CSPrim->ToPolygon());
+ setWindowTitle(tr("Polygon Editor"));
+ break;
+ case CSPrimitives::USERDEFINED:
+ CSPrimEdit = new QCSPrimUserDefinedLayout(CSPrim->ToUserDefined());
+ setWindowTitle(tr("User Defined Primitive Editor"));
+ break;
+ default:
+ setWindowTitle(tr("default Editor"));
+ CSPrimEdit = new QCSPrimitiveLayout(CSPrim);
+ break;
+ };
+
+ MainLayout->addWidget(BuildGeneral());
+
+ QGroupBox* gb = new QGroupBox(tr("Geometrical Properties"));
+ gb->setLayout(CSPrimEdit);
+
+ MainLayout->addWidget(gb);
+
+ MainLayout->addStretch();
+
+ MainLayout->addLayout(BuildButtons());
+
+
+ setLayout(MainLayout);
+
+ setAttribute(Qt::WA_DeleteOnClose, true);
+ setWindowModality(Qt::ApplicationModal);
+}
+
+QCSPrimEditor::~QCSPrimEditor()
+{
+}
+
+void QCSPrimEditor::Reset()
+{
+ PrioSpinBox->setValue(CSPrim->GetPriority());
+ UpdatePropertyCB();
+ CSPrimEdit->GetValues();
+}
+
+void QCSPrimEditor::Save()
+{
+ CSPrim->SetPriority(PrioSpinBox->value());
+ CSProperties* prop = clCS->GetProperty((unsigned int)PropertiesComboBox->currentIndex());
+ if (prop==NULL)
+ {
+ std::cerr << __func__ << ": Error, property invalid!" << std::endl;
+ reject();
+ return;
+ }
+ if (prop!=CSPrim->GetProperty())
+ prop->AddPrimitive(CSPrim);
+ CSPrimEdit->SetValues();
+ accept();
+}
+
+void QCSPrimEditor::Cancel()
+{
+ reject();
+}
+
+QGroupBox* QCSPrimEditor::BuildGeneral()
+{
+ QGroupBox* box= new QGroupBox("General");
+ QGridLayout* grid = new QGridLayout();
+
+ grid->addWidget(new QLabel(QString(tr("ID: %1")).arg(CSPrim->GetID())),0,0);
+
+ grid->addWidget(new QLabel(tr("Priority: ")),0,1);
+ PrioSpinBox = new QSpinBox();
+ PrioSpinBox->setRange(-1,1000);
+ PrioSpinBox->setValue(CSPrim->GetPriority());
+ PrioSpinBox->setEnabled(QCSX_Settings.GetEdit());
+ grid->addWidget(PrioSpinBox,0,2);
+ PropertiesComboBox = new QComboBox();
+ PropertiesComboBox->setEnabled(QCSX_Settings.GetEdit());
+
+ UpdatePropertyCB();
+
+ grid->addWidget(new QLabel(QString(tr("Choose Property: "))),1,0);
+ grid->addWidget(PropertiesComboBox,1,1,1,2);
+
+ box->setLayout(grid);
+
+ return box;
+}
+
+QLayout* QCSPrimEditor::BuildButtons()
+{
+ QHBoxLayout* lay = new QHBoxLayout();
+
+ QPushButton* ok = new QPushButton(tr("Ok"));
+ QObject::connect(ok,SIGNAL(clicked()),this,SLOT(Save()));
+ lay->addWidget(ok);
+ if (QCSX_Settings.GetEdit())
+ {
+ QPushButton* reset = new QPushButton(tr("Reset"));
+ QObject::connect(reset,SIGNAL(clicked()),this,SLOT(Reset()));
+ lay->addWidget(reset);
+ QPushButton* cancel = new QPushButton(tr("Cancel"));
+ QObject::connect(cancel,SIGNAL(clicked()),this,SLOT(Cancel()));
+ lay->addWidget(cancel);
+ }
+
+ lay->addStretch();
+ return lay;
+}
+
+void QCSPrimEditor::UpdatePropertyCB()
+{
+ PropertiesComboBox->clear();
+ for (size_t i=0;i<clCS->GetQtyProperties();++i)
+ {
+ QString str;
+ CSProperties* prop=clCS->GetProperty(i);
+ if (prop==NULL) break;
+ str=QString(prop->GetName().c_str());
+ switch (prop->GetType())
+ {
+ case CSProperties::UNKNOWN:
+ str+=tr(" (Unknown)");
+ break;
+ case CSProperties::MATERIAL:
+ str+=tr(" (Material)");
+ break;
+ case CSProperties::METAL:
+ str+=tr(" (Metal)");
+ break;
+ case CSProperties::EXCITATION:
+ str+=tr(" (Excitation)");
+ break;
+ case CSProperties::PROBEBOX:
+ str+=tr(" (Charge-Box)");
+ break;
+ case CSProperties::RESBOX:
+ str+=tr(" (Res-Box)");
+ break;
+ case CSProperties::DUMPBOX:
+ str+=tr(" (Dump-Box)");
+ break;
+ };
+ PropertiesComboBox->addItem(str);
+ }
+
+ CSProperties* prop=CSPrim->GetProperty();
+ if (prop==NULL) PropertiesComboBox->setCurrentIndex(0);
+ else PropertiesComboBox->setCurrentIndex(prop->GetID());
+}
+
+QCSPrimitiveLayout::QCSPrimitiveLayout(CSPrimitives *prim, QWidget *parent) : QGridLayout(parent)
+{
+ clPrim = prim;
+}
+
+QCSPrimitiveLayout::~QCSPrimitiveLayout()
+{
+}
+
+void QCSPrimitiveLayout::SetValues()
+{
+}
+
+void QCSPrimitiveLayout::GetValues()
+{
+}
+
+
+QCSPrimBoxLayout::QCSPrimBoxLayout(CSPrimBox* prim, QWidget *parent) : QCSPrimitiveLayout(prim, parent)
+{
+ clBox=prim;
+
+ addWidget(new QLabel(tr("1. Point")),0,0,1,6);
+ addWidget(new QLabel("X:"),1,0);
+ Lines[0]=new QLineEdit();
+ addWidget(Lines[0],1,1);
+ addWidget(new QLabel("Y:"),1,2);
+ Lines[2]=new QLineEdit();
+ addWidget(Lines[2],1,3);
+ addWidget(new QLabel("Z:"),1,4);
+ Lines[4]=new QLineEdit();
+ addWidget(Lines[4],1,5);
+
+ addWidget(new QLabel(tr("2. Point")),2,0,1,6);
+ addWidget(new QLabel("X:"),3,0);
+ Lines[1]=new QLineEdit();addWidget(Lines[1],3,1);
+ addWidget(new QLabel("Y:"),3,2);
+ Lines[3]=new QLineEdit();addWidget(Lines[3],3,3);
+ addWidget(new QLabel("Z:"),3,4);
+ Lines[5]=new QLineEdit();addWidget(Lines[5],3,5);
+
+ for (int i=0;i<6;++i)
+ Lines[i]->setEnabled(QCSX_Settings.GetEdit());
+
+ GetValues();
+}
+
+QCSPrimBoxLayout::~QCSPrimBoxLayout()
+{
+}
+
+void QCSPrimBoxLayout::SetValues()
+{
+ bool bOk;
+ double dVal;
+ QString line;
+ for (size_t i=0; i< 6; ++i)
+ {
+ line=Lines[i]->text();
+ dVal=line.toDouble(&bOk);
+ if (bOk) clBox->SetCoord(i,dVal);
+ else clBox->SetCoord(i,line.toStdString());
+ }
+}
+
+void QCSPrimBoxLayout::GetValues()
+{
+ ParameterScalar* ps;
+ for (size_t i=0; i< 6; ++i)
+ {
+ ps=clBox->GetCoordPS(i);
+ if (ps->GetMode()) Lines[i]->setText(ps->GetString().c_str());
+ else Lines[i]->setText(QString("%1").arg(ps->GetValue()));
+ }
+}
+
+QCSPrimSphereLayout::QCSPrimSphereLayout(CSPrimSphere* prim, QWidget *parent) : QCSPrimitiveLayout(prim, parent)
+{
+ clSphere=prim;
+
+ addWidget(new QLabel(tr("Center Point")),0,0,1,6);
+ addWidget(new QLabel("X:"),1,0);
+ Lines[0]=new QLineEdit();addWidget(Lines[0],1,1);
+ addWidget(new QLabel("Y:"),1,2);
+ Lines[1]=new QLineEdit();addWidget(Lines[1],1,3);
+ addWidget(new QLabel("Z:"),1,4);
+ Lines[2]=new QLineEdit();addWidget(Lines[2],1,5);
+
+ addWidget(new QLabel(tr("Radius")),2,0,1,2);
+ Lines[3]=new QLineEdit();addWidget(Lines[3],2,3,1,4);
+
+ for (int i=0;i<4;++i)
+ Lines[i]->setEnabled(QCSX_Settings.GetEdit());
+
+ GetValues();
+}
+
+QCSPrimSphereLayout::~QCSPrimSphereLayout()
+{
+}
+
+void QCSPrimSphereLayout::SetValues()
+{
+ bool bOk;
+ double dVal;
+ QString line;
+ for (size_t i=0; i< 3; ++i)
+ {
+ line=Lines[i]->text();
+ dVal=line.toDouble(&bOk);
+ if (bOk) clSphere->SetCoord(i,dVal);
+ else clSphere->SetCoord(i,line.toLatin1().data());
+ }
+
+ ParameterScalar* ps=clSphere->GetRadiusPS();
+ line=Lines[3]->text();
+ dVal=line.toDouble(&bOk);
+ if (bOk) ps->SetValue(dVal);
+ else ps->SetValue(line.toLatin1().data());
+
+}
+
+void QCSPrimSphereLayout::GetValues()
+{
+ ParameterScalar* ps;
+ for (size_t i=0; i< 3; ++i)
+ {
+ ps=clSphere->GetCoordPS(i);
+ if (ps->GetMode()) Lines[i]->setText(ps->GetString().c_str());
+ else Lines[i]->setText(QString("%1").arg(ps->GetValue()));
+ }
+
+ ps=clSphere->GetRadiusPS();
+ if (ps->GetMode()) Lines[3]->setText(ps->GetString().c_str());
+ else Lines[3]->setText(QString("%1").arg(ps->GetValue()));
+}
+
+//****Cylinder
+QCSPrimCylinderLayout::QCSPrimCylinderLayout(CSPrimCylinder* prim, QWidget *parent) : QCSPrimitiveLayout(prim, parent)
+{
+ clCylinder=prim;
+
+ addWidget(new QLabel(tr("Start Point")),0,0,1,6);
+ addWidget(new QLabel("X:"),1,0);
+ Lines[0]=new QLineEdit();addWidget(Lines[0],1,1);
+ addWidget(new QLabel("Y:"),1,2);
+ Lines[2]=new QLineEdit();addWidget(Lines[2],1,3);
+ addWidget(new QLabel("Z:"),1,4);
+ Lines[4]=new QLineEdit();addWidget(Lines[4],1,5);
+
+ addWidget(new QLabel(tr("End Point")),2,0,1,6);
+ addWidget(new QLabel("X:"),3,0);
+ Lines[1]=new QLineEdit();addWidget(Lines[1],3,1);
+ addWidget(new QLabel("Y:"),3,2);
+ Lines[3]=new QLineEdit();addWidget(Lines[3],3,3);
+ addWidget(new QLabel("Z:"),3,4);
+ Lines[5]=new QLineEdit();addWidget(Lines[5],3,5);
+
+ addWidget(new QLabel(tr("Radius")),4,0,1,2);
+ Lines[6]=new QLineEdit();addWidget(Lines[6],4,3,1,4);
+
+ for (int i=0;i<7;++i)
+ Lines[i]->setEnabled(QCSX_Settings.GetEdit());
+
+ GetValues();
+}
+
+QCSPrimCylinderLayout::~QCSPrimCylinderLayout()
+{
+}
+
+void QCSPrimCylinderLayout::SetValues()
+{
+ bool bOk;
+ double dVal;
+ QString line;
+ for (size_t i=0; i< 6; ++i)
+ {
+ line=Lines[i]->text();
+ dVal=line.toDouble(&bOk);
+ if (bOk) clCylinder->SetCoord(i,dVal);
+ else clCylinder->SetCoord(i,line.toLatin1().data());
+ }
+
+ ParameterScalar* ps=clCylinder->GetRadiusPS();
+ line=Lines[6]->text();
+ dVal=line.toDouble(&bOk);
+ if (bOk) ps->SetValue(dVal);
+ else ps->SetValue(line.toLatin1().data());
+
+}
+
+void QCSPrimCylinderLayout::GetValues()
+{
+ ParameterScalar* ps;
+ for (size_t i=0; i< 6; ++i)
+ {
+ ps=clCylinder->GetCoordPS(i);
+ if (ps->GetMode()) Lines[i]->setText(ps->GetString().c_str());
+ else Lines[i]->setText(QString("%1").arg(ps->GetValue()));
+ }
+ ps=clCylinder->GetRadiusPS();
+ if (ps->GetMode()) Lines[6]->setText(ps->GetString().c_str());
+ else Lines[6]->setText(QString("%1").arg(ps->GetValue()));
+}
+
+//****CylindricalShell
+QCSPrimCylindricalShellLayout::QCSPrimCylindricalShellLayout(CSPrimCylindricalShell* prim, QWidget *parent) : QCSPrimCylinderLayout(prim, parent)
+{
+ clCylindricalShell=prim;
+
+ addWidget(new QLabel(tr("ShellWidth")),5,0,1,2);
+ m_ShellWidth=new QLineEdit();addWidget(m_ShellWidth,5,3,1,4);
+
+ for (int i=0;i<8;++i)
+ m_ShellWidth->setEnabled(QCSX_Settings.GetEdit());
+
+ GetValues();
+}
+
+QCSPrimCylindricalShellLayout::~QCSPrimCylindricalShellLayout()
+{
+}
+
+void QCSPrimCylindricalShellLayout::SetValues()
+{
+ QCSPrimCylinderLayout::SetValues();
+
+ bool bOk;
+ double dVal;
+ QString line;
+
+ ParameterScalar* ps = clCylindricalShell->GetShellWidthPS();
+ line = m_ShellWidth->text();
+ dVal = line.toDouble(&bOk);
+ if (bOk)
+ ps->SetValue(dVal);
+ else
+ ps->SetValue(line.toLatin1().constData());
+}
+
+void QCSPrimCylindricalShellLayout::GetValues()
+{
+ QCSPrimCylinderLayout::GetValues();
+
+ ParameterScalar* ps = clCylindricalShell->GetShellWidthPS();
+ if (ps->GetMode())
+ m_ShellWidth->setText(ps->GetString().c_str());
+ else
+ m_ShellWidth->setText(QString("%1").arg(ps->GetValue()));
+}
+
+/*****************MultiBox*****/
+QCSPrimMultiBoxLayout::QCSPrimMultiBoxLayout(CSPrimMultiBox* prim, QWidget *parent) : QCSPrimitiveLayout(prim, parent)
+{
+ clMultiBox=prim;
+
+ QPushButton *addButton = new QPushButton("Add Box");
+ QObject::connect(addButton,SIGNAL(clicked()),this,SLOT(NewBox()));
+ addWidget(addButton,0,0);
+ addButton->setEnabled(QCSX_Settings.GetEdit());
+
+ QPushButton *editButton = new QPushButton("Edit Box");
+ QObject::connect(editButton,SIGNAL(clicked()),this,SLOT(EditBox()));
+ addWidget(editButton,0,1);
+ editButton->setEnabled(QCSX_Settings.GetEdit());
+
+ QPushButton *deleteButton = new QPushButton("Delete Box");
+ QObject::connect(deleteButton,SIGNAL(clicked()),this,SLOT(DeleteBox()));
+ addWidget(deleteButton,0,2);
+ deleteButton->setEnabled(QCSX_Settings.GetEdit());
+
+ qBoxList = new QListWidget();
+ addWidget(qBoxList,1,0,1,3);
+ for (unsigned int i=0;i<clMultiBox->GetQtyBoxes();++i)
+ {
+ qBoxList->addItem(tr("Box #%1").arg(i));
+ }
+ qBoxList->setEnabled(QCSX_Settings.GetEdit());
+
+ GetValues();
+}
+
+QCSPrimMultiBoxLayout::~QCSPrimMultiBoxLayout()
+{
+}
+
+void QCSPrimMultiBoxLayout::SetValues()
+{
+
+
+}
+
+void QCSPrimMultiBoxLayout::GetValues()
+{
+
+}
+
+void QCSPrimMultiBoxLayout::NewBox(QListWidgetItem* item)
+{
+ UNUSED(item);
+// unsigned int nr=qBoxList->count()
+// clMultiBox->ClearOverlap();
+// qBoxList->addItem(tr("Box #%1").arg(nr));
+// if (item==NULL) clMultiBox->AddBox();
+// else clMultiBox->AddBox(qBoxList->row(item));
+}
+
+void QCSPrimMultiBoxLayout::DeleteBox(QListWidgetItem* item)
+{
+ UNUSED(item);
+}
+
+void QCSPrimMultiBoxLayout::EditBox(QListWidgetItem* item)
+{
+ UNUSED(item);
+}
+
+//***********************************************************************************//
+QCSPrimPolygonLayout::QCSPrimPolygonLayout(CSPrimPolygon* prim, QWidget *parent) : QCSPrimitiveLayout(prim, parent)
+{
+ clPoly=prim;
+
+ addWidget(new QLabel(tr("Polygon Plane")),0,0);
+ NormVec = new QComboBox();
+ NormVec->addItem(tr("yz-plane"));
+ NormVec->addItem(tr("zx-plane"));
+ NormVec->addItem(tr("xy-plane"));
+ QObject::connect(NormVec,SIGNAL(currentIndexChanged(int)),this,SLOT(NormVecChanged()));
+ addWidget(NormVec,0,1);
+ NormVec->setEnabled(QCSX_Settings.GetEdit());
+
+ addWidget(new QLabel(tr("Polygon Elevation")),1,0);
+ Elevation = new QLineEdit();;
+ addWidget(Elevation,1,1);
+ Elevation->setEnabled(QCSX_Settings.GetEdit());
+
+ QGroupBox* gb = new QGroupBox(tr("Polygon Vertices"));
+ QFormLayout* gbl = new QFormLayout();
+ gb->setLayout(gbl);
+ addWidget(gb,2,0,1,2);
+
+ CoordLineX = new QLineEdit();
+ gbl->addRow(tr("X_1"),CoordLineX);
+ CoordLineX->setEnabled(QCSX_Settings.GetEdit());
+ CoordLineY = new QLineEdit();
+ gbl->addRow(tr("X_2"),CoordLineY);
+ CoordLineY->setEnabled(QCSX_Settings.GetEdit());
+
+ GetValues();
+}
+
+QCSPrimPolygonLayout::~QCSPrimPolygonLayout()
+{
+}
+
+void QCSPrimPolygonLayout::SetValues()
+{
+ int ind = NormVec->currentIndex();
+ clPoly->SetNormDir(ind);
+ ParameterScalar* ps;
+ bool bOk;
+ double dVal;
+ QString line;
+
+ ps=clPoly->GetElevationPS();
+ line=Elevation->text();
+ dVal=line.toDouble(&bOk);
+ if (bOk) ps->SetValue(dVal);
+ else ps->SetValue(line.toStdString());
+
+ clPoly->ClearCoords();
+
+ QStringList strListX = CoordLineX->text().split(",",QString::SkipEmptyParts);
+ QStringList strListY = CoordLineY->text().split(",",QString::SkipEmptyParts);
+
+ for (int i=0; (i<strListX.size()) && (i<strListY.size()) ; ++i)
+ {
+
+ QString x1 = strListX.at(i);
+ QString x2 = strListY.at(i);
+
+ if (x1.isEmpty() && x2.isEmpty()) return;
+
+ dVal=x1.toDouble(&bOk);
+ if (bOk) clPoly->AddCoord(dVal);
+ else clPoly->AddCoord(line.toStdString());
+
+ dVal=x2.toDouble(&bOk);
+ if (bOk) clPoly->AddCoord(dVal);
+ else clPoly->AddCoord(line.toStdString());
+ }
+}
+
+void QCSPrimPolygonLayout::GetValues()
+{
+ NormVec->setCurrentIndex(clPoly->GetNormDir());
+ ParameterScalar* ps;
+ ps=clPoly->GetElevationPS();
+ if (ps->GetMode()) Elevation->setText(ps->GetString().c_str());
+ else Elevation->setText(QString("%1").arg(ps->GetValue()));
+
+ QStringList strListX;
+ QStringList strListY;
+
+ for (size_t i=0; i<clPoly->GetQtyCoords(); ++i)
+ {
+ ps=clPoly->GetCoordPS(2*i);
+ if (ps)
+ {
+ if (ps->GetMode()) strListX.append(ps->GetString().c_str());
+ else strListX.append(QString("%1").arg(ps->GetValue()));
+ }
+
+ ps=clPoly->GetCoordPS(2*i+1);
+ if (ps)
+ {
+ if (ps->GetMode()) strListY.append(ps->GetString().c_str());
+ else strListY.append(QString("%1").arg(ps->GetValue()));
+ }
+ }
+ CoordLineX->setText(strListX.join(", "));
+ CoordLineY->setText(strListY.join(", "));
+}
+
+void QCSPrimPolygonLayout::NormVecChanged()
+{
+// QStringList headers;
+// switch (NormVec->currentIndex())
+// {
+// case 0:
+// headers << "x" << "y";
+// break;
+// case 1:
+// headers << "y" << "z";
+// break;
+// case 2:
+// headers << "z" << "x";
+// break;
+// default:
+// headers << "x" << "y";
+// break;
+// }
+// CoordTable->setHorizontalHeaderLabels(headers);
+}
+
+//***********************************************************************************//
+QCSPrimUserDefinedLayout::QCSPrimUserDefinedLayout(CSPrimUserDefined* prim, QWidget *parent) : QCSPrimitiveLayout(prim, parent)
+{
+ clUserDef=prim;
+
+ int row=0;
+ addWidget(new QLabel(tr("Choose Coordinate System")),row++,0);
+ CoordSystem = new QComboBox();
+ CoordSystem->addItem("Cartesian Coord. System (x,y,z)");
+ CoordSystem->addItem("Cartesian & Cylindrical Coord. System (x,y,z,r,a)");
+ CoordSystem->addItem("Cartesian & Spherical Coord. System (x,y,z,r,a,t)");
+ addWidget(CoordSystem,row++,0);
+ CoordSystem->setEnabled(QCSX_Settings.GetEdit());
+
+ QGroupBox* SysShiftGrp = new QGroupBox(tr("Shift Coordinate System"));
+ addWidget(SysShiftGrp,row++,0);
+
+ QGridLayout* lay = new QGridLayout;
+ SysShiftGrp->setLayout(lay);
+
+ lay->addWidget(new QLabel(tr("X-Shift:")),0,0);
+ CoordShift[0]=new QLineEdit();
+ lay->addWidget(CoordShift[0],0,1);
+ lay->addWidget(new QLabel(tr("Y-Shift:")),1,0);
+ CoordShift[1]=new QLineEdit();
+ lay->addWidget(CoordShift[1],1,1);
+ lay->addWidget(new QLabel(tr("Z-Shift:")),2,0);
+ CoordShift[2]=new QLineEdit();
+ lay->addWidget(CoordShift[2],2,1);
+ for (int i=0;i<3;++i)
+ CoordShift[i]->setEnabled(QCSX_Settings.GetEdit());
+
+ addWidget(new QLabel(tr("Define Bool-Function for this Primitive in chosen Coord. System:")),row++,0);
+ FunctionLine = new QLineEdit();
+ addWidget(FunctionLine,row++,0);
+ FunctionLine->setEnabled(QCSX_Settings.GetEdit());
+
+ GetValues();
+}
+
+QCSPrimUserDefinedLayout::~QCSPrimUserDefinedLayout()
+{
+}
+
+void QCSPrimUserDefinedLayout::SetValues()
+{
+ clUserDef->SetCoordSystem((CSPrimUserDefined::UserDefinedCoordSystem)CoordSystem->currentIndex());
+ clUserDef->SetFunction(FunctionLine->text().toStdString().c_str());
+
+ bool bOk;
+ double dVal;
+ QString line;
+ ParameterScalar* ps;
+ for (size_t i=0; i< 3; ++i)
+ {
+ ps=clUserDef->GetCoordShiftPS(i);
+ line=CoordShift[i]->text();
+ dVal=line.toDouble(&bOk);
+ if (bOk) ps->SetValue(dVal);
+ else ps->SetValue(line.toLatin1().data());
+ }
+}
+
+void QCSPrimUserDefinedLayout::GetValues()
+{
+ CoordSystem->setCurrentIndex(clUserDef->GetCoordSystem());
+ FunctionLine->setText(clUserDef->GetFunction());
+
+ ParameterScalar* ps;
+ for (size_t i=0; i< 3; ++i)
+ {
+ ps=clUserDef->GetCoordShiftPS(i);
+ if (ps==NULL) return;
+ if (ps->GetMode()) CoordShift[i]->setText(ps->GetString().c_str());
+ else CoordShift[i]->setText(QString("%1").arg(ps->GetValue()));
+ }
+}
+
+
diff --git a/QCSXCAD/QCSPrimEditor.h b/QCSXCAD/QCSPrimEditor.h
new file mode 100644
index 0000000..19794ee
--- /dev/null
+++ b/QCSXCAD/QCSPrimEditor.h
@@ -0,0 +1,237 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _QCSPRIMEDITOR_H_
+#define _QCSPRIMEDITOR_H_
+
+#include <QDialog>
+#include <QWidget>
+#include <QLayout>
+#include <QGroupBox>
+#include <QVBoxLayout>
+#include <QSpinBox>
+#include <QComboBox>
+#include <QListWidgetItem>
+
+#include "ContinuousStructure.h"
+
+class QCSPrimitiveLayout;
+class QCSPrimBoxLayout;
+class QCSPrimSphereLayout;
+class QCSPrimCylinderLayout;
+class QCSPrimMultiBoxLayout;
+class QCSPrimPolygon;
+ class QCSPrimLinPoly;
+ class QCSPrimRotPoly;
+class QCSPrimUserDefinedLayout;
+
+class QCSPrimEditor : public QDialog
+{
+ Q_OBJECT
+public:
+ QCSPrimEditor(ContinuousStructure *CS, CSPrimitives* prim, QWidget* parent=NULL);
+ virtual ~QCSPrimEditor();
+
+protected slots:
+ void Reset();
+ void Save();
+ void Cancel();
+
+ void UpdatePropertyCB();
+
+protected:
+ QGroupBox* BuildGeneral();
+ QLayout* BuildButtons();
+
+ QSpinBox* PrioSpinBox;
+ QComboBox* PropertiesComboBox;
+
+ QVBoxLayout* MainLayout;
+ QCSPrimitiveLayout* CSPrimEdit;
+ ContinuousStructure *clCS;
+ CSPrimitives* CSPrim;
+};
+
+class QCSPrimitiveLayout : public QGridLayout
+{
+ Q_OBJECT
+public:
+ QCSPrimitiveLayout(CSPrimitives* prim, QWidget *parent=NULL);
+ virtual ~QCSPrimitiveLayout();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPrimitives* clPrim;
+
+};
+
+
+class QCSPrimBoxLayout : public QCSPrimitiveLayout
+{
+ Q_OBJECT
+public:
+ QCSPrimBoxLayout(CSPrimBox* prim, QWidget *parent=NULL);
+ virtual ~QCSPrimBoxLayout();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPrimBox* clBox;
+ QLineEdit *Lines[6];
+};
+
+class QCSPrimSphereLayout : public QCSPrimitiveLayout
+{
+ Q_OBJECT
+public:
+ QCSPrimSphereLayout(CSPrimSphere* prim, QWidget *parent=NULL);
+ virtual ~QCSPrimSphereLayout();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPrimSphere* clSphere;
+ QLineEdit *Lines[4];
+};
+
+class QCSPrimCylinderLayout : public QCSPrimitiveLayout
+{
+ Q_OBJECT
+public:
+ QCSPrimCylinderLayout(CSPrimCylinder* prim, QWidget *parent=NULL);
+ virtual ~QCSPrimCylinderLayout();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPrimCylinder* clCylinder;
+ QLineEdit *Lines[7];
+};
+
+class QCSPrimCylindricalShellLayout : public QCSPrimCylinderLayout
+{
+ Q_OBJECT
+public:
+ QCSPrimCylindricalShellLayout(CSPrimCylindricalShell* prim, QWidget *parent=NULL);
+ virtual ~QCSPrimCylindricalShellLayout();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPrimCylindricalShell* clCylindricalShell;
+ QLineEdit *m_ShellWidth;
+};
+
+class QCSPrimMultiBoxLayout : public QCSPrimitiveLayout
+{
+ Q_OBJECT
+public:
+ QCSPrimMultiBoxLayout(CSPrimMultiBox* prim, QWidget *parent=NULL);
+ virtual ~QCSPrimMultiBoxLayout();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+protected slots:
+ void NewBox(QListWidgetItem* item=NULL);
+ void DeleteBox(QListWidgetItem* item=NULL);
+ void EditBox(QListWidgetItem* item=NULL);
+
+signals:
+ void modified();
+
+protected:
+ CSPrimMultiBox* clMultiBox;
+
+ QListWidget* qBoxList;
+ QVector<QString> vLines;
+};
+
+class QCSPrimPolygonLayout : public QCSPrimitiveLayout
+{
+ Q_OBJECT
+public:
+ QCSPrimPolygonLayout(CSPrimPolygon* prim, QWidget *parent=NULL);
+ virtual ~QCSPrimPolygonLayout();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+protected slots:
+ void NormVecChanged();
+
+signals:
+ void modified();
+
+protected:
+ CSPrimPolygon* clPoly;
+ QComboBox* NormVec;
+ QLineEdit* Elevation;
+ QLineEdit* CoordLineX;
+ QLineEdit* CoordLineY;
+};
+
+class QCSPrimUserDefinedLayout : public QCSPrimitiveLayout
+{
+ Q_OBJECT
+public:
+ QCSPrimUserDefinedLayout(CSPrimUserDefined* prim, QWidget *parent=NULL);
+ virtual ~QCSPrimUserDefinedLayout();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPrimUserDefined* clUserDef;
+ QLineEdit *FunctionLine;
+ QComboBox *CoordSystem;
+ QLineEdit *CoordShift[3];
+};
+
+#endif //_QCSPRIMEDITOR_H_
diff --git a/QCSXCAD/QCSPropEditor.cpp b/QCSXCAD/QCSPropEditor.cpp
new file mode 100644
index 0000000..15804e0
--- /dev/null
+++ b/QCSXCAD/QCSPropEditor.cpp
@@ -0,0 +1,623 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QColorDialog>
+
+#include "QCSPropEditor.h"
+#include "QCSXCAD_Global.h"
+#include "iostream"
+#include "time.h"
+
+#include "CSPropUnknown.h"
+#include "CSPropMaterial.h"
+#include "CSPropDispersiveMaterial.h"
+#include "CSPropLorentzMaterial.h"
+#include "CSPropDiscMaterial.h"
+#include "CSPropLumpedElement.h"
+#include "CSPropMetal.h"
+#include "CSPropConductingSheet.h"
+#include "CSPropExcitation.h"
+#include "CSPropProbeBox.h"
+#include "CSPropDumpBox.h"
+#include "CSPropResBox.h"
+
+QColorPushButton::QColorPushButton(const QString & text, QWidget * parent ) : QPushButton(text,parent)
+{
+ setFlat(true);
+ setAutoFillBackground(true);
+ QObject::connect(this,SIGNAL(clicked()),this,SLOT(ChangeColor()));
+ //Color.setAlpha(255);
+
+ RGBa c;
+ c.R=1 + (rand()%255);
+ c.G=1 + (rand()%255);
+ c.B=1 + (rand()%255);
+ SetColor(c);
+}
+
+QColorPushButton::~QColorPushButton()
+{
+}
+
+void QColorPushButton::SetColor(RGBa c)
+{
+ QPalette palette;
+
+ Color=QColor(c.R,c.G,c.B,c.a);
+
+ palette.setColor(QPalette::Button,QColor(c.R,c.G,c.B));
+ if (c.R+c.G+c.B>(128*3)) palette.setColor(QPalette::ButtonText,QColor(0,0,0));
+ else palette.setColor(QPalette::ButtonText,QColor(255,255,255));
+ setPalette(palette);
+}
+
+RGBa QColorPushButton::GetColor()
+{
+ RGBa c;
+ c.R=Color.red();
+ c.G=Color.green();
+ c.B=Color.blue();
+ c.a=Color.alpha();
+ return c;
+}
+
+void QColorPushButton::ChangeColor()
+{
+ QColor newColor=QColorDialog::getColor(Color,this);
+ if (newColor.isValid())
+ {
+ int alpha=Color.alpha();
+ Color=newColor;
+ Color.setAlpha(alpha);
+ QPalette palette;
+ palette.setColor(QPalette::Button,newColor);
+ if (Color.red()+Color.blue()+Color.green()>(128*3)) palette.setColor(QPalette::ButtonText,QColor(0,0,0));
+ else palette.setColor(QPalette::ButtonText,QColor(255,255,255));
+ setPalette(palette);
+ }
+}
+
+QCSPropEditor::QCSPropEditor(ContinuousStructure *CS, CSProperties* prop, int iSimMode, QWidget* parent) : QDialog(parent)
+{
+ clCS=CS;
+ clProp=prop;
+ saveProp=clProp;
+ m_SimMode=iSimMode;
+
+ MainLayout = new QVBoxLayout();
+
+ setWindowTitle(tr("Property Editor"));
+
+ MainLayout->addWidget(BuildGeneral());
+ GetValues();
+
+
+ if (propGB!=NULL)
+ {
+ MainLayout->addWidget(propGB);
+ }
+
+ MainLayout->addStretch();
+
+ MainLayout->addLayout(BuildButtons());
+
+
+ setLayout(MainLayout);
+
+ setAttribute(Qt::WA_DeleteOnClose, true);
+ setWindowModality(Qt::ApplicationModal);
+}
+
+QCSPropertyGroupBox* QCSPropEditor::BuildPropGroupBox(CSProperties* clProp)
+{
+ QCSPropertyGroupBox* propGB=NULL;
+ switch (clProp->GetType())
+ {
+ case CSProperties::MATERIAL:
+ propGB = new QCSPropMaterialGB(clProp->ToMaterial());
+ break;
+ case CSProperties::METAL:
+ break;
+ case CSProperties::EXCITATION:
+ propGB = new QCSPropExcitationGB(clProp->ToExcitation());
+ break;
+ case CSProperties::PROBEBOX:
+ propGB = new QCSPropProbeBoxGB(clProp->ToProbeBox());
+ break;
+ case CSProperties::DUMPBOX:
+ propGB = new QCSPropDumpBoxGB(clProp->ToDumpBox(),m_SimMode);
+ break;
+ case CSProperties::RESBOX:
+ propGB = new QCSPropResBoxGB(clProp->ToResBox());
+ break;
+ case CSProperties::UNKNOWN:
+ propGB = new QCSPropUnknownGB(clProp->ToUnknown());
+ break;
+ default:
+ return NULL;
+ break;
+ };
+ return propGB;
+}
+
+
+void QCSPropEditor::Reset()
+{
+ GetValues();
+ if (propGB!=NULL) propGB->GetValues();
+}
+
+void QCSPropEditor::Save()
+{
+ SetValues();
+ if (propGB!=NULL) propGB->SetValues();
+
+ accept();
+}
+
+void QCSPropEditor::Cancel()
+{
+ reject();
+}
+
+void QCSPropEditor::ChangeType(int item)
+{
+ bool ok=false;
+ int type = TypeCB->itemData(item).toInt(&ok);
+ if (ok==false) return;
+ if (type==clProp->GetType()) return;
+ //if (propGB!=NULL) MainLayout->removeWidget(propGB);
+ //if (propGB!=savePropGB) delete propGB;
+ if (clProp!=saveProp) delete clProp;
+ delete propGB;propGB=NULL;
+ if (type==saveProp->GetType())
+ {
+ clProp=saveProp;
+ }
+ else switch (type)
+ {
+ case CSProperties::MATERIAL:
+ clProp = new CSPropMaterial(saveProp);
+ break;
+ case CSProperties::METAL:
+ clProp = new CSPropMetal(saveProp);
+ break;
+ case CSProperties::EXCITATION:
+ clProp = new CSPropExcitation(saveProp);
+ break;
+ case CSProperties::PROBEBOX:
+ clProp = new CSPropProbeBox(saveProp);
+ break;
+ case CSProperties::DUMPBOX:
+ clProp = new CSPropDumpBox(saveProp);
+ break;
+ case CSProperties::RESBOX:
+ clProp = new CSPropResBox(saveProp);
+ break;
+ default:
+ clProp = new CSPropUnknown(saveProp);
+ break;
+ };
+ propGB=BuildPropGroupBox(clProp);
+ if (propGB!=NULL) MainLayout->insertWidget(1,propGB);
+ setLayout(MainLayout);
+}
+
+void QCSPropEditor::Fill2EdgeColor()
+{
+ ECButton->SetColor(FCButton->GetColor());
+}
+
+void QCSPropEditor::Edge2FillColor()
+{
+ FCButton->SetColor(ECButton->GetColor());
+}
+
+QGroupBox* QCSPropEditor::BuildGeneral()
+{
+ QGroupBox* box= new QGroupBox("General");
+ QGridLayout* grid = new QGridLayout();
+
+ Name = new QLineEdit(QString::fromUtf8(clProp->GetName().c_str()));
+ Name->setEnabled(QCSX_Settings.GetEdit());
+ grid->addWidget(new QLabel(tr("Name: ")),0,0);
+ grid->addWidget(Name,0,1);
+ grid->addWidget(new QLabel(QString(tr("ID: %1")).arg(clProp->GetID())),0,2);
+
+ grid->addWidget(new QLabel(tr("Type: ")),1,0);
+ TypeCB = new QComboBox();
+ TypeCB->addItem(tr("Unknown"),QVariant(CSProperties::UNKNOWN));
+ TypeCB->addItem(tr("Material"),QVariant(CSProperties::MATERIAL));
+ TypeCB->addItem(tr("Metal"),QVariant(CSProperties::METAL));
+ TypeCB->addItem(tr("Excitation"),QVariant(CSProperties::EXCITATION));
+ TypeCB->addItem(tr("Probe Box"),QVariant(CSProperties::PROBEBOX));
+ TypeCB->addItem(tr("Res Box"),QVariant(CSProperties::RESBOX));
+ TypeCB->addItem(tr("Dump Box"),QVariant(CSProperties::DUMPBOX));
+ TypeCB->setEnabled(QCSX_Settings.GetEdit());
+ grid->addWidget(TypeCB,1,1,1,2);
+ QObject::connect(TypeCB,SIGNAL(currentIndexChanged(int)),this,SLOT(ChangeType(int)));
+
+ QHBoxLayout* HLay = new QHBoxLayout();
+ HLay->addStretch(1);
+ FCButton = new QColorPushButton(tr("Change Fill-Color"));
+ FCButton->setFixedSize(100,50);
+ HLay->addWidget(FCButton);
+
+ QVBoxLayout* VLay = new QVBoxLayout();
+ QPushButton* F2EButton = new QPushButton("-->");
+ F2EButton->setFixedSize(30,20);
+ QObject::connect(F2EButton,SIGNAL(clicked()),this,SLOT(Fill2EdgeColor()));
+ QPushButton* E2FButton = new QPushButton("<--");
+ E2FButton->setFixedSize(30,20);
+ QObject::connect(E2FButton,SIGNAL(clicked()),this,SLOT(Edge2FillColor()));
+ VLay->addWidget(F2EButton);
+ VLay->addWidget(E2FButton);
+ HLay->addLayout(VLay);
+
+ ECButton = new QColorPushButton(tr("Change Edge-Color"));
+ ECButton->setFixedSize(100,50);
+ HLay->addWidget(ECButton);
+ HLay->addStretch(1);
+
+ grid->addLayout(HLay,2,0,1,3);
+ box->setLayout(grid);
+
+ return box;
+}
+
+QLayout* QCSPropEditor::BuildButtons()
+{
+ QHBoxLayout* lay = new QHBoxLayout();
+
+ QPushButton* ok = new QPushButton(tr("Ok"));
+ QObject::connect(ok,SIGNAL(clicked()),this,SLOT(Save()));
+ lay->addWidget(ok);
+ if (QCSX_Settings.GetEdit())
+ {
+ QPushButton* reset = new QPushButton(tr("Reset"));
+ QObject::connect(reset,SIGNAL(clicked()),this,SLOT(Reset()));
+ lay->addWidget(reset);
+ QPushButton* cancel = new QPushButton(tr("Cancel"));
+ QObject::connect(cancel,SIGNAL(clicked()),this,SLOT(Cancel()));
+ lay->addWidget(cancel);
+ }
+ lay->addStretch();
+
+ return lay;
+}
+
+void QCSPropEditor::GetValues()
+{
+ if (clProp!=saveProp)
+ {
+ delete clProp;
+ delete propGB;
+ clProp=saveProp;
+ }
+
+ propGB = BuildPropGroupBox(clProp);
+
+ Name->setText(QString::fromUtf8(clProp->GetName().c_str()));
+ TypeCB->setCurrentIndex(GetIndexOfType());
+ FCButton->SetColor(clProp->GetFillColor());
+ ECButton->SetColor(clProp->GetEdgeColor());
+}
+
+void QCSPropEditor::SetValues()
+{
+ //RGBa c;
+ clProp->SetFillColor(FCButton->GetColor());
+ clProp->SetEdgeColor(ECButton->GetColor());
+ clProp->SetName(Name->text().toLatin1().data());
+
+ if (saveProp!=clProp) clCS->ReplaceProperty(saveProp,clProp);
+}
+
+int QCSPropEditor::GetIndexOfType()
+{
+ for (int i=0;i<TypeCB->count();++i)
+ {
+ if (TypeCB->itemData(i).toInt()==clProp->GetType()) return i;
+ }
+ return 0;
+}
+
+/***************************QCSPropertyGroupBox**************************************/
+QCSPropertyGroupBox::QCSPropertyGroupBox(QWidget *parent) : QGroupBox(parent)
+{
+}
+
+QCSPropertyGroupBox::~QCSPropertyGroupBox()
+{
+}
+
+void QCSPropertyGroupBox::SetValues()
+{
+}
+
+void QCSPropertyGroupBox::GetValues()
+{
+}
+
+/***************************QCSPropUnknownGB**************************************/
+QCSPropUnknownGB::QCSPropUnknownGB(CSPropUnknown *prop, QWidget *parent) : QCSPropertyGroupBox(parent)
+{
+ clProp=prop;
+ TypeName=QString(tr("Unknown"));
+ setTitle(tr("Unknown Property"));
+
+ QGridLayout* layout = new QGridLayout();
+
+ Property = new QLineEdit();
+ layout->addWidget(new QLabel(tr("Property: ")),0,0);
+ layout->addWidget(Property,0,1);
+
+ GetValues();
+
+ setLayout(layout);
+}
+
+QCSPropUnknownGB::~QCSPropUnknownGB()
+{
+}
+
+void QCSPropUnknownGB::SetValues()
+{
+ clProp->SetProperty(Property->text().toLatin1().data());
+}
+
+void QCSPropUnknownGB::GetValues()
+{
+ Property->setText(clProp->GetProperty().c_str());
+}
+
+
+/***************************QCSPropMaterialGB**************************************/
+QCSPropMaterialGB::QCSPropMaterialGB(CSPropMaterial *prop, QWidget *parent) : QCSPropertyGroupBox(parent)
+{
+ clProp=prop;
+ TypeName=QString(tr("Material"));
+ setTitle(tr("Material Property"));
+
+ QGridLayout* layout = new QGridLayout();
+
+ GetValues();
+
+ setLayout(layout);
+}
+
+QCSPropMaterialGB::~QCSPropMaterialGB()
+{
+}
+
+void QCSPropMaterialGB::SetValues()
+{
+}
+
+void QCSPropMaterialGB::GetValues()
+{
+}
+
+/***************************QCSPropExcitationGB**************************************/
+QCSPropExcitationGB::QCSPropExcitationGB(CSPropExcitation *prop, QWidget *parent) : QCSPropertyGroupBox(parent)
+{
+ clProp=prop;
+ TypeName=QString(tr("Excitation"));
+ setTitle(tr("Excitation Property"));
+
+ QGridLayout* layout = new QGridLayout();
+
+ Number = new QSpinBox();
+ Number->setRange(0,999);
+ Number->setEnabled(QCSX_Settings.GetEdit());
+ layout->addWidget(new QLabel(tr("Number: ")),0,0);
+ layout->addWidget(Number,0,1);
+
+ Type = new QComboBox();
+ Type->addItem(tr("Electric field (soft)"));
+ Type->addItem(tr("Electric field (hard)"));
+ Type->addItem(tr("Magnetic field (soft)"));
+ Type->addItem(tr("Magnetic field (hard)"));
+ Type->setEnabled(QCSX_Settings.GetEdit());
+ layout->addWidget(new QLabel(tr("Type: ")),0,2);
+ layout->addWidget(Type,0,3,1,3);
+ QObject::connect(Type,SIGNAL(currentIndexChanged(int)),this,SLOT(TypeChanged(int)));
+
+ layout->addWidget(new QLabel(tr("Excitation (X):")),1,0);
+ Excitation[0] = new QLineEdit();
+ layout->addWidget(Excitation[0],1,1);
+
+ layout->addWidget(new QLabel(tr("Excitation Y:")),1,2);
+ Excitation[1] = new QLineEdit();
+ layout->addWidget(Excitation[1],1,3);
+
+ layout->addWidget(new QLabel(tr("Excitation Z:")),1,4);
+ Excitation[2] = new QLineEdit();
+ layout->addWidget(Excitation[2],1,5);
+
+ layout->addWidget(new QLabel(tr("Analytic Fct (X): ")),2,0);
+ FctLine[0] = new QLineEdit();
+ layout->addWidget(FctLine[0],2,1,1,5);
+
+ layout->addWidget(new QLabel(tr("Analytic Fct (Y): ")),3,0);
+ FctLine[1] = new QLineEdit();
+ layout->addWidget(FctLine[1],3,1,1,5);
+
+ layout->addWidget(new QLabel(tr("Analytic Fct (Z): ")),4,0);
+ FctLine[2] = new QLineEdit();
+ layout->addWidget(FctLine[2],4,1,1,5);
+
+ GetValues();
+
+ setLayout(layout);
+}
+
+QCSPropExcitationGB::~QCSPropExcitationGB()
+{
+}
+
+void QCSPropExcitationGB::SetValues()
+{
+ bool bOk;
+ double dVal;
+ QString line;
+
+ for (unsigned int i=0;i<3;++i)
+ {
+ line=Excitation[i]->text();
+ dVal=line.toDouble(&bOk);
+ if (bOk) clProp->SetExcitation(dVal,i);
+ else clProp->SetExcitation(line.toLatin1().data(),i);
+ }
+ clProp->SetNumber((unsigned int)Number->value());
+ clProp->SetExcitType(Type->currentIndex()+1);
+ for (unsigned int i=0;i<3;++i)
+ clProp->SetWeightFunction(FctLine[i]->text().toLatin1().data(),i);
+}
+
+void QCSPropExcitationGB::GetValues()
+{
+ std::string line;
+
+ for (unsigned int i=0;i<3;++i)
+ {
+ line=clProp->GetExcitationString(i);
+ if (!line.empty()) Excitation[i]->setText(line.c_str());
+ else Excitation[i]->setText(QString("%1").arg(clProp->GetExcitation(i)));
+ }
+
+ Number->setValue(clProp->GetNumber());
+ Type->setCurrentIndex(clProp->GetExcitType());
+ TypeChanged(clProp->GetExcitType());
+
+ for (unsigned int i=0;i<3;++i)
+ FctLine[i]->setText(clProp->GetWeightFunction(i).c_str());
+}
+
+void QCSPropExcitationGB::TypeChanged(int index)
+{
+ //enable/disable certain lines, depending on the excitation typez
+ switch (index)
+ {
+ default:
+ Excitation[0]->setEnabled(true & QCSX_Settings.GetEdit());
+ Excitation[1]->setEnabled(true & QCSX_Settings.GetEdit());
+ Excitation[2]->setEnabled(true & QCSX_Settings.GetEdit());
+ FctLine[0]->setEnabled(true & QCSX_Settings.GetEdit());
+ FctLine[1]->setEnabled(true & QCSX_Settings.GetEdit());
+ FctLine[2]->setEnabled(true & QCSX_Settings.GetEdit());
+ break;
+ }
+}
+
+/***************************QCSPropChargeBoxGB**************************************/
+QCSPropProbeBoxGB::QCSPropProbeBoxGB(CSPropProbeBox *prop, QWidget *parent) : QCSPropertyGroupBox(parent)
+{
+ clProp=prop;
+ TypeName=QString(tr("Probe Box"));
+ setTitle(tr("ProbeBox Property"));
+
+ QGridLayout* layout = new QGridLayout();
+
+ Number = new QSpinBox();
+ Number->setRange(0,999);
+ Number->setEnabled(QCSX_Settings.GetEdit());
+ layout->addWidget(new QLabel(tr("Number: ")),0,0);
+ layout->addWidget(Number,0,1);
+
+ GetValues();
+
+ setLayout(layout);
+}
+
+QCSPropProbeBoxGB::~QCSPropProbeBoxGB()
+{
+}
+
+void QCSPropProbeBoxGB::SetValues()
+{
+ clProp->SetNumber((unsigned int)Number->value());
+}
+
+void QCSPropProbeBoxGB::GetValues()
+{
+ Number->setValue(clProp->GetNumber());
+}
+
+/***************************QCSPropResBoxGB**************************************/
+QCSPropResBoxGB::QCSPropResBoxGB(CSPropResBox *prop, QWidget *parent) : QCSPropertyGroupBox(parent)
+{
+ clProp=prop;
+ TypeName=QString(tr("Resolution Box"));
+ setTitle(tr("ResBox Property"));
+
+ QGridLayout* layout = new QGridLayout();
+
+ Factor = new QSpinBox();
+ Factor->setRange(2,16);
+ Factor->setEnabled(QCSX_Settings.GetEdit());
+ layout->addWidget(new QLabel(tr("Resolution Factor: ")),0,0);
+ layout->addWidget(Factor,0,1);
+
+ GetValues();
+
+ setLayout(layout);
+}
+
+QCSPropResBoxGB::~QCSPropResBoxGB()
+{
+}
+
+void QCSPropResBoxGB::SetValues()
+{
+ clProp->SetResFactor((unsigned int)Factor->value());
+}
+
+void QCSPropResBoxGB::GetValues()
+{
+ Factor->setValue(clProp->GetResFactor());
+}
+
+
+/***************************QCSPropDumpBoxGB**************************************/
+QCSPropDumpBoxGB::QCSPropDumpBoxGB(CSPropDumpBox *prop, int SimMode, QWidget *parent) : QCSPropertyGroupBox(parent)
+{
+ UNUSED(SimMode);
+
+ clProp=prop;
+ TypeName=QString(tr("Dump Box"));
+ setTitle(tr("Dump Property"));
+
+ QVBoxLayout* layout = new QVBoxLayout();
+
+ GetValues();
+
+ setLayout(layout);
+}
+
+QCSPropDumpBoxGB::~QCSPropDumpBoxGB()
+{
+}
+
+void QCSPropDumpBoxGB::SetValues()
+{
+}
+
+void QCSPropDumpBoxGB::GetValues()
+{
+}
+
diff --git a/QCSXCAD/QCSPropEditor.h b/QCSXCAD/QCSPropEditor.h
new file mode 100644
index 0000000..d46ce85
--- /dev/null
+++ b/QCSXCAD/QCSPropEditor.h
@@ -0,0 +1,248 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _QCSPROPEDITOR_H_
+#define _QCSPROPEDITOR_H_
+
+#include <QPushButton>
+#include <QDialog>
+#include <QWidget>
+#include <QComboBox>
+#include <QGroupBox>
+#include <QLayout>
+#include <QLabel>
+#include <QSpinBox>
+#include <QLineEdit>
+
+#include "ContinuousStructure.h"
+
+class QColorPushButton : public QPushButton
+{
+ Q_OBJECT
+public:
+ QColorPushButton(const QString & text, QWidget * parent = 0 );
+ ~QColorPushButton();
+
+ void SetColor(RGBa c);
+ RGBa GetColor();
+
+protected slots:
+ void ChangeColor();
+
+protected:
+ QColor Color;
+};
+
+class QCSPropertyGroupBox;
+class QCSPropMaterialGB;
+
+class QCSPropEditor : public QDialog
+{
+ Q_OBJECT
+public:
+ QCSPropEditor(ContinuousStructure *CS, CSProperties* prop, int iSimMode, QWidget* parent=NULL);
+ ~QCSPropEditor() {};
+
+protected slots:
+ void Reset();
+ void Save();
+ void Cancel();
+
+ void ChangeType(int item);
+
+ void Fill2EdgeColor();
+ void Edge2FillColor();
+
+ void GetValues();
+ void SetValues();
+
+protected:
+ QComboBox* TypeCB;
+
+ QGroupBox* BuildGeneral();
+ QLayout* BuildButtons();
+
+ QVBoxLayout* MainLayout;
+ //QCSPropertyLayout* CSPropEdit;
+ ContinuousStructure *clCS;
+
+ QLineEdit* Name;
+ QLabel* TypeLbl;
+
+ QColorPushButton* FCButton;
+ QColorPushButton* ECButton;
+
+ CSProperties* clProp;
+ CSProperties* saveProp;
+
+ QCSPropertyGroupBox* BuildPropGroupBox(CSProperties* clProp);
+ QCSPropertyGroupBox* propGB;
+
+ int GetIndexOfType();
+
+ int m_SimMode;
+};
+
+//dummy class
+class QCSPropertyGroupBox : public QGroupBox
+{
+ Q_OBJECT
+public:
+ virtual ~QCSPropertyGroupBox();
+
+protected:
+ QCSPropertyGroupBox(QWidget *parent=NULL);
+
+ QString TypeName;
+ QString GetTypeName() {return TypeName;};
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+};
+
+class QCSPropUnknownGB : public QCSPropertyGroupBox
+{
+ Q_OBJECT
+public:
+ QCSPropUnknownGB(CSPropUnknown *prop, QWidget *parent=NULL);
+ virtual ~QCSPropUnknownGB();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPropUnknown* clProp;
+
+ QLineEdit* Property;
+};
+
+
+class QCSPropMaterialGB : public QCSPropertyGroupBox
+{
+ Q_OBJECT
+public:
+ QCSPropMaterialGB(CSPropMaterial *prop, QWidget *parent=NULL);
+ virtual ~QCSPropMaterialGB();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPropMaterial* clProp;
+};
+
+class QCSPropExcitationGB : public QCSPropertyGroupBox
+{
+ Q_OBJECT
+public:
+ QCSPropExcitationGB(CSPropExcitation *prop, QWidget *parent=NULL);
+ virtual ~QCSPropExcitationGB();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+protected slots:
+ void TypeChanged(int index);
+
+signals:
+ void modified();
+
+protected:
+ CSPropExcitation* clProp;
+
+ QLineEdit* FctLine[3];
+
+ QSpinBox* Number;
+ QComboBox* Type;
+
+ QLineEdit* Excitation[3];
+};
+
+class QCSPropProbeBoxGB : public QCSPropertyGroupBox
+{
+ Q_OBJECT
+public:
+ QCSPropProbeBoxGB(CSPropProbeBox *prop, QWidget *parent=NULL);
+ virtual ~QCSPropProbeBoxGB();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPropProbeBox* clProp;
+
+ QSpinBox* Number;
+};
+
+class QCSPropResBoxGB : public QCSPropertyGroupBox
+{
+ Q_OBJECT
+public:
+ QCSPropResBoxGB(CSPropResBox *prop, QWidget *parent=NULL);
+ virtual ~QCSPropResBoxGB();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPropResBox* clProp;
+
+ QSpinBox* Factor;
+};
+
+class QCSPropDumpBoxGB : public QCSPropertyGroupBox
+{
+ Q_OBJECT
+public:
+ QCSPropDumpBoxGB(CSPropDumpBox *prop, int SimMode, QWidget *parent=NULL);
+ virtual ~QCSPropDumpBoxGB();
+
+public slots:
+ virtual void SetValues();
+ virtual void GetValues();
+
+signals:
+ void modified();
+
+protected:
+ CSPropDumpBox* clProp;
+};
+
+
+#endif //_QCSPROPEDITOR_H_
diff --git a/QCSXCAD/QCSTreeWidget.cpp b/QCSXCAD/QCSTreeWidget.cpp
new file mode 100644
index 0000000..e15743d
--- /dev/null
+++ b/QCSXCAD/QCSTreeWidget.cpp
@@ -0,0 +1,242 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QMenu>
+#include <QContextMenuEvent>
+
+#include "QCSTreeWidget.h"
+#include "QCSXCAD_Global.h"
+
+QCSTreeWidget::QCSTreeWidget(ContinuousStructure* CS, QWidget * parent) : QTreeWidget(parent)
+{
+ clCS=CS;
+ setColumnCount(2);
+ setColumnWidth(0,200);
+// setColumnWidth(1,16);
+ setHeaderLabels(QStringList(tr("Properties / Primitives"))<<tr("Vis"));
+// setItemHidden(headerItem(),true);
+// qTree->setDragEnabled(true);
+// qTree->setAcceptDrops(true);
+// qTree->setDropIndicatorShown(true);
+ QObject::connect(this,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(Edit(QTreeWidgetItem*,int)));
+ QObject::connect(this,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(Clicked(QTreeWidgetItem*,int)));
+}
+
+QCSTreeWidget::~QCSTreeWidget()
+{
+}
+
+CSProperties* QCSTreeWidget::GetCurrentProperty()
+{
+ QTreeWidgetItem* curr=currentItem();
+ if (curr==NULL) return NULL;
+ if (curr->type()==PRIMTYPE) curr=curr->parent();
+ if (curr==NULL) return NULL;
+ return clCS->GetProperty(indexOfTopLevelItem(curr));
+}
+
+CSPrimitives* QCSTreeWidget::GetCurrentPrimitive()
+{
+ QTreeWidgetItem* curr=currentItem();
+ if (curr==NULL) return NULL;
+ if (curr->type()!=PRIMTYPE) return NULL;
+ return clCS->GetPrimitiveByID(curr->data(0,1).toInt());
+}
+
+void QCSTreeWidget::AddPrimItem(CSPrimitives* prim)
+{
+ if (prim==NULL)
+ return;
+ int propID=clCS->GetIndex(prim->GetProperty());
+ if (propID<0)
+ return;
+ QTreeWidgetItem* parent = topLevelItem(propID);
+ if (parent==NULL)
+ return;
+ QString str = QString(prim->GetTypeName().c_str());
+
+ str+=QString(" - ID: %1").arg(prim->GetID());
+ QTreeWidgetItem* newPrimItem = new QTreeWidgetItem(parent,QStringList(str),1);
+ newPrimItem->setData(0,1,QVariant(prim->GetID()));
+ vPrimItems.push_back(newPrimItem);
+}
+
+void QCSTreeWidget::AddPropItem(CSProperties* prop)
+{
+ QString str;
+ if (prop==NULL) return;
+ str=QString(prop->GetTypeXMLString().c_str())+"::";
+ str+=QString::fromUtf8(prop->GetName().c_str());
+
+ QTreeWidgetItem* newItem = new QTreeWidgetItem(this,QStringList(str),0);
+ newItem->setFont(0,QFont("Arial",10));
+ if (prop->GetVisibility()) newItem->setIcon(1,QIcon(":/images/bulb.png"));
+ else newItem->setIcon(1,QIcon(":/images/bulb_off.png"));
+}
+
+
+QTreeWidgetItem* QCSTreeWidget::GetTreeItemByPrimID(int primID)
+{
+ for (int n=0;n<vPrimItems.size();++n)
+ if (vPrimItems.at(n)->data(0,1).toInt()==primID)
+ return vPrimItems.at(n);
+ return NULL;
+}
+
+int QCSTreeWidget::GetTreeItemIndexByPrimID(int primID)
+{
+ for (int n=0;n<vPrimItems.size();++n)
+ if (vPrimItems.at(n)->data(0,1).toInt()==primID)
+ return n;
+ return -1;
+}
+
+void QCSTreeWidget::DeletePrimItem(CSPrimitives* prim)
+{
+ int index=GetTreeItemIndexByPrimID(prim->GetID());
+ QTreeWidgetItem* item;
+ if ((index>=0) && (index<vPrimItems.size()))
+ item=vPrimItems.at(index);
+ else return;
+ vPrimItems.remove(index);
+ delete item;
+}
+
+void QCSTreeWidget::DeletePropItem(CSProperties* prop)
+{
+ int index=clCS->GetIndex(prop);
+
+ QTreeWidgetItem* parent = topLevelItem(index);
+ if (parent==NULL) return;
+
+ delete parent;
+}
+
+void QCSTreeWidget::RefreshItem(int index)
+{
+ CSProperties* prop=clCS->GetProperty(index);
+ if (prop==NULL) return;
+ QTreeWidgetItem* item = topLevelItem(index);
+ if (item==NULL) return;
+ QString str=QString(prop->GetTypeXMLString().c_str())+"::";
+ str+=QString::fromUtf8(prop->GetName().c_str());
+ item->setText(0,str);
+ if (prop->GetVisibility()) item->setIcon(1,QIcon(":/images/bulb.png"));
+ else item->setIcon(1,QIcon(":/images/bulb_off.png"));
+}
+
+
+void QCSTreeWidget::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu menu(this);
+ if (QCSX_Settings.GetEdit())
+ {
+ QMenu* primM = menu.addMenu(QIcon(":/images/edit_add.png"),tr("New Primitive"));
+ primM->addAction(tr("Box"),this,SIGNAL(NewBox()));
+ primM->addAction(tr("Multi-Box"),this,SIGNAL(NewMultiBox()));
+ primM->addAction(tr("Sphere"),this,SIGNAL(NewSphere()));
+ primM->addAction(tr("Cylinder"),this,SIGNAL(NewCylinder()));
+ primM->addAction(tr("User Defined"),this,SIGNAL(NewUserDefined()));
+
+ QMenu* propM = menu.addMenu(QIcon(":/images/edit_add.png"),tr("New Property"));
+ propM->addAction(tr("Material"),this,SIGNAL(NewMaterial()));
+ propM->addAction(tr("Metal"),this,SIGNAL(NewMetal()));
+ propM->addAction(tr("Excitation"),this,SIGNAL(NewExcitation()));
+ propM->addAction(tr("Probe-Box"),this,SIGNAL(NewChargeBox()));
+ propM->addAction(tr("Res-Box"),this,SIGNAL(NewResBox()));
+ propM->addAction(tr("Dump-Box"),this,SIGNAL(NewDumpBox()));
+
+ menu.addSeparator();
+
+ menu.addAction(QIcon(":/images/edit.png"),tr("Edit"),this,SIGNAL(Edit()));
+ menu.addAction(QIcon(":/images/editcopy.png"),tr("Copy"),this,SIGNAL(Copy()));
+ menu.addAction(QIcon(":/images/edit_remove.png"),tr("Delete"),this,SIGNAL(Delete()));
+ }
+ else
+ {
+ menu.addAction(QIcon(":/images/edit.png"),tr("View"),this,SIGNAL(Edit()));
+ }
+
+ menu.exec(event->globalPos());
+}
+
+void QCSTreeWidget::UpdateTree()
+{
+ ClearTree();
+ for (size_t i=0;i<clCS->GetQtyProperties();++i)
+ {
+ QString str;
+ CSProperties* prop=clCS->GetProperty(i);
+ if (prop==NULL) break;
+ AddPropItem(prop);
+ }
+
+ std::vector<CSPrimitives*> vPrims = clCS->GetAllPrimitives();
+ for (size_t i=0;i<vPrims.size();++i)
+ AddPrimItem(vPrims.at(i));
+}
+
+void QCSTreeWidget::ClearTree()
+{
+ this->clear();
+ vPrimItems.clear();
+}
+
+void QCSTreeWidget::SwitchProperty(CSPrimitives* prim, CSProperties* newProp)
+{
+ int index=GetTreeItemIndexByPrimID(prim->GetID());
+ QTreeWidgetItem *item=NULL;
+ if ((index>=0) && (index<vPrimItems.size()))
+ item=vPrimItems.at(index);
+ else
+ return;
+
+ QTreeWidgetItem *parent=item->parent();
+ if (parent==NULL)
+ return;
+ QTreeWidgetItem *newParent = topLevelItem(clCS->GetIndex(newProp));
+ if (newParent==NULL)
+ return;
+
+ parent->takeChild(parent->indexOfChild(item));
+ newParent->addChild(item);
+}
+
+void QCSTreeWidget::collapseAll()
+{
+ for (int i=0;i<topLevelItemCount();++i) collapseItem(topLevelItem(i));
+}
+
+void QCSTreeWidget::expandAll()
+{
+ for (int i=0;i<topLevelItemCount();++i) expandItem(topLevelItem(i));
+}
+
+void QCSTreeWidget::Edit(QTreeWidgetItem * item, int column)
+{
+ UNUSED(column);
+ if (item==NULL) return;
+ if (item->type()!=PRIMTYPE) return;
+ emit Edit();
+}
+
+void QCSTreeWidget::Clicked(QTreeWidgetItem * item, int column)
+{
+ if (item==NULL) return;
+ if (item->type()!=PROPTYPE) return;
+ if (column==1) {emit ShowHide();}
+}
diff --git a/QCSXCAD/QCSTreeWidget.h b/QCSXCAD/QCSTreeWidget.h
new file mode 100644
index 0000000..b0a55f2
--- /dev/null
+++ b/QCSXCAD/QCSTreeWidget.h
@@ -0,0 +1,92 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _QCSTREEWIDGET_H_
+#define _QCSTREEWIDGET_H_
+
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+
+#include "ContinuousStructure.h"
+
+#define PROPTYPE 0
+#define PRIMTYPE 1
+
+class QCSTreeWidget : public QTreeWidget
+{
+ Q_OBJECT
+public:
+ QCSTreeWidget(ContinuousStructure* CS, QWidget * parent = 0);
+ virtual ~QCSTreeWidget();
+
+ CSProperties* GetCurrentProperty();
+ CSPrimitives* GetCurrentPrimitive();
+
+ void AddPrimItem(CSPrimitives* prim);
+ void AddPropItem(CSProperties* prop);
+
+ void DeletePrimItem(CSPrimitives* prim);
+ void DeletePropItem(CSProperties* prop);
+
+ void RefreshItem(int index);
+
+ void UpdateTree();
+ void ClearTree();
+
+signals:
+ void Edit();
+ void Copy();
+ void ShowHide();
+
+ void NewBox();
+ void NewMultiBox();
+ void NewSphere();
+ void NewCylinder();
+ void NewUserDefined();
+
+ void NewMaterial();
+ void NewMetal();
+ void NewExcitation();
+ void NewChargeBox();
+ void NewResBox();
+ void NewDumpBox();
+
+ void Delete();
+
+public slots:
+ void SwitchProperty(CSPrimitives* prim, CSProperties* newProp);
+
+ void collapseAll();
+ void expandAll();
+
+protected slots:
+ void Edit(QTreeWidgetItem * item, int column);
+ void Clicked(QTreeWidgetItem * item, int column);
+
+protected:
+ void contextMenuEvent(QContextMenuEvent *event);
+
+// void BuildContextMenu();
+ ContinuousStructure* clCS;
+
+ QTreeWidgetItem* GetTreeItemByPrimID(int primID);
+ int GetTreeItemIndexByPrimID(int primID);
+ QVector<QTreeWidgetItem*> vPrimItems;
+
+};
+
+#endif //_QCSTREEWIDGET_H_
diff --git a/QCSXCAD/QCSXCAD.cpp b/QCSXCAD/QCSXCAD.cpp
new file mode 100644
index 0000000..4cd4a74
--- /dev/null
+++ b/QCSXCAD/QCSXCAD.cpp
@@ -0,0 +1,999 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QDockWidget>
+#include <QMessageBox>
+#include <QFileDialog>
+#include <QAction>
+
+#include "QCSXCAD.h"
+#include "QVTKStructure.h"
+#include "QCSPrimEditor.h"
+#include "QCSPropEditor.h"
+#include "QCSTreeWidget.h"
+#include "QCSGridEditor.h"
+#include "QParameterGui.h"
+#include "vtkConfigure.h"
+#include "tinyxml.h"
+#include <iostream>
+
+#include "CSPropUnknown.h"
+#include "CSPropMaterial.h"
+#include "CSPropDispersiveMaterial.h"
+#include "CSPropLorentzMaterial.h"
+#include "CSPropDiscMaterial.h"
+#include "CSPropLumpedElement.h"
+#include "CSPropMetal.h"
+#include "CSPropConductingSheet.h"
+#include "CSPropExcitation.h"
+#include "CSPropProbeBox.h"
+#include "CSPropDumpBox.h"
+#include "CSPropResBox.h"
+
+#include "CSPrimPoint.h"
+#include "CSPrimBox.h"
+#include "CSPrimMultiBox.h"
+#include "CSPrimSphere.h"
+#include "CSPrimSphericalShell.h"
+#include "CSPrimCylinder.h"
+#include "CSPrimCylindricalShell.h"
+#include "CSPrimPolygon.h"
+#include "CSPrimLinPoly.h"
+#include "CSPrimRotPoly.h"
+#include "CSPrimCurve.h"
+#include "CSPrimWire.h"
+#include "CSPrimUserDefined.h"
+
+#include <QVTKWidget.h>
+#include <vtkRendererCollection.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderer.h>
+#include <vtkCamera.h>
+#include <vtkPOVExporter.h>
+
+// exporter
+#include "export_x3d.h"
+#include "export_pov.h"
+
+QCSXCAD::QCSXCAD(QWidget *parent) : QMainWindow(parent)
+{
+ QStringList argList=qApp->arguments();
+ for (int i=1;i<argList.size();++i)
+ {
+ if (argList.at(i).startsWith("-"))
+ QCSX_Settings.parseCommandLineArgument(argList.at(i));
+ }
+
+ m_ViewDir = 2;
+
+ m_RenderDiscModels = QCSX_Settings.GetRenderDiscMaterial();
+
+ StructureVTK = new QVTKStructure();
+ StructureVTK->SetGeometry(this);
+
+ setCentralWidget(StructureVTK->GetVTKWidget());
+
+ CSTree = new QCSTreeWidget(this);
+ QObject::connect(CSTree,SIGNAL(Edit()),this,SLOT(Edit()));
+ QObject::connect(CSTree,SIGNAL(Copy()),this,SLOT(Copy()));
+ QObject::connect(CSTree,SIGNAL(ShowHide()),this,SLOT(ShowHide()));
+ QObject::connect(CSTree,SIGNAL(Delete()),this,SLOT(Delete()));
+ QObject::connect(CSTree,SIGNAL(NewBox()),this,SLOT(NewBox()));
+ QObject::connect(CSTree,SIGNAL(NewMultiBox()),this,SLOT(NewMultiBox()));
+ QObject::connect(CSTree,SIGNAL(NewSphere()),this,SLOT(NewSphere()));
+ QObject::connect(CSTree,SIGNAL(NewCylinder()),this,SLOT(NewCylinder()));
+ QObject::connect(CSTree,SIGNAL(NewUserDefined()),this,SLOT(NewUserDefined()));
+
+ QObject::connect(CSTree,SIGNAL(NewMaterial()),this,SLOT(NewMaterial()));
+ QObject::connect(CSTree,SIGNAL(NewMetal()),this,SLOT(NewMetal()));
+ QObject::connect(CSTree,SIGNAL(NewExcitation()),this,SLOT(NewExcitation()));
+ QObject::connect(CSTree,SIGNAL(NewChargeBox()),this,SLOT(NewChargeBox()));
+ QObject::connect(CSTree,SIGNAL(NewResBox()),this,SLOT(NewResBox()));
+ QObject::connect(CSTree,SIGNAL(NewDumpBox()),this,SLOT(NewDumpBox()));
+
+ QDockWidget *dock = new QDockWidget(tr("Properties and Structures"),this);
+ dock->setAllowedAreas(Qt::LeftDockWidgetArea);
+ dock->setWidget(CSTree);
+ dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
+ dock->setObjectName("Properties_and_Structures_Dock");
+
+ addDockWidget(Qt::LeftDockWidgetArea,dock);
+
+ GridEditor = new QCSGridEditor(&clGrid);
+ QObject::connect(GridEditor,SIGNAL(OpacityChange(int)),StructureVTK,SLOT(SetGridOpacity(int)));
+ QObject::connect(GridEditor,SIGNAL(signalDetectEdges(int)),this,SLOT(DetectEdges(int)));
+ QObject::connect(GridEditor,SIGNAL(GridChanged()),StructureVTK,SLOT(RenderGrid()));
+ QObject::connect(GridEditor,SIGNAL(GridPlaneXChanged(int)),StructureVTK,SLOT(RenderGridX(int)));
+ QObject::connect(GridEditor,SIGNAL(GridPlaneYChanged(int)),StructureVTK,SLOT(RenderGridY(int)));
+ QObject::connect(GridEditor,SIGNAL(GridPlaneZChanged(int)),StructureVTK,SLOT(RenderGridZ(int)));
+
+ dock = new QDockWidget(tr("Rectilinear Grid"),this);
+ dock->setAllowedAreas(Qt::LeftDockWidgetArea);
+ dock->setWidget(GridEditor);
+ dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
+ dock->setObjectName("Rectilinear_Grid_Dock");
+ addDockWidget(Qt::LeftDockWidgetArea,dock);
+
+ QParaSet= new QParameterSet();
+ QObject::connect(QParaSet,SIGNAL(ParameterChanged()),this,SLOT(CheckGeometry()));
+ QObject::connect(QParaSet,SIGNAL(ParameterChanged()),this,SLOT(setModified()));
+ clParaSet=QParaSet;
+
+ dock = new QDockWidget(tr("Rectilinear Grid - Plane Position"),this);
+ dock->setAllowedAreas(Qt::LeftDockWidgetArea);
+ dock->setWidget(GridEditor->BuildPlanePosWidget());
+ dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
+ dock->setObjectName("Grid_Plane_Pos");
+ addDockWidget(Qt::LeftDockWidgetArea,dock);
+
+ dock = new QDockWidget(tr("Parameter"),this);
+ dock->setAllowedAreas(Qt::LeftDockWidgetArea);
+ dock->setWidget(QParaSet);
+ dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
+ dock->setObjectName("Parameter_Dock");
+ addDockWidget(Qt::LeftDockWidgetArea,dock);
+
+ BuildToolBar();
+
+ bModified=true;
+ GridEditor->SetOpacity(30);
+ Render();
+}
+
+QCSXCAD::~QCSXCAD()
+{
+}
+
+QString QCSXCAD::GetInfoString()
+{
+ QString text = QString("%1").arg(_QCSXCAD_LIB_NAME_);
+ text += QString("<br>Author: %1<br>EMail: %2").arg(_QCSXCAD_AUTHOR_).arg(_QCSXCAD_AUTHOR_MAIL_);
+ text += QString("<br>Version: %1\t Build: %2 %3").arg(_QCSXCAD_VERSION_).arg(__DATE__).arg(__TIME__);
+ text += QString("<br>License: %1").arg(_QCSXCAD_LICENSE_);
+ return text;
+}
+
+QIcon QCSXCAD::GetLibIcon()
+{
+ return QIcon(":/images/QCSXCAD_Icon.png");
+}
+
+void QCSXCAD::aboutQCSXCAD(QWidget* parent)
+{
+ QDialog infoWidget(parent);
+ infoWidget.setWindowTitle("Info");
+ QLabel *infoLbl = new QLabel();
+ infoLbl->setText(GetInfoString());
+ infoLbl->setAlignment(Qt::AlignLeft);
+
+ QGroupBox* DependGroup = new QGroupBox(tr("Used Libraries"),&infoWidget);
+
+ QLabel *qtinfo = new QLabel();
+ QPushButton* qtButton = new QPushButton(QIcon(":/images/qt-logo.png"),QString());
+ qtButton->setToolTip(tr("About Qt"));
+ qtButton->setIconSize(QSize(50,50));
+ QObject::connect(qtButton,SIGNAL(clicked()),qApp,SLOT(aboutQt()));
+ qtinfo->setText(QString("GUI-Toolkit: Qt by Trolltech (OSS) <br>Version: %1<br>http://www.trolltech.com/<br>License: GNU General Public License (GPL)").arg(QT_VERSION,0,16));
+ qtinfo->setAlignment(Qt::AlignLeft);
+
+ QLabel *vtkinfo = new QLabel();
+ QPushButton* vtkButton = new QPushButton(QIcon(":/images/vtk-logo.png"),QString());
+ vtkButton->setIconSize(QSize(50,50));
+ //vtkButton->setToolTip(tr("About Vtk"));
+ //QObject::connect(vtkButton,SIGNAL(clicked()),qApp,SLOT(aboutQt()));
+ vtkinfo->setText(QString("3D-Toolkit: Visualization Toolkit (VTK)<br>Version: %1<br>http://www.vtk.org/<br>License: BSD-License").arg(VTK_VERSION));
+ vtkinfo->setAlignment(Qt::AlignLeft);
+
+ QLabel *CSXCADinfo = new QLabel();
+ CSXCADinfo->setText(ContinuousStructure::GetInfoLine().c_str());
+ CSXCADinfo->setAlignment(Qt::AlignLeft);
+
+ QGridLayout *Glay = new QGridLayout();
+ Glay->addWidget(qtButton,1,1);
+ Glay->addWidget(qtinfo,1,2);
+ Glay->addWidget(vtkButton,2,1);
+ Glay->addWidget(vtkinfo,2,2);
+ Glay->addWidget(CSXCADinfo,3,2);
+ Glay->setColumnStretch(1,0);
+ Glay->setColumnStretch(2,1);
+
+ DependGroup->setLayout(Glay);
+
+ QGridLayout *infoLayout = new QGridLayout();
+ QPushButton* iconButt = new QPushButton(QCSXCAD::GetLibIcon(),"");
+ iconButt->setFlat(true);
+ iconButt->setIconSize(QSize(128,128));
+ infoLayout->addWidget(iconButt,1,1);
+ infoLayout->addWidget(infoLbl,1,2,1,3);
+ infoLayout->addWidget(DependGroup,2,1,1,3);
+
+ QPushButton* OKBut = new QPushButton(tr("Ok"));
+ QObject::connect(OKBut,SIGNAL(clicked()),&infoWidget,SLOT(accept()));
+ infoLayout->addWidget(OKBut,3,2);
+
+ infoLayout->setColumnStretch(1,1);
+ infoLayout->setColumnStretch(3,1);
+
+ infoWidget.setLayout(infoLayout);
+
+// infoWidget->show();
+// infoWidget->adjustSize();
+ infoWidget.exec();
+}
+
+//void QCSXCAD::SetFile(QString filename)
+//{
+// QFilename=filename;
+//
+// QString file;
+// if (QFilename.startsWith("./")) file=relPath+QFilename.mid(2);
+// else file=QFilename;
+//
+// //File_Lbl->setText(QString("Geometry File: %1").arg(file));
+//
+// emit FileModified(true);
+// setModified();
+// ReadFile(file);
+//}
+//
+//QString QCSXCAD::GetFilename()
+//{
+// return QFilename;
+//}
+//
+//QString QCSXCAD::GetGeometry()
+//{
+// if (QFilename.startsWith("./")) return relPath+QFilename.mid(2);
+// else return QFilename;
+//}
+
+bool QCSXCAD::CheckGeometry()
+{
+ QString msg = QString::fromStdString(Update());
+ if (msg.isEmpty())
+ {
+ return true;
+ }
+
+ QMessageBox::warning(this,tr("Geometry Edit Warning"),tr("Geometry Edit Warning: Update Error occurred!!\n")+msg,QMessageBox::Ok,QMessageBox::NoButton);
+
+ return false;
+}
+
+TiXmlNode* QCSXCAD::FindRootNode(TiXmlNode* node)
+{
+ if (node==NULL) return NULL;
+ TiXmlElement* child = node->FirstChildElement("ContinuousStructure");
+ if (child)
+ return node;
+ child=node->FirstChildElement();
+ TiXmlNode* found=NULL;
+ while (child!=NULL)
+ {
+ if (child->FirstChildElement("ContinuousStructure"))
+ return child;
+ found = FindRootNode(child);
+ if (found)
+ return found;
+ child = node->NextSiblingElement();
+ }
+ return NULL;
+}
+
+bool QCSXCAD::ReadNode(TiXmlNode* root)
+{
+ if (root==NULL) return false;
+ clear();
+ QString msg(ReadFromXML(root));
+ if (msg.isEmpty()==false) QMessageBox::warning(this,tr("Geometry read error"),tr("An geometry read error occured!!\n\n")+msg,QMessageBox::Ok,QMessageBox::NoButton);
+ CSTree->UpdateTree();
+ CSTree->expandAll();
+ setModified();
+ CheckGeometry();
+ GridEditor->Update();
+ BestView();
+ StructureVTK->ResetView();
+ return true;
+}
+
+bool QCSXCAD::ReadFile(QString filename)
+{
+ if (QFile::exists(filename)==false) return false;
+
+ TiXmlDocument doc(filename.toStdString().c_str());
+ if (!doc.LoadFile()) { QMessageBox::warning(this,tr("File- Error!!! File: "),tr("File-Loading failed!!!"),QMessageBox::Ok,QMessageBox::NoButton); }
+
+ TiXmlNode* root = 0;
+ TiXmlElement* openEMS = doc.FirstChildElement("openEMS");
+ if (openEMS)
+ {
+ root = ReadOpenEMS(openEMS);
+ }
+ else
+ {
+ //try to find a root node somewhere else...
+ root = FindRootNode(&doc);
+ }
+ if (root==NULL)
+ {
+ QMessageBox::warning(this,tr("Geometry read error"),tr("Can't find root CSX node!!"),QMessageBox::Ok,QMessageBox::NoButton);
+ return false;
+ }
+// QString msg(ReadFromXML(filename.toLatin1().constData()));
+ QString msg(ReadFromXML(root));
+ if (msg.isEmpty()==false)
+ QMessageBox::warning(this,tr("Geometry read error"),tr("An geometry read error occured!!\n\n")+msg,QMessageBox::Ok,QMessageBox::NoButton);
+
+ CSTree->UpdateTree();
+ CSTree->expandAll();
+ setModified();
+ CheckGeometry();
+ GridEditor->Update();
+ BestView();
+ StructureVTK->ResetView();
+ return true;
+}
+
+TiXmlNode* QCSXCAD::ReadOpenEMS(TiXmlNode* openEMS)
+{
+ // read FDTD options
+ m_BC.clear();
+ TiXmlElement* element = openEMS->FirstChildElement("FDTD");
+ if (element)
+ {
+ TiXmlElement* BC = element->FirstChildElement("BoundaryCond");
+ if (BC)
+ {
+ TiXmlAttribute *attr = BC->FirstAttribute();
+ while (attr)
+ {
+ m_BC[attr->Name()] = attr->Value();
+ attr = attr->Next();
+ }
+ }
+ }
+ return openEMS;
+}
+
+int QCSXCAD::GetCurrentProperty()
+{
+ return GetIndex(CSTree->GetCurrentProperty());
+}
+
+ParameterSet* QCSXCAD::GetParaSet()
+{
+ return QParaSet;
+}
+
+bool QCSXCAD::Write2XML(TiXmlNode* rootNode, bool parameterised)
+{
+ return ContinuousStructure::Write2XML(rootNode,parameterised);
+}
+
+bool QCSXCAD::Write2XML(const char* file, bool parameterised)
+{
+ return ContinuousStructure::Write2XML(file,parameterised);
+}
+
+bool QCSXCAD::Write2XML(QString file, bool parameterised)
+{
+ return ContinuousStructure::Write2XML(file.toStdString().c_str(),parameterised);
+}
+
+bool QCSXCAD::isGeometryValid()
+{
+ if (ContinuousStructure::isGeometryValid()==false) return false;
+ return true;
+}
+
+void QCSXCAD::ImportGeometry()
+{
+ QString filter;
+ QString filename=QFileDialog::getOpenFileName(0,tr("Choose geometry file"),NULL,tr("XML-File (*.xml)"),&filter);
+ if (filename.isEmpty())
+ return;
+ ReadFile(filename);
+}
+
+void QCSXCAD::Edit()
+{
+ CSPrimitives* prim = CSTree->GetCurrentPrimitive();
+ if (prim!=NULL)
+ {
+ CSProperties* oldProp=prim->GetProperty();
+ QCSPrimEditor* newEdit = new QCSPrimEditor(this,prim);
+ if (newEdit->exec()==QDialog::Accepted)
+ {
+ CSProperties* newProp=prim->GetProperty();
+ if (newProp!=oldProp)
+ CSTree->SwitchProperty(prim,newProp);
+ setModified();
+ //CSTree->UpdateTree();
+ }
+ return;
+ }
+ CSProperties* prop = CSTree->GetCurrentProperty();
+ if (prop!=NULL)
+ {
+ int index=GetIndex(prop);
+ QCSPropEditor* newEdit = new QCSPropEditor(this,prop,m_SimMode);
+ if (newEdit->exec()==QDialog::Accepted)
+ {
+ CSTree->RefreshItem(index);
+ setModified();
+ }
+ }
+}
+
+void QCSXCAD::Copy()
+{
+ CSPrimitives* prim = CSTree->GetCurrentPrimitive();
+ if (prim!=NULL)
+ {
+ CSPrimitives* newPrim=prim->GetCopy();
+ if (newPrim==NULL)
+ return;
+ QCSPrimEditor* newEdit = new QCSPrimEditor(this,newPrim);
+ if (newEdit->exec()==QDialog::Accepted)
+ {
+ setModified();
+ CSTree->AddPrimItem(newPrim);
+ }
+ else
+ delete newPrim;
+ }
+}
+
+void QCSXCAD::SetVisibility2All(bool value)
+{
+ for (size_t n=0; n<vProperties.size();++n)
+ {
+ CSProperties* prop = vProperties.at(n);
+ prop->SetVisibility(value);
+ CSTree->RefreshItem(GetIndex(prop));
+ if (value) StructureVTK->SetPropOpacity(prop->GetUniqueID(),prop->GetFillColor().a);
+ else StructureVTK->SetPropOpacity(prop->GetUniqueID(),0);
+ }
+}
+
+void QCSXCAD::HideAll()
+{
+ SetVisibility2All(false);
+}
+
+void QCSXCAD::ShowAll()
+{
+ SetVisibility2All(true);
+}
+
+void QCSXCAD::SetParallelProjection(bool val)
+{
+ StructureVTK->SetParallelProjection(val);
+}
+
+void QCSXCAD::ShowHide()
+{
+ CSProperties* prop = CSTree->GetCurrentProperty();
+ if (prop!=NULL)
+ {
+ prop->SetVisibility(!prop->GetVisibility());
+ CSTree->RefreshItem(GetIndex(prop));
+ if (prop->GetVisibility()) StructureVTK->SetPropOpacity(prop->GetUniqueID(),prop->GetFillColor().a);
+ else StructureVTK->SetPropOpacity(prop->GetUniqueID(),0);
+ }
+}
+
+void QCSXCAD::Delete()
+{
+ CSPrimitives* prim = CSTree->GetCurrentPrimitive();
+ if (prim!=NULL)
+ {
+ if (QMessageBox::question(this,tr("Delete Primitive"),tr("Delete current Primitive (ID: %1)?").arg(prim->GetID()),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
+ {
+ CSTree->DeletePrimItem(prim);
+ DeletePrimitive(prim);
+ setModified();
+ }
+ return;
+ }
+ CSProperties* prop = CSTree->GetCurrentProperty();
+ if (prop!=NULL)
+ {
+ size_t qtyPrim=prop->GetQtyPrimitives();
+ if (qtyPrim>0)
+ {
+ if (QMessageBox::question(this,tr("Delete Property"),tr("\"%1\" contains Primitive(s)!!\n Delete anyway?").arg(prop->GetName().c_str()),QMessageBox::Yes,QMessageBox::No)!=QMessageBox::Yes)
+ return;
+ }
+ else if (QMessageBox::question(this,tr("Delete Property"),tr("Delete current Property?"),QMessageBox::Yes,QMessageBox::No)!=QMessageBox::Yes)
+ return;
+ CSTree->DeletePropItem(prop);
+ DeleteProperty(prop);
+ setModified();
+ }
+}
+
+void QCSXCAD::NewBox()
+{
+ NewPrimitive(new CSPrimBox(clParaSet,CSTree->GetCurrentProperty()));
+}
+
+void QCSXCAD::NewMultiBox()
+{
+ NewPrimitive(new CSPrimMultiBox(clParaSet,CSTree->GetCurrentProperty()));
+}
+
+void QCSXCAD::NewSphere()
+{
+ NewPrimitive(new CSPrimSphere(clParaSet,CSTree->GetCurrentProperty()));
+}
+
+void QCSXCAD::NewCylinder()
+{
+ NewPrimitive(new CSPrimCylinder(clParaSet,CSTree->GetCurrentProperty()));
+}
+
+void QCSXCAD::NewPolygon()
+{
+ NewPrimitive(new CSPrimPolygon(clParaSet,CSTree->GetCurrentProperty()));
+}
+
+void QCSXCAD::NewUserDefined()
+{
+ NewPrimitive(new CSPrimUserDefined(clParaSet,CSTree->GetCurrentProperty()));
+}
+
+
+void QCSXCAD::NewPrimitive(CSPrimitives* newPrim)
+{
+ if (GetQtyProperties()==0)
+ {
+ QMessageBox::question(this,tr("New Primitive"),tr("No Property available. You have to add one first!"),QMessageBox::Ok);
+ delete newPrim;
+ return;
+ }
+ QCSPrimEditor* newEdit = new QCSPrimEditor(this,newPrim);
+
+ if (newEdit->exec()==QDialog::Accepted)
+ {
+ setModified();
+ CSTree->AddPrimItem(newPrim);
+ }
+ else
+ delete newPrim;
+}
+
+void QCSXCAD::NewMaterial()
+{
+ NewProperty(new CSPropMaterial(clParaSet));
+}
+
+void QCSXCAD::NewMetal()
+{
+ NewProperty(new CSPropMetal(clParaSet));
+}
+
+void QCSXCAD::NewExcitation()
+{
+ NewProperty(new CSPropExcitation(clParaSet,GetQtyPropertyType(CSProperties::EXCITATION)));
+}
+
+void QCSXCAD::NewChargeBox()
+{
+ NewProperty(new CSPropProbeBox(clParaSet));
+}
+
+void QCSXCAD::NewResBox()
+{
+ NewProperty(new CSPropResBox(clParaSet));
+}
+
+void QCSXCAD::NewDumpBox()
+{
+ NewProperty(new CSPropDumpBox(clParaSet));
+}
+
+void QCSXCAD::setModified()
+{
+ bModified=true;
+ emit modified(true);
+ Render();
+}
+
+void QCSXCAD::DetectEdges(int nu)
+{
+ InsertEdges2Grid(nu);
+}
+
+void QCSXCAD::BestView()
+{
+ StructureVTK->ResetView();
+}
+
+void QCSXCAD::setViewDir(int dir)
+{
+ switch (dir)
+ {
+ default:
+ case 0:
+ setYZ();
+ return;
+ case 1:
+ setZX();
+ return;
+ case 2:
+ setXY();
+ return;
+ }
+}
+
+void QCSXCAD::setXY()
+{
+ m_ViewDir = 2;
+ StructureVTK->setXY();
+}
+
+void QCSXCAD::setYZ()
+{
+ m_ViewDir = 0;
+ StructureVTK->setYZ();
+}
+
+void QCSXCAD::setZX()
+{
+ m_ViewDir = 1;
+ StructureVTK->setZX();
+}
+
+void QCSXCAD::SetSimMode(int mode)
+{
+ m_SimMode=mode;
+}
+
+void QCSXCAD::NewProperty(CSProperties* newProp)
+{
+ QCSPropEditor* newEdit = new QCSPropEditor(this,newProp,m_SimMode);
+
+ if (newEdit->exec()==QDialog::Accepted)
+ {
+ AddProperty(newProp);
+ CSTree->AddPropItem(newProp);
+ }
+ else delete newProp;
+}
+
+void QCSXCAD::New()
+{
+ if (bModified)
+ {
+ if (QMessageBox::question(this,tr("New Geometry"),tr("Create empty Geometry??"),QMessageBox::Yes,QMessageBox::No)==QMessageBox::No)
+ return;
+ else
+ clear();
+ }
+}
+
+//void QCSXCAD::Load()
+//{
+// if (bModified)
+// switch (QMessageBox::question(this,tr("Load Geometry"),tr("Save current Geometry??"),QMessageBox::Yes,QMessageBox::No,QMessageBox::Cancel))
+// {
+// case QMessageBox::Yes:
+// Save();
+// break;
+// case QMessageBox::Cancel:
+// return;
+// break;
+// };
+// browseGeometryFile();
+//}
+
+
+//void QCSXCAD::Save()
+//{
+// if (QFilename.isEmpty()) {SaveAs(); return;}
+//
+// CheckGeometry();
+//
+// if (QFilename.startsWith("./")) Write2XML((relPath+QFilename.mid(2)).toLatin1().data());
+// else Write2XML(QFilename.toLatin1().data());
+// bModified=false;
+//}
+
+void QCSXCAD::ExportGeometry()
+{
+ QString qFilename=QFileDialog::getSaveFileName(0,"Choose Geometrie File",NULL,"SimGeometryXML (*.xml)");
+ if (qFilename==NULL) return;
+ if (!qFilename.endsWith(".xml")) qFilename+=".xml";
+
+ if (Write2XML(qFilename.toLatin1().data())==false) QMessageBox::warning(this,tr("Geometry Export"),tr("Unknown error occured! Geometry Export failed"),1,0);
+}
+
+void QCSXCAD::ExportGeometry_Povray()
+{
+ QString filename = QFileDialog::getSaveFileName( this, tr("Save Povray file"), QString(), tr("Povray files (*.pov)") );
+ if (filename.isEmpty())
+ return;
+
+ export_pov pov( this );
+ pov.save( filename );
+
+ // start povray?
+ int ans = QMessageBox::question( 0, "Start Povray", "Should the file directly be rendered?", "Yes", "No", "", 0, 1 );
+ if (ans == 1)
+ return;
+
+ // start povray
+ QStringList args;
+ args << filename;
+ args << "-W640";
+ args << "-H480";
+ args << "+A";
+ //only valid for povray >3.7.0 args << "+WT4";
+ QProcess::startDetached( "povray", args, QFileInfo(filename).absolutePath() );
+ return;
+
+ // // Instead of letting renderer to render the scene, we use
+// // an exportor to save it to a file.
+// vtkPOVExporter *povexp = vtkPOVExporter::New();
+// povexp->SetRenderWindow( ((QVTKWidget*)(StructureVTK->GetVTKWidget()))->GetRenderWindow() );
+// povexp->SetFileName("/tmp/TestPOVExporter.pov");
+// cout << "Writing file TestPOVExporter.pov..." << endl;
+//
+// povexp->Write();
+// cout << "Done writing file TestPOVExporter.pov..." << endl;
+//
+// povexp->Delete();
+}
+
+void QCSXCAD::ExportGeometry_X3D(QString filename)
+{
+ if (filename.isEmpty())
+ filename = QFileDialog::getSaveFileName( this, tr("Save X3D-file"), QString(), tr("X3D files (*.x3d)") );
+ if (filename.isEmpty())
+ return;
+
+ export_X3D x3d( this );
+ x3d.save( filename );
+}
+
+void QCSXCAD::ExportGeometry(QString dirname, int type)
+{
+ if (dirname.isEmpty())
+ dirname = QFileDialog::getExistingDirectory(this, tr("Choose directory to save data"));
+ if (dirname.isEmpty())
+ return;
+ int QtyProp = GetQtyProperties();
+ for (int i=0;i<QtyProp;++i)
+ {
+ CSProperties* prop = GetProperty(i);
+ if (prop==NULL) continue;
+
+ unsigned int uID = prop->GetUniqueID();
+
+ if (prop->GetVisibility()==true)
+ {
+ QString filename(dirname);
+ filename.append("/");
+ filename.append(QString::fromUtf8(prop->GetName().c_str()));
+ switch (type)
+ {
+ case 0:
+ StructureVTK->ExportProperty2PolyDataVTK(uID,filename,clGrid.GetDeltaUnit());
+ break;
+ case 1:
+ StructureVTK->ExportProperty2STL(uID,filename,clGrid.GetDeltaUnit());
+ break;
+ case 2:
+ StructureVTK->ExportProperty2PLY(uID,filename,clGrid.GetDeltaUnit());
+ break;
+ default:
+ QMessageBox::warning(this, "Export Dialog","Unkown export type, skipping...");
+ return;
+ break;
+ }
+ }
+ }
+}
+
+void QCSXCAD::ExportGeometry_PolyDataVTK(QString dirname)
+{
+ ExportGeometry(dirname, 0);
+}
+
+void QCSXCAD::ExportGeometry_STL(QString dirname)
+{
+ ExportGeometry(dirname, 1);
+}
+
+void QCSXCAD::ExportGeometry_PLY(QString dirname)
+{
+ ExportGeometry(dirname, 2);
+}
+
+void QCSXCAD::ExportView2Image()
+{
+ if (ViewLevel==VIEW_3D)
+ StructureVTK->ExportView2Image();
+ else
+ QMessageBox::warning(this,tr("PNG export"),tr("Not Yet Implemented for 2D view, use 3D instead."),QMessageBox::Ok,QMessageBox::NoButton);
+}
+
+void QCSXCAD::EnableDiscModelRendering(bool val)
+{
+ m_RenderDiscModels = val;
+}
+
+void QCSXCAD::GUIUpdate()
+{
+ CSTree->UpdateTree();
+ GridEditor->Update();
+ for (int n=0;n<3;++n)
+ viewPlane[n]->setText(GridEditor->GetNormName(n));
+}
+
+void QCSXCAD::clear()
+{
+ ContinuousStructure::clear();
+ GUIUpdate();
+ setModified();
+ bModified=false;
+}
+
+void QCSXCAD::BuildToolBar()
+{
+ QToolBar *mainTB = addToolBar(tr("General"));
+ mainTB->setObjectName("General_ToolBar");
+ QSize TBIconSize(16,16);
+ mainTB->setIconSize(TBIconSize);
+
+ if (QCSX_Settings.GetEdit())
+ mainTB->addAction(QIcon(":/images/filenew.png"),tr("New"),this,SLOT(New()));
+ if (QCSX_Settings.GetEdit())
+ mainTB->addAction(QIcon(":/images/down.png"),tr("Import"),this,SLOT(ImportGeometry()));
+ mainTB->addAction(QIcon(":/images/up.png"),tr("Export"),this,SLOT(ExportGeometry()));
+
+
+ QToolBar *ItemTB = addToolBar(tr("Item View"));
+ ItemTB->setIconSize(TBIconSize);
+ ItemTB->setObjectName("Item_View_ToolBar");
+
+ ItemTB->addAction(tr("CollapseAll"),CSTree,SLOT(collapseAll()));
+ ItemTB->addAction(tr("ExpandAll"),CSTree,SLOT(expandAll()));
+
+ ItemTB->addAction(QIcon(":/images/bulb.png"),tr("ShowAll"),this,SLOT(ShowAll()));
+ ItemTB->addAction(QIcon(":/images/bulb_off.png"),tr("HideAll"),this,SLOT(HideAll()));
+
+ QToolBar *newObjct = NULL;
+ QAction* newAct = NULL;
+
+ if (QCSX_Settings.GetEdit())
+ {
+ newObjct = addToolBar(tr("add new Primitive"));
+ newObjct->setObjectName("New_Primitive_ToolBar");
+
+ newAct = newObjct->addAction(tr("Box"),this,SLOT(NewBox()));
+ newAct->setToolTip(tr("add new Box"));
+
+ newAct = newObjct->addAction(tr("MultiBox"),this,SLOT(NewMultiBox()));
+ newAct->setToolTip(tr("add new Multi-Box"));
+
+ newAct = newObjct->addAction(tr("Sphere"),this,SLOT(NewSphere()));
+ newAct->setToolTip(tr("add new Sphere"));
+
+ newAct = newObjct->addAction(tr("Cylinder"),this,SLOT(NewCylinder()));
+ newAct->setToolTip(tr("add new Cylinder"));
+
+ newAct = newObjct->addAction(tr("Polygon"),this,SLOT(NewPolygon()));
+ newAct->setToolTip(tr("add new Polygon"));
+
+ newAct = newObjct->addAction(tr("User Defined"),this,SLOT(NewUserDefined()));
+ newAct->setToolTip(tr("add new User Definied Primitive"));
+
+ newObjct = addToolBar(tr("add new Property"));
+ newObjct->setObjectName("New_Property_ToolBar");
+
+ newAct = newObjct->addAction(tr("Material"),this,SLOT(NewMaterial()));
+ newAct->setToolTip(tr("add new Material-Property"));
+
+ newAct = newObjct->addAction(tr("Metal"),this,SLOT(NewMetal()));
+ newAct->setToolTip(tr("add new Metal-Property"));
+
+ newAct = newObjct->addAction(tr("Excitation"),this,SLOT(NewExcitation()));
+ newAct->setToolTip(tr("add new Excitation-Property"));
+
+ newAct = newObjct->addAction(tr("ProbeBox"),this,SLOT(NewChargeBox()));
+ newAct->setToolTip(tr("add new Probe-Box-Property"));
+
+ newAct = newObjct->addAction(tr("ResBox"),this,SLOT(NewResBox()));
+ newAct->setToolTip(tr("add new Res-Box-Property"));
+
+ newAct = newObjct->addAction(tr("DumpBox"),this,SLOT(NewDumpBox()));
+ newAct->setToolTip(tr("add new Dump-Box-Property"));
+ }
+
+ newObjct = addToolBar(tr("Zoom"));
+ newObjct->setIconSize(TBIconSize);
+ newObjct->setObjectName("Zoom_ToolBar");
+
+ newAct = newObjct->addAction(QIcon(":/images/viewmagfit.png"),tr("Zoom fit"),this,SLOT(BestView()));
+ newAct->setToolTip("Zoom to best fit all objects");
+
+ viewPlane[0] = newObjct->addAction(GridEditor->GetNormName(0),this,SLOT(setYZ()));
+ viewPlane[0]->setToolTip(tr("Switch to y-z-plane view (x-normal)"));
+ viewPlane[1] = newObjct->addAction(GridEditor->GetNormName(1),this,SLOT(setZX()));
+ viewPlane[1]->setToolTip(tr("Switch to z-x-plane view (y-normal)"));
+ viewPlane[2] = newObjct->addAction(GridEditor->GetNormName(2),this,SLOT(setXY()));
+ viewPlane[2]->setToolTip(tr("Switch to x-y-plane view (z-normal)"));
+
+ addToolBarBreak();
+
+ QActionGroup* ActViewGrp = new QActionGroup(this);
+ newAct = newObjct->addAction(tr("2D"),this,SLOT(View2D()));
+ newAct->setToolTip(tr("Switch to 2D view mode"));
+ ActViewGrp->addAction(newAct);
+ newAct->setCheckable(true);
+ newAct = newObjct->addAction(tr("3D"),this,SLOT(View3D()));
+ newAct->setToolTip(tr("Switch to 3D view mode"));
+ ActViewGrp->addAction(newAct);
+ newAct->setCheckable(true);
+ m_PPview = newObjct->addAction(tr("PP"));
+ m_PPview->setToolTip(tr("Toggle parallel projection view mode"));
+ QObject::connect(m_PPview,SIGNAL(toggled(bool)),this,SLOT(SetParallelProjection(bool)));
+ m_PPview->setCheckable(true);
+
+ if (QCSX_Settings.GetEdit())
+ addToolBar(GridEditor->BuildToolbar());
+}
+
+void QCSXCAD::Render()
+{
+ StructureVTK->RenderGrid();
+ StructureVTK->RenderGeometry();
+ if (m_RenderDiscModels)
+ StructureVTK->RenderDiscMaterialModel();
+
+}
+
+void QCSXCAD::View2D()
+{
+ ViewLevel=VIEW_2D;
+ StructureVTK->SaveCamData();
+ setViewDir(m_ViewDir);
+ StructureVTK->SetParallelProjection(true, false);
+ StructureVTK->Set2DInteractionStyle(true);
+ m_PPview->setDisabled(true);
+}
+
+void QCSXCAD::View3D()
+{
+ ViewLevel=VIEW_3D;
+
+ m_PPview->setDisabled(false);
+ StructureVTK->SetParallelProjection(m_PPview->isChecked(), false);
+ StructureVTK->Set2DInteractionStyle(false, false);
+ StructureVTK->RestoreCamData(true);
+}
+
+void QCSXCAD::keyPressEvent(QKeyEvent * event)
+{
+ if (event->key()==Qt::Key_Delete) Delete();
+ if (event->key()==Qt::Key_Escape)
+ CSTree->setCurrentItem(NULL);
+ QMainWindow::keyPressEvent(event);
+}
+
diff --git a/QCSXCAD/QCSXCAD.h b/QCSXCAD/QCSXCAD.h
new file mode 100644
index 0000000..9bebf20
--- /dev/null
+++ b/QCSXCAD/QCSXCAD.h
@@ -0,0 +1,180 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _QCSXCAD_H_
+#define _QCSXCAD_H_
+
+#include <QMainWindow>
+#include <QHash>
+#include <QString>
+#include "QCSXCAD_Global.h"
+#include "ContinuousStructure.h"
+
+class QVTKStructure;
+class QCSPrimEditor;
+class QCSPropEditor;
+class QCSTreeWidget;
+class QCSGridEditor;
+class QParameterGui;
+class QParameterSet;
+
+class TiXmlNode;
+
+class QCSXCAD_EXPORT QCSXCAD : public QMainWindow, public ContinuousStructure
+{
+ Q_OBJECT
+ friend class export_X3D;
+ friend class export_pov;
+public:
+ QCSXCAD(QWidget *parent=NULL);
+ virtual ~QCSXCAD();
+
+ enum ViewMode
+ {
+ VIEW_2D, VIEW_3D
+ };
+
+// void SetFile(QString filename);
+// void SetPath(QString path) {relPath=path;};
+// QString GetFilename();
+
+ //StaticComplexGeometry* GetDiscGeometry() {return SCGeometry;};
+ QString GetGeometry();
+
+ virtual bool isGeometryValid();
+
+ virtual bool Write2XML(TiXmlNode* rootNode, bool parameterised=true);
+ virtual bool Write2XML(const char* file, bool parameterised=true);
+ virtual bool Write2XML(QString file, bool parameterised=true);
+
+ virtual bool ReadFile(QString filename);
+ bool ReadNode(TiXmlNode* root);
+
+ int GetCurrentProperty();
+
+ ParameterSet* GetParaSet();
+
+ static QString GetInfoString();
+ static QIcon GetLibIcon();
+
+ const QHash<QString,QString> &Get_BC() const { return m_BC; }
+
+signals:
+ void modified(bool val);
+
+public slots:
+ bool CheckGeometry();
+
+ void ImportGeometry();
+ void ExportGeometry();
+ void ExportGeometry_Povray();
+ void ExportGeometry_X3D(QString filename=QString());
+
+ //! Export geometry into a given directory and type
+ void ExportGeometry(QString dirname, int type);
+ void ExportGeometry_PolyDataVTK(QString dirname=QString());
+ void ExportGeometry_STL(QString dirname=QString());
+ void ExportGeometry_PLY(QString dirname=QString());
+
+ void ExportView2Image();
+
+ void EnableDiscModelRendering(bool val=true);
+
+ void Render();
+ virtual void clear();
+ void New();
+
+ void HideAll();
+ void ShowAll();
+
+ //! Enable/Disable 3D parallel projection for the 3D vtk viewer
+ void SetParallelProjection(bool val);
+
+ void BestView();
+ void setViewDir(int dir);
+ void setXY();
+ void setYZ();
+ void setZX();
+
+ void SetSimMode(int mode);
+
+ void GUIUpdate();
+
+ static void aboutQCSXCAD(QWidget* parent=0);
+
+protected slots:
+ void Edit();
+ void Copy();
+ void ShowHide();
+
+ void Delete();
+
+ void NewBox();
+ void NewMultiBox();
+ void NewSphere();
+ void NewCylinder();
+ void NewPolygon();
+ void NewUserDefined();
+
+ void NewMaterial();
+ void NewMetal();
+ void NewExcitation();
+ void NewChargeBox();
+ void NewResBox();
+ void NewDumpBox();
+
+ void setModified();
+
+ void DetectEdges(int nu);
+
+ void View2D();
+ void View3D();
+
+protected:
+ //read supported files, return the root to a CSX
+ TiXmlNode* ReadOpenEMS(TiXmlNode* openEMS);
+
+ void NewPrimitive(CSPrimitives* newPrim);
+ void NewProperty(CSProperties* newProp);
+
+ TiXmlNode* FindRootNode(TiXmlNode* node);
+
+ void SetVisibility2All(bool value);
+
+ bool m_RenderDiscModels;
+
+ QCSTreeWidget *CSTree;
+ QCSGridEditor* GridEditor;
+ QParameterSet* QParaSet;
+
+ QVTKStructure* StructureVTK;
+
+ QAction* viewPlane[3];
+ void BuildToolBar();
+
+ bool bModified;
+ ViewMode ViewLevel;
+ QAction* m_PPview;
+ int m_ViewDir;
+ int m_SimMode;
+
+ virtual void keyPressEvent(QKeyEvent * event);
+
+ QHash<QString,QString> m_BC; //!< boundary conditions
+};
+
+#endif //_QCSXCAD_H_
diff --git a/QCSXCAD/QCSXCAD_Global.cpp b/QCSXCAD/QCSXCAD_Global.cpp
new file mode 100644
index 0000000..d29175e
--- /dev/null
+++ b/QCSXCAD/QCSXCAD_Global.cpp
@@ -0,0 +1,58 @@
+/*
+* Copyright (C) 2012 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <cstring>
+#include <iostream>
+#include <QtCore>
+#include "QCSXCAD_Global.h"
+
+// create global object
+QCSXCAD_Global QCSX_Settings;
+
+QCSXCAD_Global::QCSXCAD_Global()
+{
+ m_EnableEdit = true;
+ m_RenderDiscMat = false;
+}
+
+void QCSXCAD_Global::ShowArguments(std::ostream& ostr, std::string front)
+{
+ ostr << front << "--disableEdit\tDisable Edit" << std::endl;
+ ostr << front << "--RenderDiscMaterial\tRender discrete material" << std::endl;
+}
+
+bool QCSXCAD_Global::parseCommandLineArgument( QString argv )
+{
+ if (argv.isEmpty())
+ return false;
+
+ if (argv.compare("--disableEdit")==0)
+ {
+ std::cout << "QCSXCAD - disabling editing" << std::endl;
+ SetEdit(false);
+ return true;
+ }
+ if (argv.compare("--RenderDiscMaterial")==0)
+ {
+ std::cout << "QCSXCAD - Render discrete material" << std::endl;
+ SetRenderDiscMaterial(true);
+ return true;
+ }
+// std::cerr << "QCSXCAD_Global::parseCommandLineArgument: Warning, unknown argument: " << argv.toStdString() << std::endl;
+ return false;
+}
+
diff --git a/QCSXCAD/QCSXCAD_Global.h b/QCSXCAD/QCSXCAD_Global.h
new file mode 100644
index 0000000..15ce6ff
--- /dev/null
+++ b/QCSXCAD/QCSXCAD_Global.h
@@ -0,0 +1,58 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef QCSXCAD_GLOBAL_H_
+#define QCSXCAD_GLOBAL_H_
+
+#define _QCSXCAD_LIB_NAME_ "QCSXCAD-Lib: Qt-Gui for Continuous Structure XML - CAD"
+#define _QCSXCAD_AUTHOR_ "Thorsten Liebig (2008-2010)"
+#define _QCSXCAD_AUTHOR_MAIL_ "Thorsten.Liebig@gmx.de"
+#define _QCSXCAD_VERSION_ GIT_VERSION
+#define _QCSXCAD_LICENSE_ "LGPL v3"
+
+#if defined(WIN32)
+ #ifdef BUILD_QCSXCAD_LIB
+ #define QCSXCAD_EXPORT Q_DECL_EXPORT
+ #else
+ #define QCSXCAD_EXPORT Q_DECL_IMPORT
+ #endif
+#else
+#define QCSXCAD_EXPORT
+#endif
+
+class QCSXCAD_EXPORT QCSXCAD_Global
+{
+public:
+ QCSXCAD_Global();
+ bool parseCommandLineArgument( QString argv );
+
+ void ShowArguments(std::ostream& ostr, std::string front=std::string());
+
+ void SetEdit(bool val) {m_EnableEdit=val;}
+ bool GetEdit() {return m_EnableEdit;}
+
+ void SetRenderDiscMaterial(bool val) {m_EnableEdit=val;}
+ bool GetRenderDiscMaterial() {return m_EnableEdit;}
+
+protected:
+ bool m_EnableEdit;
+ bool m_RenderDiscMat;
+};
+
+extern QCSXCAD_EXPORT QCSXCAD_Global QCSX_Settings;
+
+#endif /*QCSXCAD_GLOBAL_H_*/
diff --git a/QCSXCAD/QParameterGui.cpp b/QCSXCAD/QParameterGui.cpp
new file mode 100644
index 0000000..e5eb8a8
--- /dev/null
+++ b/QCSXCAD/QParameterGui.cpp
@@ -0,0 +1,401 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QPushButton>
+#include <QDialog>
+#include <QMessageBox>
+#include <QScrollArea>
+#include <QButtonGroup>
+#include <QRadioButton>
+
+#include "QParameterGui.h"
+#include "QCSXCAD_Global.h"
+
+QParameter::QParameter(Parameter* para, QWidget* parent) : QGroupBox(parent)
+{
+ clPara=para;
+ Name=new QLabel("");
+ Value=new QLineEdit("");
+ QObject::connect(Value,SIGNAL(textEdited(QString)),this,SLOT(Changed()));
+
+
+ lay = new QGridLayout();
+// lay->addWidget(new QLabel(tr("Name: ")),0,0);
+// lay->addWidget(Name,0,1);
+
+ lay->addWidget(new QLabel(tr("Value: ")),0,0);
+ lay->addWidget(Value,0,1);
+
+ QPushButton* btn = new QPushButton(QIcon(":/images/failed.png"),QString());
+ QObject::connect(btn,SIGNAL(clicked()),this,SLOT(deleteLater()));
+ QObject::connect(btn,SIGNAL(clicked()),this,SLOT(DeleteParameter()));
+ btn->setToolTip(tr("Delete parameter"));
+ lay->addWidget(btn,0,3);
+
+ SweepCB = new QCheckBox();
+ QObject::connect(SweepCB,SIGNAL(stateChanged(int)),this,SLOT(SweepState(int)));
+ SweepCB->setToolTip(tr("Sweep this parameter"));
+ lay->addWidget(SweepCB,0,2);
+
+ setLayout(lay);
+ //setFrameStyle(QFrame::Box);
+}
+
+QParameter::~QParameter()
+{
+}
+
+void QParameter::DeleteParameter()
+{
+ emit Delete(clPara);
+}
+
+void QParameter::SweepState(int state)
+{
+ clPara->SetSweep(state);
+}
+
+void QParameter::Changed()
+{
+ double val=Value->text().toDouble();
+ clPara->SetValue(val);
+ emit ParameterChanged();
+}
+
+bool QParameter::Edit()
+{
+ QDialog* diag = new QDialog(this);
+
+ QGroupBox* Group=new QGroupBox(tr("Edit Constant Parameter"));
+
+ QGridLayout* lay = new QGridLayout();
+
+ lay->addWidget(new QLabel(tr("Name: ")),0,0);
+ QLineEdit* eName= new QLineEdit(QString::fromUtf8(clPara->GetName().c_str()));
+ lay->addWidget(eName,0,1);
+
+ lay->addWidget(new QLabel(tr("Value: ")),1,0);
+ QLineEdit* eValue=new QLineEdit(QString("%1").arg(clPara->GetValue()));
+ lay->addWidget(eValue,1,1);
+
+ Group->setLayout(lay);
+
+ QGridLayout* Grid = new QGridLayout();
+ Grid->addWidget(Group,0,0,1,2);
+
+ QPushButton* PB = new QPushButton(tr("Ok"));
+ QObject::connect(PB,SIGNAL(clicked()),diag,SLOT(accept()));
+ Grid->addWidget(PB,1,0);
+ PB = new QPushButton(tr("Cancel"));
+ QObject::connect(PB,SIGNAL(clicked()),diag,SLOT(reject()));
+ Grid->addWidget(PB,1,1);
+
+ diag->setLayout(Grid);
+ diag->show();
+ diag->setFixedSize(diag->size());
+
+ if (diag->exec()==QDialog::Accepted)
+ {
+ if (eName->text().isEmpty())
+ {
+ QMessageBox::warning(this,tr("Edit Parameter"),tr("Parameter-Name is invalid!"));
+ return false;
+ }
+ clPara->SetName(eName->text().toStdString());
+ clPara->SetValue(eValue->text().toDouble());
+ Update();
+ return true;
+ }
+ return false;
+}
+
+void QParameter::Update()
+{
+ //Name->setText(clPara->GetName());
+ setTitle(QString::fromUtf8(clPara->GetName().c_str()));
+ Value->setText(QString("%1").arg(clPara->GetValue()));
+ if (clPara->GetSweep()) SweepCB->setCheckState(Qt::Checked);
+ else SweepCB->setCheckState(Qt::Unchecked);
+}
+
+QLinearParameter::QLinearParameter(LinearParameter* para, QWidget* parent) : QParameter(para,parent)
+{
+ slider = new QSlider(Qt::Horizontal);
+ lay->addWidget(slider,1,0,1,3);
+ Value->setReadOnly(true);
+ QObject::connect(slider,SIGNAL(valueChanged(int)),this,SLOT(Changed()));
+
+ QPushButton* btn = new QPushButton(QIcon(":/images/edit.png"),QString());
+ QObject::connect(btn,SIGNAL(clicked()),this,SLOT(Edit()));
+ lay->addWidget(btn,1,3);
+ btn->setToolTip(tr("Edit Parameter"));
+}
+
+
+QLinearParameter::~QLinearParameter()
+{
+}
+
+bool QLinearParameter::Edit()
+{
+ LinearParameter* LP = clPara->ToLinear();
+ if (LP==NULL) return false;
+
+ QDialog* diag = new QDialog(this);
+
+ QGroupBox* Group=new QGroupBox(tr("Edit Linear Parameter"));
+
+ QGridLayout* lay = new QGridLayout();
+
+ lay->addWidget(new QLabel(tr("Name: ")),0,0);
+ QLineEdit* eName= new QLineEdit(QString::fromUtf8(LP->GetName().c_str()));
+ lay->addWidget(eName,0,1);
+
+ lay->addWidget(new QLabel(tr("Value: ")),1,0);
+ QLineEdit* eValue=new QLineEdit(QString("%1").arg(LP->GetValue()));
+ lay->addWidget(eValue,1,1);
+
+ lay->addWidget(new QLabel(tr("Start: ")),2,0);
+ QLineEdit* Start=new QLineEdit(QString("%1").arg(LP->GetMin()));
+ lay->addWidget(Start,2,1);
+
+ lay->addWidget(new QLabel(tr("Stop: ")),3,0);
+ QLineEdit* Stop=new QLineEdit(QString("%1").arg(LP->GetMax()));
+ lay->addWidget(Stop,3,1);
+
+ lay->addWidget(new QLabel(tr("Step: ")),4,0);
+ QLineEdit* Step=new QLineEdit(QString("%1").arg(LP->GetStep()));
+ lay->addWidget(Step,4,1);
+
+ Group->setLayout(lay);
+
+ QGridLayout* Grid = new QGridLayout();
+ Grid->addWidget(Group,0,0,1,2);
+
+ QPushButton* PB = new QPushButton(tr("Ok"));
+ QObject::connect(PB,SIGNAL(clicked()),diag,SLOT(accept()));
+ Grid->addWidget(PB,1,0);
+ PB = new QPushButton(tr("Cancel"));
+ QObject::connect(PB,SIGNAL(clicked()),diag,SLOT(reject()));
+ Grid->addWidget(PB,1,1);
+
+ diag->setLayout(Grid);
+ diag->show();
+ diag->setFixedSize(diag->size());
+
+ if (diag->exec()==QDialog::Accepted)
+ {
+ if (eName->text().isEmpty())
+ {
+ QMessageBox::warning(this,tr("Edit Parameter"),tr("Parameter-Name is invalid!"));
+ return false;
+ }
+ LP->SetName(eName->text().toStdString());
+ LP->SetMin(Start->text().toDouble());
+ LP->SetMax(Stop->text().toDouble());
+ LP->SetStep(Step->text().toDouble());
+ LP->SetValue(eValue->text().toDouble());
+ Update();
+ return true;
+ }
+ return false;
+}
+
+void QLinearParameter::Update()
+{
+ QParameter::Update();
+ LinearParameter* LP=clPara->ToLinear();
+ if (LP==NULL) return;
+ if ((LP->GetStep()>0) && (LP->GetMax()>LP->GetMin()))
+ {
+ double steps=(LP->GetMax()-LP->GetMin())/LP->GetStep();
+ double val=(LP->GetValue()-LP->GetMin())/LP->GetStep();
+ slider->setRange(1,(int)steps+1);
+ slider->setValue((int)val+1);
+ }
+ else slider->setRange(1,1);
+}
+
+void QLinearParameter::Changed()
+{
+ LinearParameter* LP=clPara->ToLinear();
+ if (LP==NULL) return;
+ double val=LP->GetMin()+LP->GetStep()*(slider->value()-1);
+ LP->SetValue(val);
+ Value->setText(QString("%1").arg(LP->GetValue()));
+ emit ParameterChanged();
+}
+
+QParameterSet::QParameterSet(QWidget* parent) : QWidget(parent), ParameterSet()
+{
+ QGridLayout* grid = new QGridLayout();
+
+ ParaLay = new QVBoxLayout();
+
+ QScrollArea* QSA = new QScrollArea();
+ QWidget* QW = new QWidget();
+
+ QVBoxLayout* QVBL = new QVBoxLayout();
+ QVBL->addLayout(ParaLay);
+ QVBL->addStretch(1);
+ QW->setLayout(QVBL);
+ QSA->setWidget(QW);
+ QSA->setWidgetResizable(true);
+
+ grid->addWidget(QSA);
+// grid->addLayout(ParaLay,0,0,1,2);
+
+// grid->setRowStretch(1,1);
+
+ QPushButton* btn = new QPushButton(tr("New"));
+ QObject::connect(btn,SIGNAL(clicked()),this,SLOT(NewParameter()));
+ btn->setEnabled(QCSX_Settings.GetEdit());
+ grid->addWidget(btn,2,0);
+
+ setLayout(grid);
+}
+
+QParameterSet::~QParameterSet()
+{
+}
+
+void QParameterSet::SetModified(bool mod)
+{
+ emit ParameterChanged();
+ ParameterSet::SetModified(mod);
+}
+
+void QParameterSet::clear()
+{
+ ParameterSet::clear();
+ for (int i=0;i<vecQPara.size();++i)
+ {
+ QParameter* QPara=vecQPara.at(i);
+ delete QPara;
+ }
+ vecQPara.clear();
+}
+
+void QParameterSet::NewParameter()
+{
+ QDialog* diag = new QDialog(this);
+
+ QGroupBox* Group=new QGroupBox(tr("Choose Type of Parameter"));
+
+ QVBoxLayout* lay = new QVBoxLayout();
+
+ QButtonGroup* BG = new QButtonGroup();
+ QRadioButton* RB = new QRadioButton("Constant");
+ RB->setChecked(true);
+ BG->addButton(RB,0);
+ lay->addWidget(RB);
+ RB = new QRadioButton("Linear");
+ BG->addButton(RB,1);
+ lay->addWidget(RB);
+
+ Group->setLayout(lay);
+
+ QGridLayout* Grid = new QGridLayout();
+ Grid->addWidget(Group,0,0,1,2);
+
+ QPushButton* PB = new QPushButton(tr("Ok"));
+ QObject::connect(PB,SIGNAL(clicked()),diag,SLOT(accept()));
+ Grid->addWidget(PB,1,0);
+ PB = new QPushButton(tr("Cancel"));
+ QObject::connect(PB,SIGNAL(clicked()),diag,SLOT(reject()));
+ Grid->addWidget(PB,1,1);
+
+ diag->setLayout(Grid);
+ diag->show();
+ diag->setFixedSize(diag->size());
+
+ if (diag->exec()==QDialog::Accepted)
+ {
+ Parameter* newPara=NULL;
+ QParameter* QPara=NULL;
+ switch (BG->checkedId())
+ {
+ case 0:
+ newPara = new Parameter();
+ QPara = new QParameter(newPara);
+ break;
+ case 1:
+ newPara = new LinearParameter();
+ QPara = new QLinearParameter(newPara->ToLinear());
+ break;
+ }
+ if (newPara!=NULL)
+ {
+ if (QPara->Edit()==true) LinkParameter(newPara);
+ else
+ {
+ delete newPara;
+ delete QPara;
+ }
+ }
+ }
+}
+
+size_t QParameterSet::DeleteParameter(Parameter* para)
+{
+ if (para!=NULL)
+ for (int i=0;i<vecQPara.size();++i)
+ {
+ QParameter* QPara=vecQPara.at(i);
+ if (QPara->GetParameter()==para)
+ {
+ delete QPara;
+ vecQPara.remove(i);
+ }
+ }
+ return ParameterSet::DeleteParameter(para);
+}
+
+void QParameterSet::AddParaWid(Parameter* newPara)
+{
+ if (newPara!=NULL)
+ {
+ QParameter* QPara=NULL;
+ switch (newPara->GetType())
+ {
+ case 0:
+ QPara = new QParameter(newPara);
+ break;
+ case 1:
+ QPara = new QLinearParameter(newPara->ToLinear());
+ break;
+ default:
+ QPara=NULL;
+ break;
+ }
+ if (QPara!=NULL)
+ {
+ ParaLay->addWidget(QPara);
+ QObject::connect(QPara,SIGNAL(Delete(Parameter*)),this,SLOT(DeleteParameter(Parameter*)));
+ QObject::connect(QPara,SIGNAL(ParameterChanged()),this,SLOT(SetModified()));
+ QPara->Update();
+ vecQPara.append(QPara);
+ }
+ }
+}
+
+size_t QParameterSet::LinkParameter(Parameter* newPara)
+{
+ AddParaWid(newPara);
+ return ParameterSet::LinkParameter(newPara);
+
+}
diff --git a/QCSXCAD/QParameterGui.h b/QCSXCAD/QParameterGui.h
new file mode 100644
index 0000000..239bde1
--- /dev/null
+++ b/QCSXCAD/QParameterGui.h
@@ -0,0 +1,107 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _QPARAMETERGUI_H_
+#define _QPARAMETERGUI_H_
+
+#include <QCheckBox>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QGridLayout>
+#include <QSlider>
+
+#include "ParameterObjects.h"
+
+class QParameter : public QGroupBox
+{
+ Q_OBJECT
+public:
+ QParameter(Parameter* para, QWidget* parent=NULL);
+ virtual ~QParameter();
+
+ Parameter* GetParameter() {return clPara;};
+
+signals:
+ void ParameterChanged();
+ void Delete(Parameter* para);
+
+public slots:
+ virtual bool Edit();
+ virtual void Update();
+ void DeleteParameter();
+ void SweepState(int state);
+
+protected slots:
+ virtual void Changed();
+
+protected:
+ Parameter* clPara;
+ QLabel* Name;
+ QLineEdit* Value;
+ QGridLayout *lay;
+ QCheckBox* SweepCB;
+};
+
+class QLinearParameter : public QParameter
+{
+ Q_OBJECT
+public:
+ QLinearParameter(LinearParameter* para, QWidget* parent=NULL);
+ virtual ~QLinearParameter();
+
+signals:
+
+public slots:
+ virtual bool Edit();
+ virtual void Update();
+
+protected slots:
+ virtual void Changed();
+
+protected:
+ QSlider* slider;
+};
+
+class QParameterSet : public QWidget, public ParameterSet
+{
+ Q_OBJECT
+public:
+ QParameterSet(QWidget* parent=NULL);
+ virtual ~QParameterSet();
+
+ virtual size_t LinkParameter(Parameter* newPara);
+
+signals:
+ void ParameterChanged();
+
+public slots:
+ void NewParameter();
+ virtual void SetModified(bool mod=true);
+
+ virtual void clear();
+
+protected slots:
+ virtual size_t DeleteParameter(Parameter* para);
+
+protected:
+ void AddParaWid(Parameter* newPara);
+ QVBoxLayout* ParaLay;
+ QVector<QParameter*> vecQPara;
+};
+
+#endif //_QPARAMETERGUI_H_
diff --git a/QCSXCAD/QVTKStructure.cpp b/QCSXCAD/QVTKStructure.cpp
new file mode 100644
index 0000000..9482dde
--- /dev/null
+++ b/QCSXCAD/QVTKStructure.cpp
@@ -0,0 +1,873 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QFileDialog>
+
+#include "QVTKStructure.h"
+
+#include "QVTKWidget.h"
+#include "vtkRenderWindow.h"
+#include "vtkRenderWindowInteractor.h"
+#include "vtkRenderer.h"
+#include "vtkAxesActor.h"
+#include "vtkActor.h"
+#include "ContinuousStructure.h"
+#include "ParameterCoord.h"
+#include "VTKPrimitives.h"
+#include "vtkCubeSource.h"
+#include "vtkPolyDataMapper.h"
+#include "vtkCellArray.h"
+#include "vtkActor.h"
+#include "vtkLODActor.h"
+#include "vtkFollower.h"
+#include "vtkAxes.h"
+#include "vtkVectorText.h"
+#include "vtkFollower.h"
+#include "vtkTextProperty.h"
+#include "vtkTextActor.h"
+#include "vtkCamera.h"
+#include "vtkProperty.h"
+#include "vtkOrientationMarkerWidget.h"
+#include "vtkPropAssembly.h"
+#include "vtkTextProperty.h"
+#include "vtkCaptionActor2D.h"
+#include "vtkRectilinearGrid.h"
+#include "vtkRectilinearGridGeometryFilter.h"
+#include "vtkDoubleArray.h"
+#include "vtkActorCollection.h"
+#include "vtkInteractorStyle.h"
+#include "vtkCommand.h"
+#include "vtkCallbackCommand.h"
+#include "vtkWindowToImageFilter.h"
+#include "vtkPNGWriter.h"
+#include <vtkStructuredGrid.h>
+#include <vtkStructuredGridGeometryFilter.h>
+#include <vtkCamera.h>
+#include <vtkInteractorStyleTrackballCamera.h>
+#include "vtkInteractorStyleRubberBand2DPlane.h"
+#include <vtkInteractorStyleRubberBand2D.h>
+
+#include "CSPrimPoint.h"
+#include "CSPrimBox.h"
+#include "CSPrimMultiBox.h"
+#include "CSPrimSphere.h"
+#include "CSPrimSphericalShell.h"
+#include "CSPrimCylinder.h"
+#include "CSPrimCylindricalShell.h"
+#include "CSPrimPolygon.h"
+#include "CSPrimLinPoly.h"
+#include "CSPrimRotPoly.h"
+#include "CSPrimPolyhedron.h"
+#include "CSPrimCurve.h"
+#include "CSPrimWire.h"
+#include "CSPrimUserDefined.h"
+
+#include "CSPropDiscMaterial.h"
+
+#include "CSTransform.h"
+
+QVTKStructure::QVTKStructure()
+{
+ clCS=NULL;
+ ActorGridPlane[0]=NULL;
+ ActorGridPlane[1]=NULL;
+ ActorGridPlane[2]=NULL;
+ m_Rect_Grid = NULL;
+ m_Struct_Grid = NULL;
+ m_CamData = NULL;
+
+ iResolution=32;
+ AllowUpdate=true;
+
+ VTKWidget= new QVTKWidget();
+
+ ren = vtkRenderer::New();
+ VTKWidget->GetRenderWindow()->AddRenderer(ren);
+
+ AddAxes();
+ SetBackgroundColor(255,255,255);
+
+ SetCallback(VTKWidget->GetRenderWindow()->GetInteractor());
+}
+
+QVTKStructure::~QVTKStructure()
+{
+ clear();
+}
+
+void QVTKStructure::AddAxes()
+{
+ Axes = vtkAxesActor::New();
+ Axes->SetTotalLength(4,4,4);
+ vtkOrientationMarkerWidget* marker = vtkOrientationMarkerWidget::New();
+ vtkPropAssembly* assembly = vtkPropAssembly::New();
+ assembly->AddPart(Axes);
+
+ marker->SetOrientationMarker(assembly);
+ marker->SetViewport(0.0,0.0,0.25,0.25);
+
+ marker->SetInteractor(VTKWidget->GetRenderWindow()->GetInteractor());
+ marker->SetEnabled(1);
+ marker->InteractiveOff();
+
+ //assembly->Delete();
+ //marker->Delete();
+}
+
+void QVTKStructure::SetBackgroundColor(int r, int g, int b)
+{
+ double rgb[3]={(double)r/255.0,(double)g/255.0,(double)b/255.0};
+ double irgb[3]={1-rgb[0],1-rgb[1],1-rgb[2]};
+ ren->SetBackground(rgb);
+
+ Axes->GetXAxisCaptionActor2D()->GetCaptionTextProperty()->SetColor(irgb);
+ Axes->GetYAxisCaptionActor2D()->GetCaptionTextProperty()->SetColor(irgb);
+ Axes->GetZAxisCaptionActor2D()->GetCaptionTextProperty()->SetColor(irgb);
+
+ for (int i=0;i<3;++i)
+ {
+ if (ActorGridPlane[i]!=NULL) ActorGridPlane[i]->GetProperty()->SetColor(irgb);
+ }
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::SetGeometry(ContinuousStructure *CS)
+{
+ clear();
+ clCS=CS;
+}
+
+void QVTKStructure::clear()
+{
+ for (int i=0;i<LayerPrimitives.size();++i)
+ {
+ delete LayerPrimitives.at(i).VTKProp;
+ }
+ LayerPrimitives.clear();
+
+ for (int i=0;i<m_DiscMatModels.size();++i)
+ {
+ delete m_DiscMatModels.at(i).vtk_model;
+ }
+ m_DiscMatModels.clear();
+
+ for (int i=0; i<3; i++)
+ {
+ if (ActorGridPlane[i]!=NULL)
+ {
+ ren->RemoveActor(ActorGridPlane[i]);
+ ActorGridPlane[i]->Delete();
+ ActorGridPlane[i]=NULL;
+ }
+ }
+ if (m_Rect_Grid)
+ m_Rect_Grid->Delete();
+ m_Rect_Grid=NULL;
+ if (m_Struct_Grid)
+ m_Struct_Grid->Delete();
+ m_Struct_Grid=NULL;
+}
+
+
+void QVTKStructure::RenderGrid()
+{
+ if (clCS==NULL) return;
+ CSRectGrid* CSGrid = clCS->GetGrid();
+ if (CSGrid->isValid()==false)
+ return;
+
+ if (CSGrid->GetMeshType()==CARTESIAN)
+ {
+ if (m_Rect_Grid)
+ m_Rect_Grid->Delete();
+ m_Rect_Grid = vtkRectilinearGrid::New();
+ vtkDoubleArray *Coords[3];
+ int iQty[3];
+
+ for (int n=0;n<3;++n)
+ {
+ iQty[n]=CSGrid->GetQtyLines(n);
+ Coords[n]=vtkDoubleArray::New();
+ for (int m=0;m<iQty[n];++m) Coords[n]->InsertNextValue(CSGrid->GetLine(n,m));
+ }
+ if (iQty[0]*iQty[1]*iQty[2]==0)
+ {
+ for (int n=0;n<3;++n) Coords[n]->Delete();
+ return;
+ }
+ m_Rect_Grid->SetDimensions(iQty[0],iQty[1],iQty[2]);
+ m_Rect_Grid->SetXCoordinates(Coords[0]);
+ m_Rect_Grid->SetYCoordinates(Coords[1]);
+ m_Rect_Grid->SetZCoordinates(Coords[2]);
+ for (int n=0;n<3;++n)
+ Coords[n]->Delete();
+ }
+ else if (CSGrid->GetMeshType()==CYLINDRICAL)
+ {
+ if (m_Struct_Grid)
+ m_Struct_Grid->Delete();
+ m_Struct_Grid = vtkStructuredGrid::New();
+
+ unsigned int uiQty[3];
+ double* lines[3]={NULL,NULL,NULL};
+ for (unsigned int n=0;n<3;++n)
+ lines[n] = CSGrid->GetLines(n,lines[n],uiQty[n]);
+
+ m_Struct_Grid->SetDimensions(uiQty[0],uiQty[1],uiQty[2]);
+ vtkPoints *points = vtkPoints::New();
+ points->SetNumberOfPoints(uiQty[0]*uiQty[1]*uiQty[2]);
+ double r[3];
+ int id=0;
+ for (unsigned int k=0; k<uiQty[2]; ++k)
+ for (unsigned int j=0; j<uiQty[1]; ++j)
+ for (unsigned int i=0; i<uiQty[0]; ++i)
+ {
+ r[0] = lines[0][i] * cos(lines[1][j]);
+ r[1] = lines[0][i] * sin(lines[1][j]);
+ r[2] = lines[2][k];
+ points->SetPoint(id++,r);
+ }
+ m_Struct_Grid->SetPoints(points);
+ points->Delete();
+ for (unsigned int n=0;n<3;++n)
+ {
+ delete[] lines[n];
+ lines[n] = NULL;
+ }
+ }
+ else
+ cerr << "QVTKStructure::RenderGrid(): Error, unknown grid type!" << endl;
+
+ RenderGridDir(0,0);
+ RenderGridDir(1,0);
+ RenderGridDir(2,0);
+}
+
+void QVTKStructure::RenderGridX(int plane_pos)
+{
+ RenderGridDir(0,plane_pos);
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::RenderGridY(int plane_pos)
+{
+ RenderGridDir(1,plane_pos);
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+
+}
+
+void QVTKStructure::RenderGridZ(int plane_pos)
+{
+ RenderGridDir(2,plane_pos);
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::RenderGridDir(int dir, unsigned int plane_pos)
+{
+ if (ActorGridPlane[dir]!=NULL)
+ {
+ ren->RemoveActor(ActorGridPlane[dir]);
+ ActorGridPlane[dir]->Delete();
+ }
+
+ ActorGridPlane[dir] = vtkLODActor::New();
+ vtkPolyDataMapper *gridMapper = vtkPolyDataMapper::New();
+ vtkPolyDataAlgorithm *plane = NULL;
+
+ CSRectGrid* CSGrid = clCS->GetGrid();
+ int uiQty[3];
+
+ for (int n=0;n<3;++n)
+ uiQty[n]=CSGrid->GetQtyLines(n);
+ if ((int)plane_pos>=uiQty[dir])
+ {
+ cerr << "QVTKStructure::RenderGridDir: requested plane postion is out of range, resetting to max value!" << endl;
+ plane_pos = uiQty[dir]-1;
+ }
+
+ if (CSGrid->GetMeshType()==CARTESIAN)
+ {
+ if (m_Rect_Grid==NULL)
+ {
+ ActorGridPlane[dir]->Delete();
+ gridMapper->Delete();
+ ActorGridPlane[dir]=NULL;
+ cerr << "QVTKStructure::RenderGridDir: Error, rect grid mesh was not created, skipping drawing..." << endl;
+ return;
+ }
+ vtkRectilinearGridGeometryFilter *grid_plane = vtkRectilinearGridGeometryFilter::New();
+ plane = grid_plane;
+#if VTK_MAJOR_VERSION>=6
+ grid_plane->SetInputData(m_Rect_Grid);
+#else
+ grid_plane->SetInput(m_Rect_Grid);
+#endif
+ switch (dir)
+ {
+ case 2:
+ {
+ grid_plane->SetExtent(0,uiQty[0]-1, 0,uiQty[1]-1, plane_pos,plane_pos);
+ break;
+ }
+ case 1:
+ {
+ grid_plane->SetExtent(0,uiQty[0]-1, plane_pos,plane_pos, 0,uiQty[2]-1);
+ break;
+ }
+ case 0:
+ {
+ grid_plane->SetExtent(plane_pos,plane_pos, 0,uiQty[1]-1, 0,uiQty[2]-1);
+ break;
+ }
+ }
+ }
+ else if (CSGrid->GetMeshType()==CYLINDRICAL)
+ {
+ if (m_Struct_Grid==NULL)
+ {
+ ActorGridPlane[dir]->Delete();
+ gridMapper->Delete();
+ ActorGridPlane[dir]=NULL;
+ cerr << "QVTKStructure::RenderGridDir: Error, structured grid mesh was not created, skipping drawing..." << endl;
+ return;
+ }
+
+ vtkStructuredGridGeometryFilter *grid_plane = vtkStructuredGridGeometryFilter::New();
+ plane = grid_plane;
+#if VTK_MAJOR_VERSION>=6
+ grid_plane->SetInputData(m_Struct_Grid);
+#else
+ grid_plane->SetInput(m_Struct_Grid);
+#endif
+ switch (dir)
+ {
+ case 2:
+ {
+ grid_plane->SetExtent(0,uiQty[0]-1, 0,uiQty[1]-1, plane_pos,plane_pos);
+ break;
+ }
+ case 1:
+ {
+ grid_plane->SetExtent(0,uiQty[0]-1, plane_pos,plane_pos, 0,uiQty[2]-1);
+ break;
+ }
+ case 0:
+ {
+ grid_plane->SetExtent(plane_pos,plane_pos, 0,uiQty[1]-1, 0,uiQty[2]-1);
+ break;
+ }
+ }
+ }
+ else
+ cerr << "QVTKStructure::RenderGrid(): Error, unknown grid type!" << endl;
+
+ gridMapper->SetInputConnection(plane->GetOutputPort());
+ ActorGridPlane[dir]->SetMapper(gridMapper);
+ ActorGridPlane[dir]->GetProperty()->SetColor(0,0,0);
+ ActorGridPlane[dir]->GetProperty()->SetDiffuse(0);
+ ActorGridPlane[dir]->GetProperty()->SetAmbient(1);
+ ActorGridPlane[dir]->GetProperty()->SetRepresentationToWireframe();
+ ActorGridPlane[dir]->GetProperty()->SetOpacity((double)GridOpacity/255.0);
+ ren->AddActor(ActorGridPlane[dir]);
+ gridMapper->Delete();
+ plane->Delete();
+
+}
+
+void QVTKStructure::SetGridOpacity(int val)
+{
+ GridOpacity = val;
+ if (AllowUpdate==false) return;
+ for (int i=0;i<3;++i)
+ {
+ if (ActorGridPlane[i]!=NULL) ActorGridPlane[i]->GetProperty()->SetOpacity((double)val/255.0);
+ }
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::ResetView()
+{
+ ren->ResetCamera();
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::setXY()
+{
+ vtkCamera* cam=ren->GetActiveCamera();
+ ren->ResetCamera();
+ double fp[3];
+ cam->SetViewUp(0.5,0.5,0.5);
+ cam->GetFocalPoint(fp);
+ fp[2]+=1;
+ cam->SetPosition(fp);
+ cam->SetRoll(0);
+ ResetView();
+}
+
+void QVTKStructure::setYZ()
+{
+ vtkCamera* cam=ren->GetActiveCamera();
+ ren->ResetCamera();
+ double fp[3];
+ cam->SetViewUp(0.5,0.5,0.5);
+ cam->GetFocalPoint(fp);
+ fp[0]+=1;
+ cam->SetPosition(fp);
+
+ cam->SetRoll(-90);
+ ResetView();
+}
+
+
+void QVTKStructure::setZX()
+{
+ vtkCamera* cam=ren->GetActiveCamera();
+ ren->ResetCamera();
+ double fp[3];
+ cam->SetViewUp(0.5,0.5,0.5);
+ cam->GetFocalPoint(fp);
+ fp[1]+=1;
+ cam->SetPosition(fp);
+ cam->SetRoll(90);
+ ResetView();
+}
+
+void QVTKStructure::SetPropOpacity(unsigned int uiID, int val)
+{
+ for (int i=0;i<LayerPrimitives.size();++i)
+ {
+ if (LayerPrimitives.at(i).uID==uiID)
+ {
+ if (LayerPrimitives.at(i).VTKProp!=NULL) LayerPrimitives.at(i).VTKProp->SetOpacity2All((double)val/255.0);
+ }
+ }
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::RenderGeometry()
+{
+ for (int i=0;i<LayerPrimitives.size();++i)
+ {
+ delete LayerPrimitives.at(i).VTKProp;
+ }
+ LayerPrimitives.clear();
+ if (clCS==NULL) return;
+ int QtyProp=clCS->GetQtyProperties();
+ for (int i=0;i<QtyProp;++i)
+ {
+ CSProperties* prop = clCS->GetProperty(i);
+ if (prop==NULL) return;
+ int QtyPrim=prop->GetQtyPrimitives();
+ if (QtyPrim>0)
+ {
+ VTKLayerStruct layStruct;
+ VTKPrimitives* vtkPrims= new VTKPrimitives(ren);
+ layStruct.VTKProp=vtkPrims;
+ layStruct.uID=prop->GetUniqueID();
+ LayerPrimitives.append(layStruct);
+ RGBa col=prop->GetFillColor();
+ if (prop->GetVisibility()==false) col.a=0;
+ double rgb[3]={(double)col.R/255.0,(double)col.G/255.0,(double)col.B/255.0};
+ for (int n=0;n<QtyPrim;++n)
+ {
+ CSPrimitives* prim = prop->GetPrimitive(n);
+ if (prim==NULL) return;
+ CoordinateSystem primCS = prim->GetCoordinateSystem();
+ CSTransform* transform = prim->GetTransform();
+ double* transform_matrix = NULL;
+ if (transform)
+ transform_matrix = transform->GetMatrix();
+ if (primCS==UNDEFINED_CS)
+ primCS=clCS->GetCoordInputType();
+ switch (prim->GetType())
+ {
+ case CSPrimitives::BOX:
+ {
+ CSPrimBox* box = prim->ToBox();
+ if (primCS==CARTESIAN)
+ vtkPrims->AddCube(box->GetStartCoord()->GetCartesianCoords(),box->GetStopCoord()->GetCartesianCoords(),rgb,(double)col.a/255.0,transform_matrix);
+ else if (primCS==CYLINDRICAL)
+ vtkPrims->AddCylindricalCube(box->GetStartCoord()->GetCylindricalCoords(),box->GetStopCoord()->GetCylindricalCoords(),rgb,(double)col.a/255.0,transform_matrix);
+ break;
+ }
+ case CSPrimitives::MULTIBOX:
+ {
+ CSPrimMultiBox* multibox = prim->ToMultiBox();
+ int qtyPts=multibox->GetQtyBoxes()*2;
+ double *coords = new double[qtyPts*3];
+ for (int a=0;a<qtyPts;a=a+2)
+ {
+ coords[a]=multibox->GetCoord(3*a);
+ coords[a+1]=multibox->GetCoord(3*a+1);
+ coords[qtyPts+a]=multibox->GetCoord(3*a+2);
+ coords[qtyPts+a+1]=multibox->GetCoord(3*a+3);
+ coords[2*qtyPts+a]=multibox->GetCoord(3*a+4);
+ coords[2*qtyPts+a+1]=multibox->GetCoord(3*a+5);
+ }
+ vtkPrims->AddDisc(coords,qtyPts,rgb,(double)col.a/255.0,transform_matrix);
+ delete[] coords;
+ break;
+ }
+ case CSPrimitives::SPHERE:
+ {
+ CSPrimSphere* sphere = prim->ToSphere();
+ vtkPrims->AddSphere(sphere->GetCenter()->GetCartesianCoords(),sphere->GetRadius(),rgb,(double)col.a/255.0,iResolution,transform_matrix);
+ break;
+ }
+ case CSPrimitives::SPHERICALSHELL:
+ {
+ CSPrimSphericalShell* sphereshell = prim->ToSphericalShell();
+ const double* center = sphereshell->GetCenter()->GetCartesianCoords();
+ const double radius = sphereshell->GetRadius();
+ const double shellWidth = sphereshell->GetShellWidth();
+ vtkPrims->AddSphericalShell(center, radius-shellWidth/2, radius+shellWidth/2, rgb, (double)col.a/255.0, iResolution, transform_matrix);
+ break;
+ }
+ case CSPrimitives::CYLINDER:
+ {
+ CSPrimCylinder* cylinder = prim->ToCylinder();
+ vtkPrims->AddCylinder2(cylinder->GetAxisStartCoord()->GetCartesianCoords(),cylinder->GetAxisStopCoord()->GetCartesianCoords(),cylinder->GetRadius(),rgb,(double)col.a/255.0,iResolution,transform_matrix);
+ break;
+ }
+ case CSPrimitives::CYLINDRICALSHELL:
+ {
+ CSPrimCylindricalShell* cylinder = prim->ToCylindricalShell();
+ const double* start = cylinder->GetAxisStartCoord()->GetCartesianCoords();
+ const double* stop = cylinder->GetAxisStopCoord()->GetCartesianCoords();
+ const double radius = cylinder->GetRadius();
+ const double shellWidth = cylinder->GetShellWidth();
+ vtkPrims->AddCylindricalShell( start, stop, radius-shellWidth/2, radius+shellWidth/2, rgb, (double)col.a/255.0, iResolution, transform_matrix );
+ break;
+ }
+ case CSPrimitives::POLYGON:
+ case CSPrimitives::LINPOLY:
+ case CSPrimitives::ROTPOLY:
+ {
+ CSPrimPolygon* poly = NULL;
+ if (prim->GetType()==CSPrimitives::POLYGON)
+ poly = prim->ToPolygon();
+ else if (prim->GetType()==CSPrimitives::LINPOLY)
+ poly = prim->ToLinPoly();
+ else if (prim->GetType()==CSPrimitives::ROTPOLY)
+ poly = prim->ToRotPoly();
+ int normDir = poly->GetNormDir();
+ double elev = poly->GetElevation();
+ int nP = (normDir+1)%3;
+ int nPP = (normDir+2)%3;
+ int nrPts = poly->GetQtyCoords();
+ double dCoords[3*nrPts];
+ for (int n=0;n<nrPts;++n)
+ {
+ dCoords[normDir*nrPts + n] = elev;
+ dCoords[nP*nrPts + n] = poly->GetCoord(2*n);
+ dCoords[nPP*nrPts + n] = poly->GetCoord(2*n+1);
+ }
+ double dVector[6] = {0,0,0,0,0,0};
+ if (prim->GetType()==CSPrimitives::POLYGON)
+ vtkPrims->AddClosedPoly(dCoords,nrPts,dVector,rgb,(double)col.a/255.0,transform_matrix);
+ if (prim->GetType()==CSPrimitives::LINPOLY)
+ {
+ dVector[normDir] = prim->ToLinPoly()->GetLength();
+ vtkPrims->AddClosedPoly(dCoords,nrPts,dVector,rgb,(double)col.a/255.0,transform_matrix);
+ }
+ if (prim->GetType()==CSPrimitives::ROTPOLY)
+ {
+ dVector[2*prim->ToRotPoly()->GetRotAxisDir()+1]=1;
+ double angles[2] = {prim->ToRotPoly()->GetAngle(0)*180/PI,prim->ToRotPoly()->GetAngle(1)*180/PI};
+ vtkPrims->AddRotationalPoly(dCoords,nrPts,dVector,angles,rgb,(double)col.a/255.0,32,transform_matrix);
+ }
+ break;
+ }
+ case CSPrimitives::POLYHEDRONREADER:
+ case CSPrimitives::POLYHEDRON:
+ {
+ CSPrimPolyhedron* polyhedron = dynamic_cast<CSPrimPolyhedron*>(prim);
+ vtkCellArray *poly = vtkCellArray::New();
+ vtkPolyData* polydata=vtkPolyData::New();
+ vtkPoints *points = vtkPoints::New();
+ for (unsigned int i=0; i<polyhedron->GetNumVertices();i++)
+ points->InsertPoint(i,polyhedron->GetVertex(i));
+ unsigned int numVertex;
+ int* vertices;
+ for (unsigned int i=0; i<polyhedron->GetNumFaces();++i)
+ {
+ if (polyhedron->GetFaceValid(i)==false)
+ continue;
+ vertices=polyhedron->GetFace(i,numVertex);
+ poly->InsertNextCell(numVertex);
+ for (unsigned int p=0; p<numVertex;++p)
+ poly->InsertCellPoint(vertices[p]);
+ }
+ polydata->SetPoints(points);
+ polydata->SetPolys(poly);
+ vtkPrims->AddPolyData(polydata,rgb,(double)col.a/255.0,transform_matrix);
+ poly->Delete();
+ points->Delete();
+ polydata->Delete();
+ break;
+ }
+// case CSPrimitives::POLYHEDRONREADER:
+// {
+// CSPrimPolyhedronReader* reader = prim->ToPolyhedronReader();
+// double center[]={0,0,0};
+// vtkPrims->AddSTLObject(reader->GetFilename().c_str(),center,rgb,(double)col.a/255.0,transform_matrix);
+// break;
+// }
+ case CSPrimitives::CURVE:
+ case CSPrimitives::WIRE:
+ {
+ CSPrimCurve* curve = NULL;
+ if (prim->GetType()==CSPrimitives::CURVE)
+ curve = prim->ToCurve();
+ else
+ curve = prim->ToWire();
+
+ unsigned int nrP = (unsigned int)curve->GetNumberOfPoints();
+ double dCoords[3*nrP];
+ double xyz[3];
+ bool isCurve = (prim->GetType()==CSPrimitives::CURVE);
+ for (unsigned int n=0;n<nrP;++n)
+ {
+ curve->GetPoint(n,xyz,CARTESIAN,isCurve);
+ dCoords[0*nrP+n] = xyz[0];
+ dCoords[1*nrP+n] = xyz[1];
+ dCoords[2*nrP+n] = xyz[2];
+ }
+ if (isCurve)
+ vtkPrims->AddLinePoly(dCoords,nrP,1,rgb,(double)col.a/255.0);
+ else
+ {
+ CSPrimWire* wire = prim->ToWire();
+ vtkPrims->AddTubePoly(dCoords,nrP,wire->GetWireRadius(),rgb,(double)col.a/255.0,8,transform_matrix);
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::RenderDiscMaterialModel()
+{
+ for (int i=0;i<m_DiscMatModels.size();++i)
+ {
+ delete m_DiscMatModels.at(i).vtk_model;
+ }
+ m_DiscMatModels.clear();
+
+ if (clCS==NULL) return;
+
+ for (unsigned int i=0;i<clCS->GetQtyProperties();++i)
+ {
+ CSProperties* prop = clCS->GetProperty(i);
+ CSPropDiscMaterial* dm_prop = prop->ToDiscMaterial();
+ if (dm_prop)
+ {
+ VTKDiscModel model;
+ VTKPrimitives* vtkPrims= new VTKPrimitives(ren);
+ model.vtk_model = vtkPrims;
+ model.uID = dm_prop->GetUniqueID();
+ m_DiscMatModels.append(model);
+ vtkPolyData* polydata = dm_prop->CreatePolyDataModel();
+
+ double rgb[3] = {1,1,1};
+ CSTransform* transform = new CSTransform(dm_prop->GetTransform());
+ transform->SetPreMultiply();
+ transform->Scale(dm_prop->GetScale());
+ double* transform_matrix = NULL;
+ if (transform)
+ transform_matrix = transform->GetMatrix();
+ vtkPrims->AddPolyData(polydata,rgb,1.0,transform_matrix);
+ delete transform;
+ }
+ }
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::SetParallelProjection(bool val, bool render)
+{
+ vtkCamera* cam = ren->GetActiveCamera();
+ cam->SetParallelProjection(val);
+
+ if (render)
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::Set2DInteractionStyle(bool val, bool render)
+{
+ if (val)
+ VTKWidget->GetRenderWindow()->GetInteractor()->SetInteractorStyle(vtkInteractorStyleRubberBand2DPlane::New());
+ else
+ VTKWidget->GetRenderWindow()->GetInteractor()->SetInteractorStyle(vtkInteractorStyleTrackballCamera::New());
+
+ if (render)
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+void QVTKStructure::SaveCamData()
+{
+ if (m_CamData==NULL)
+ m_CamData = new CamData;
+
+ vtkCamera *Camera = ren->GetActiveCamera();
+
+ Camera->GetPosition(m_CamData->pos);
+ Camera->GetFocalPoint(m_CamData->focalPoint);
+ Camera->GetViewUp(m_CamData->viewUp);
+ m_CamData->viewAngle = Camera->GetViewAngle();
+}
+
+void QVTKStructure::RestoreCamData(bool render)
+{
+ if (m_CamData==NULL)
+ return;
+
+ vtkCamera *Camera = ren->GetActiveCamera();
+ Camera->SetPosition( m_CamData->pos );
+ Camera->SetFocalPoint( m_CamData->focalPoint );
+ Camera->SetViewUp( m_CamData->viewUp );
+ Camera->SetViewAngle( m_CamData->viewAngle );
+ Camera->Modified();
+
+ if (render)
+ VTKWidget->GetRenderWindow()->GetInteractor()->Render();
+}
+
+
+void QVTKStructure::ExportView2Image()
+{
+ QString filename = QFileDialog::getSaveFileName(VTKWidget, tr("Choose file to save image"), QString(), tr("Images (*.png)"));
+
+ if (filename.isEmpty())
+ return;
+
+ vtkWindowToImageFilter* filter = vtkWindowToImageFilter::New();
+ filter->SetInput(VTKWidget->GetRenderWindow());
+
+ vtkPNGWriter* png_writer= vtkPNGWriter::New();
+ png_writer->SetInputConnection(filter->GetOutputPort());
+ //png_writer->SetQuality(100);
+ png_writer->SetFileName(filename.toStdString().c_str());
+ png_writer->Write();
+}
+
+void QVTKStructure::ExportProperty2PolyDataVTK(unsigned int uiID, QString filename, double scale)
+{
+ for (int i=0;i<LayerPrimitives.size();++i)
+ {
+ if (LayerPrimitives.at(i).uID==uiID)
+ {
+ if (LayerPrimitives.at(i).VTKProp!=NULL)
+ {
+ QString name = filename + ".vtp";
+ LayerPrimitives.at(i).VTKProp->WritePolyData2File(name.toStdString().c_str(), scale);
+ }
+ }
+ }
+
+ for (int i=0;i<m_DiscMatModels.size();++i)
+ {
+ if (m_DiscMatModels.at(i).uID==uiID)
+ {
+ if (m_DiscMatModels.at(i).vtk_model!=NULL)
+ {
+ QString name = filename + "_DiscMaterial" + ".vtp";
+ m_DiscMatModels.at(i).vtk_model->WritePolyData2File(name.toStdString().c_str(), scale);
+ }
+ }
+ }
+}
+
+void QVTKStructure::ExportProperty2STL(unsigned int uiID, QString filename, double scale)
+{
+ for (int i=0;i<LayerPrimitives.size();++i)
+ {
+ if (LayerPrimitives.at(i).uID==uiID)
+ {
+ if (LayerPrimitives.at(i).VTKProp!=NULL)
+ {
+ QString name = filename + ".stl";
+ LayerPrimitives.at(i).VTKProp->WritePolyData2STL(name.toStdString().c_str(), scale);
+ }
+ }
+ }
+}
+
+void QVTKStructure::ExportProperty2PLY(unsigned int uiID, QString filename, double scale)
+{
+ for (int i=0;i<LayerPrimitives.size();++i)
+ {
+ if (LayerPrimitives.at(i).uID==uiID)
+ {
+ if (LayerPrimitives.at(i).VTKProp!=NULL)
+ {
+ QString name = filename + ".ply";
+ LayerPrimitives.at(i).VTKProp->WritePolyData2PLY(name.toStdString().c_str(), scale);
+ }
+ }
+ }
+}
+
+void QVTKStructure::KeyPress(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
+{
+ UNUSED(caller);
+ UNUSED(eid);
+ UNUSED(calldata);
+
+ //vtkInteractorStyle * istyle = (vtkInteractorStyle *) caller;
+ vtkRenderWindowInteractor * iren = ((KeyPressData *)clientdata)->iren;
+ //vtkRenderWindow *renWin = iren->GetRenderWindow();
+ vtkActor **GridPlanes = ((KeyPressData *)clientdata)->GridPlanes;
+ //vtkRenderer *ren = ((KeyPressData *)clientdata)->ren;
+ int key;
+ key=iren->GetKeyCode();
+ // fprintf(stderr,"Event... EiD: %d Key: %d OpenGL?: %d\n",eid,key,renWin->SupportsOpenGL());
+ switch(key)
+ {
+ case 's':
+ {
+ for (int n=0;n<3;++n)
+ {
+ if (GridPlanes[n])
+ GridPlanes[n]->GetProperty()->SetRepresentationToWireframe();
+ }
+ iren->Render();
+ break;
+ }
+ }
+}
+
+void QVTKStructure::SetCallback(vtkRenderWindowInteractor *iren)
+{
+ ren->GetActiveCamera()->SetFocalPoint(0,0,0);
+ //Callback
+ KeyPressData *cbData = new KeyPressData;
+ cbData->GridPlanes=ActorGridPlane;
+ cbData->ren=ren;
+ cbData->iren=iren;
+
+ vtkCallbackCommand *cb = vtkCallbackCommand::New();
+ cb->SetCallback(KeyPress);
+ cb->SetClientData((void *)cbData);
+ iren->AddObserver(vtkCommand::KeyReleaseEvent, cb);
+ //VTKWidget->GetRenderWindow()->GetInteractor()->AddObserver(vtkCommand::KeyReleaseEvent, cb);
+
+ cb->Delete();
+ // free(cbData);
+}
diff --git a/QCSXCAD/QVTKStructure.h b/QCSXCAD/QVTKStructure.h
new file mode 100644
index 0000000..2809e8a
--- /dev/null
+++ b/QCSXCAD/QVTKStructure.h
@@ -0,0 +1,143 @@
+/*
+* Copyright (C) 2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _QVTKSTRUCTURE_H_
+#define _QVTKSTRUCTURE_H_
+
+#include <QtGui>
+
+class QVTKWidget;
+class vtkRenderWindow;
+class vtkRenderWindowInteractor;
+class vtkRenderer;
+class vtkAxesActor;
+class vtkActor;
+class ContinuousStructure;
+class VTKPrimitives;
+class vtkObject;
+class vtkRectilinearGrid;
+class vtkStructuredGrid;
+
+class QVTKStructure : public QObject
+{
+ Q_OBJECT
+public:
+ QVTKStructure();
+ virtual ~QVTKStructure();
+
+ QWidget* GetVTKWidget() {return (QWidget *)VTKWidget;};
+
+ void AddAxes();
+
+ void SetGeometry(ContinuousStructure *CS);
+ void clear();
+
+ void SetBackgroundColor(int r, int g, int b);
+
+ //! Set the update mode to false if this widget should not be rendered e.g. because it is hidden
+ void SetUpdateMode(bool mode) {AllowUpdate=mode;}
+
+ //Callback
+ void SetCallback(vtkRenderWindowInteractor *iren);
+
+public slots:
+ void SetGridOpacity(int val);
+ void ResetView();
+ void setXY();
+ void setYZ();
+ void setZX();
+ void SetPropOpacity(unsigned int uiID, int val);
+ void RenderGrid();
+ void RenderGridX(int plane_pos);
+ void RenderGridY(int plane_pos);
+ void RenderGridZ(int plane_pos);
+ void RenderGeometry();
+
+ //! Enable/Disable 3D parallel projection
+ void SetParallelProjection(bool val, bool render=true);
+
+ //! Enable/Disable 2D interaction style
+ void Set2DInteractionStyle(bool val, bool render=true);
+
+ void SaveCamData();
+ void RestoreCamData(bool render);
+
+ void RenderDiscMaterialModel();
+
+ //! Export the current view to an image file (currently only png)
+ void ExportView2Image();
+
+ void ExportProperty2PolyDataVTK(unsigned int uiID, QString filename, double scale = 1.0);
+ void ExportProperty2STL(unsigned int uiID, QString filename, double scale = 1.0);
+ void ExportProperty2PLY(unsigned int uiID, QString filename, double scale = 1.0);
+
+protected slots:
+ void RenderGridDir(int dir, unsigned int plane_pos);
+
+protected:
+ typedef struct
+ {
+ VTKPrimitives* VTKProp;
+ unsigned int uID;
+ } VTKLayerStruct;
+
+ QVTKWidget *VTKWidget;
+
+ //set to false if this widget is hidden
+ bool AllowUpdate;
+
+ vtkRenderer *ren;
+
+ vtkAxesActor* Axes;
+
+ ContinuousStructure* clCS;
+ QVector<VTKLayerStruct> LayerPrimitives;
+
+ vtkRectilinearGrid *m_Rect_Grid;
+ vtkStructuredGrid *m_Struct_Grid;
+ vtkActor* ActorGridPlane[3];
+ int GridOpacity; //remember the grid opacity
+
+ int iResolution;
+
+ typedef struct
+ {
+ VTKPrimitives* vtk_model;
+ unsigned int uID;
+ } VTKDiscModel;
+ QVector<VTKDiscModel> m_DiscMatModels;
+
+ typedef struct
+ {
+ double pos[3];
+ double focalPoint[3];
+ double viewUp[3];
+ double viewAngle;
+ } CamData;
+ CamData* m_CamData;
+
+ struct KeyPressData
+ {
+ vtkActor **GridPlanes;
+ vtkRenderer *ren;
+ vtkRenderWindowInteractor * iren;
+ };
+
+ static void KeyPress(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata);
+};
+
+#endif //_QVTKSTRUCTURE_H_
diff --git a/QCSXCAD/README b/QCSXCAD/README
new file mode 100644
index 0000000..50a82cd
--- /dev/null
+++ b/QCSXCAD/README
@@ -0,0 +1,7 @@
+*
+* QCSXCAD - Qt-GUI for CSXCAD
+*
+
+QCSXCAD the Qt-GUI for CSXCAD, a C++ library to describe geometrical objects and their physical or non-physical properties.
+QCSXCAD is licensed under the terms of the LGPLv3.
+
diff --git a/QCSXCAD/VTKPrimitives.cpp b/QCSXCAD/VTKPrimitives.cpp
new file mode 100644
index 0000000..5610a9e
--- /dev/null
+++ b/QCSXCAD/VTKPrimitives.cpp
@@ -0,0 +1,1019 @@
+/*
+* Copyright (C) 2005,2006,2007,2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "VTKPrimitives.h"
+#include "vtkRenderer.h"
+#include "vtkActorCollection.h"
+
+#include "vtkPolyDataMapper.h"
+#include "vtkDoubleArray.h"
+#include "vtkLODActor.h"
+#include "vtkActor.h"
+#include "vtkProperty.h"
+#include "vtkCamera.h"
+#include "vtkCubeSource.h"
+#include "vtkPlaneSource.h"
+#include "vtkCylinderSource.h"
+#include "vtkLineSource.h"
+#include "vtkSphereSource.h"
+#include "vtkPoints.h"
+#include "vtkCellArray.h"
+#include "vtkRotationalExtrusionFilter.h"
+#include "vtkLinearExtrusionFilter.h"
+#include "vtkArrowSource.h"
+#include "vtkSTLReader.h"
+#include "vtkVectorText.h"
+#include "vtkFollower.h"
+#include "vtkTriangleFilter.h"
+#include "vtkFloatArray.h"
+#include "vtkPointData.h"
+#include "vtkTransform.h"
+#include "vtkTransformPolyDataFilter.h"
+#include "vtkCollectionIterator.h"
+#include "vtkConeSource.h"
+#include "vtkTubeFilter.h"
+#include "vtkAppendPolyData.h"
+#include "vtkXMLPolyDataWriter.h"
+#include "vtkSTLWriter.h"
+#include "vtkDiskSource.h"
+#include "vtkPLYWriter.h"
+
+#if (VTK_MAJOR_VERSION==5 && VTK_MINOR_VERSION>=10) || (VTK_MAJOR_VERSION>=6)
+#include "vtkBooleanOperationPolyDataFilter.h"
+#endif
+
+VTKPrimitives::VTKPrimitives(vtkRenderer *Renderer)
+{
+ ren = Renderer;
+
+ ActorColl = vtkActorCollection::New();
+
+ m_PolyDataCollection = vtkAppendPolyData::New();
+ m_ArcDelta = 3.0/180.0*PI; // default of 5° resolution for representing angles
+}
+
+VTKPrimitives::~VTKPrimitives()
+{
+ ActorColl->InitTraversal();
+ vtkActor* act=NULL;
+ while ((act=ActorColl->GetNextActor()))
+ {
+ ren->RemoveActor(act);
+ act->Delete();
+ }
+ ActorColl->Delete();
+ ActorColl=NULL;
+
+ if (m_PolyDataCollection)
+ m_PolyDataCollection->Delete();
+ m_PolyDataCollection=NULL;
+}
+
+VTKPrimitives::VTKPrimitives()
+{
+}
+
+void VTKPrimitives::AddCube(const double *start, const double *stop, double *dRGB, double dOpacity, const double* tf_matrix)
+{
+ double coords[6] = {start[0],stop[0],start[1],stop[1],start[2],stop[2]};
+ double help;
+ int dim=0;
+ //swap start stop if start>stop
+ for (int n=0;n<3;++n)
+ {
+ if (coords[2*n]>coords[2*n+1])
+ {
+ help=coords[2*n+1];
+ coords[2*n+1]=coords[2*n];
+ coords[2*n]=help;
+ }
+ if (coords[2*n]!=coords[2*n+1])
+ ++dim;
+ }
+ if (dim==0)
+ {
+ cerr << "VTKPrimitives::AddCube: Warning, can't draw a Point Box... skipping" << endl;
+ return;
+ }
+ if (dim==1)
+ return AddLinePoly(coords,2,1,dRGB,dOpacity);
+ AddCube(coords,dRGB,dOpacity,tf_matrix);
+}
+
+void VTKPrimitives::AddCube(double *dCoords, double *dRGB, double dOpacity, const double* tf_matrix)
+{
+ //create a simple cartesian cube...
+ vtkCubeSource *Source = vtkCubeSource::New();
+ Source->SetBounds(dCoords);
+
+ AddPolyData(Source->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+ Source->Delete();
+}
+
+void VTKPrimitives::AddCylindricalCube(const double *start, const double *stop, double *dRGB, double dOpacity, const double* tf_matrix)
+{
+ double coords[6] = {start[0],stop[0],start[1],stop[1],start[2],stop[2]};
+ double help;
+ //swap start stop if start>stop
+ for (int n=0;n<3;++n)
+ {
+ if (coords[2*n]>coords[2*n+1])
+ {
+ help=coords[2*n+1];
+ coords[2*n+1]=coords[2*n];
+ coords[2*n]=help;
+ }
+ }
+ AddCylindricalCube(coords,dRGB,dOpacity,tf_matrix);
+}
+
+void VTKPrimitives::AddCylindricalCube(double *dCoords, double *dRGB, double dOpacity, const double* tf_matrix)
+{
+ vtkPolyDataAlgorithm* PDSource = NULL;
+ vtkPolyDataAlgorithm* PDFilter = NULL;
+
+ if ( (dCoords[2]!=dCoords[3]) )
+ {
+ if ((dCoords[0]!=dCoords[1]) && ((dCoords[4]!=dCoords[5]))) //3D object
+ {
+ double dO[3] = {dCoords[0],dCoords[2],dCoords[4]};
+ double dP1[3] = {dCoords[0],dCoords[2],dCoords[5]};
+ double dP2[3] = {dCoords[1],dCoords[2],dCoords[4]};
+ double out[3];
+ vtkPlaneSource *Source = vtkPlaneSource::New();
+ Source->SetOrigin(TransformCylindricalCoords(dO,out));
+ Source->SetPoint1(TransformCylindricalCoords(dP1,out));
+ Source->SetPoint2(TransformCylindricalCoords(dP2,out));
+ PDSource = Source;
+ }
+ else if (dCoords[4]!=dCoords[5]) // alpha-z plane
+ {
+ double dP1[3] = {dCoords[0],dCoords[2],dCoords[4]};
+ double dP2[3] = {dCoords[0],dCoords[2],dCoords[5]};
+ double out[3];
+
+ vtkLineSource *Source = vtkLineSource::New();
+ Source->SetPoint1(TransformCylindricalCoords(dP1,out));
+ Source->SetPoint2(TransformCylindricalCoords(dP2,out));
+ PDSource = Source;
+ }
+ else if (dCoords[0]!=dCoords[1]) // alpha-r plane
+ {
+ double dP1[3] = {dCoords[0],dCoords[2],dCoords[4]};
+ double dP2[3] = {dCoords[1],dCoords[2],dCoords[4]};
+ double out[3];
+
+ vtkLineSource *Source = vtkLineSource::New();
+ Source->SetPoint1(TransformCylindricalCoords(dP1,out));
+ Source->SetPoint2(TransformCylindricalCoords(dP2,out));
+ PDSource = Source;
+ }
+ else //line in a-direction
+ {
+ double out[6];
+ return AddLinePoly(TransformCylindricalCoords(dCoords,out,2),2,1,dRGB,dOpacity);
+ }
+
+ if (PDSource==NULL)
+ return;
+
+ vtkRotationalExtrusionFilter *extrude = vtkRotationalExtrusionFilter::New();
+#if VTK_MAJOR_VERSION>=6
+ extrude->SetInputConnection(PDSource->GetOutputPort());
+#else
+ extrude->SetInput(PDSource->GetOutput());
+#endif
+ int nrSteps = ceil(fabs(dCoords[3]-dCoords[2])/m_ArcDelta);
+ extrude->SetResolution(nrSteps);
+ extrude->SetAngle( (dCoords[3]-dCoords[2])*180/PI );
+ PDFilter = extrude;
+ }
+ else //rz-plane or line
+ {
+ if (dCoords[0]==dCoords[1]) //line in z-direction
+ {
+ double out[6];
+ return AddLinePoly(TransformCylindricalCoords(dCoords,out,2),2,1,dRGB,dOpacity);
+ }
+ if (dCoords[4]==dCoords[5]) //line in r-direction
+ {
+ double out[6];
+ return AddLinePoly(TransformCylindricalCoords(dCoords,out,2),2,1,dRGB,dOpacity);
+ }
+
+ //rz-plane
+ double dO[3] = {dCoords[0],dCoords[2],dCoords[4]};
+ double dP1[3] = {dCoords[0],dCoords[2],dCoords[5]};
+ double dP2[3] = {dCoords[1],dCoords[2],dCoords[4]};
+ double out[3];
+ vtkPlaneSource *Source = vtkPlaneSource::New();
+ Source->SetOrigin(TransformCylindricalCoords(dO,out));
+ Source->SetPoint1(TransformCylindricalCoords(dP1,out));
+ Source->SetPoint2(TransformCylindricalCoords(dP2,out));
+ PDFilter = Source;
+ }
+
+ if (PDFilter==NULL)
+ return;
+
+ AddPolyData(PDFilter->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+ if (PDSource)
+ PDSource->Delete();
+ PDFilter->Delete();
+}
+
+void VTKPrimitives::AddPlane(double *dOrigin, double* dP1, double* dP2, double *dRGB, double dOpacity, const double* tf_matrix)
+{
+ double out[3];
+ vtkPlaneSource *Source = vtkPlaneSource::New();
+ Source->SetOrigin(TransformCylindricalCoords(dOrigin,out));
+ Source->SetPoint1(TransformCylindricalCoords(dP1,out));
+ Source->SetPoint2(TransformCylindricalCoords(dP2,out));
+
+ AddPolyData(Source->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+ Source->Delete();
+}
+
+void VTKPrimitives::AddDisc(double *dCoords, unsigned int uiQtyCoords, double *dRGB, double dOpacity, const double* tf_matrix)
+{
+ unsigned int i=0,j=0;//,h=0;//,k=0;
+ vtkPoints *points = vtkPoints::New();
+ vtkCellArray *poly = vtkCellArray::New();
+ vtkPolyData *profile = vtkPolyData::New();
+ for (i=0; i<uiQtyCoords;i=i+2)
+ {
+ points->InsertPoint(j++,dCoords[i],dCoords[uiQtyCoords+i],dCoords[2*uiQtyCoords+i]);//0
+ points->InsertPoint(j++,dCoords[i+1],dCoords[uiQtyCoords+i],dCoords[2*uiQtyCoords+i]);//1
+ points->InsertPoint(j++,dCoords[i+1],dCoords[uiQtyCoords+i+1],dCoords[2*uiQtyCoords+i]);//2
+ points->InsertPoint(j++,dCoords[i],dCoords[uiQtyCoords+i+1],dCoords[2*uiQtyCoords+i]);//3
+ points->InsertPoint(j++,dCoords[i],dCoords[uiQtyCoords+i],dCoords[2*uiQtyCoords+i+1]);//4
+ points->InsertPoint(j++,dCoords[i+1],dCoords[uiQtyCoords+i],dCoords[2*uiQtyCoords+i+1]);//5
+ points->InsertPoint(j++,dCoords[i+1],dCoords[uiQtyCoords+i+1],dCoords[2*uiQtyCoords+i+1]);//6
+ points->InsertPoint(j++,dCoords[i],dCoords[uiQtyCoords+i+1],dCoords[2*uiQtyCoords+i+1]);//7
+ poly->InsertNextCell(4);poly->InsertCellPoint(0+i*4);poly->InsertCellPoint(1+i*4);poly->InsertCellPoint(2+i*4);poly->InsertCellPoint(3+i*4);
+ poly->InsertNextCell(4);poly->InsertCellPoint(4+i*4);poly->InsertCellPoint(5+i*4);poly->InsertCellPoint(6+i*4);poly->InsertCellPoint(7+i*4);
+ poly->InsertNextCell(4);poly->InsertCellPoint(0+i*4);poly->InsertCellPoint(1+i*4);poly->InsertCellPoint(5+i*4);poly->InsertCellPoint(4+i*4);
+ poly->InsertNextCell(4);poly->InsertCellPoint(1+i*4);poly->InsertCellPoint(2+i*4);poly->InsertCellPoint(6+i*4);poly->InsertCellPoint(5+i*4);
+ poly->InsertNextCell(4);poly->InsertCellPoint(2+i*4);poly->InsertCellPoint(3+i*4);poly->InsertCellPoint(7+i*4);poly->InsertCellPoint(6+i*4);
+ poly->InsertNextCell(4);poly->InsertCellPoint(3+i*4);poly->InsertCellPoint(0+i*4);poly->InsertCellPoint(4+i*4);poly->InsertCellPoint(7+i*4);
+ //for (h=j-8;h<j;h++) scalars->InsertTuple1(h,h%8); // not in use jet
+ //fprintf(stderr,".");
+ }
+ profile->SetPoints(points);
+ profile->SetPolys(poly);
+
+ AddPolyData(profile, dRGB, dOpacity, tf_matrix);
+ points->Delete();
+ poly->Delete();
+ profile->Delete();
+}
+
+void VTKPrimitives::AddClosedPoly(double *dCoords, unsigned int uiQtyCoords, double *dExtrusionVector, double *dRGB, double dOpacity, const double* tf_matrix)
+{ //complete
+ unsigned int i=0;
+ vtkPoints *points = vtkPoints::New();
+ vtkCellArray *poly = vtkCellArray::New();
+ vtkPolyData *profile = vtkPolyData::New();
+ vtkLinearExtrusionFilter *extrude = vtkLinearExtrusionFilter::New();
+ for (i=0; i<uiQtyCoords;i++)
+ points->InsertPoint(i,dCoords[i],dCoords[uiQtyCoords+i],dCoords[2*uiQtyCoords+i]);
+ poly->InsertNextCell(uiQtyCoords+1);
+ for (i=0; i<uiQtyCoords ;i++) poly->InsertCellPoint(i);
+ poly->InsertCellPoint(0);
+ profile->SetPoints(points);
+ profile->SetPolys(poly);
+ vtkTriangleFilter *tf = vtkTriangleFilter::New();
+#if VTK_MAJOR_VERSION>=6
+ tf->SetInputData(profile);
+#else
+ tf->SetInput(profile);
+#endif
+ extrude->SetInputConnection(tf->GetOutputPort());
+ extrude->SetExtrusionTypeToVectorExtrusion();
+ extrude->SetVector(dExtrusionVector);
+ extrude->CappingOn();
+
+ AddPolyData(extrude->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+
+ points->Delete();
+ poly->Delete();
+ profile->Delete();
+ tf->Delete();
+ extrude->Delete();
+}
+
+void VTKPrimitives::AddLinePoly(const double *dCoords, unsigned int uiQtyCoords, unsigned int LineWidth, double *dRGB, double dOpacity, const double* tf_matrix)
+{ //complete
+ unsigned int i=0;
+ vtkPoints *points = vtkPoints::New();
+ vtkCellArray *poly = vtkCellArray::New();
+ vtkPolyData *profile = vtkPolyData::New();
+ for (i=0; i<uiQtyCoords;i++) points->InsertPoint(i,dCoords[i],dCoords[uiQtyCoords+i],dCoords[2*uiQtyCoords+i]);
+ for (i=1; i<uiQtyCoords;i++)
+ {
+ poly->InsertNextCell(2);
+ poly->InsertCellPoint(i-1);
+ poly->InsertCellPoint(i);
+ }
+
+ profile->SetPoints(points);
+ profile->SetLines(poly);
+
+ vtkActor* actor = AddPolyData(profile, dRGB, dOpacity, tf_matrix);
+ actor->GetProperty()->SetLineWidth(LineWidth);
+
+ points->Delete();
+ poly->Delete();
+ profile->Delete();
+}
+
+void VTKPrimitives::AddTubePoly(const double *dCoords, unsigned int uiQtyCoords, double TubeRadius, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix)
+{ //complete
+ unsigned int i=0;
+ vtkPoints *points = vtkPoints::New();
+ vtkCellArray *poly = vtkCellArray::New();
+ vtkPolyData *profile = vtkPolyData::New();
+ for (i=0; i<uiQtyCoords;i++) points->InsertPoint(i,dCoords[i],dCoords[uiQtyCoords+i],dCoords[2*uiQtyCoords+i]);
+ for (i=1; i<uiQtyCoords;i++)
+ {
+ poly->InsertNextCell(2);
+ poly->InsertCellPoint(i-1);
+ poly->InsertCellPoint(i);
+ }
+
+ profile->SetPoints(points);
+ profile->SetLines(poly);
+
+ vtkTubeFilter* m_profileTubes = vtkTubeFilter::New();
+ m_profileTubes->SetNumberOfSides(iResolution);
+#if VTK_MAJOR_VERSION>=6
+ m_profileTubes->SetInputData(profile);
+#else
+ m_profileTubes->SetInput(profile);
+#endif
+ m_profileTubes->SetRadius(TubeRadius);
+
+ AddPolyData(m_profileTubes->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+
+ points->Delete();
+ poly->Delete();
+ profile->Delete();
+ m_profileTubes->Delete();
+}
+
+void VTKPrimitives::AddCylinder2(const double *dAxisStart, const double* dAxisStop, float fRadius, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix)
+{
+ double direction[3] = {dAxisStop[0]-dAxisStart[0],dAxisStop[1]-dAxisStart[1],dAxisStop[2]-dAxisStart[2]};
+ AddCylinder(dAxisStart,direction,fRadius,dRGB,dOpacity,iResolution,tf_matrix);
+}
+
+void VTKPrimitives::AddCylinder(const double *dCenter, const double *dExtrusionVector, float fRadius, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix)
+{
+ double alpha=0,beta=0;
+ double length=sqrt( dExtrusionVector[0]*dExtrusionVector[0]+dExtrusionVector[1]*dExtrusionVector[1]+dExtrusionVector[2]*dExtrusionVector[2] ) ;
+ //if (length==0) { fprintf(stderr," Error Cylinder Extrusion Vector ist Zero.. Abort..."); exit(1); }
+ vtkCylinderSource *Source = vtkCylinderSource::New();
+ vtkTransform *transform = vtkTransform::New();
+ vtkTransformPolyDataFilter *transformFilter = vtkTransformPolyDataFilter::New();
+ Source->SetResolution(iResolution);
+ Source->SetRadius(fRadius);
+ Source->SetHeight(length);
+
+ alpha=VectorAngel(dExtrusionVector[0],sqrt(dExtrusionVector[1]*dExtrusionVector[1]+dExtrusionVector[2]*dExtrusionVector[2]),0,0,1,0);
+ beta=VectorAngel(0,dExtrusionVector[1],dExtrusionVector[2],0,1,0);
+ // cout << alpha << " " << beta << endl; //debuging
+ if (dExtrusionVector[0]>0) alpha=-alpha;
+ if (dExtrusionVector[2]<0) beta=-beta;
+ transform->Translate(dExtrusionVector[0]/2+dCenter[0],dExtrusionVector[1]/2+dCenter[1],dExtrusionVector[2]/2+dCenter[2]);
+ transform->RotateWXYZ(beta,1,0,0);
+ transform->RotateWXYZ(alpha,0,0,1);
+
+ transform->PostMultiply();
+
+#if VTK_MAJOR_VERSION>=6
+ transformFilter->SetInputConnection(Source->GetOutputPort());
+#else
+ transformFilter->SetInput(Source->GetOutput());
+#endif
+ transformFilter->SetTransform(transform);
+
+ AddPolyData(transformFilter->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+
+ Source->Delete();
+ transform->Delete();
+ transformFilter->Delete();
+}
+
+void VTKPrimitives::AddCylindricalShell(const double *dAxisStart, const double* dAxisStop, double r_i, double r_o, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix)
+{
+ const double dExtrusionVector[3] = {dAxisStop[0]-dAxisStart[0], dAxisStop[1]-dAxisStart[1], dAxisStop[2]-dAxisStart[2]};
+ double length = sqrt( dExtrusionVector[0]*dExtrusionVector[0] + dExtrusionVector[1]*dExtrusionVector[1] + dExtrusionVector[2]*dExtrusionVector[2] ) ;
+
+ // create a disk in xy plane
+ vtkDiskSource *diskSource = vtkDiskSource::New();
+ diskSource->SetInnerRadius( r_i );
+ diskSource->SetOuterRadius( r_o );
+ diskSource->SetCircumferentialResolution(iResolution);
+
+ // extrude in +z
+ vtkLinearExtrusionFilter *linearExtrusionFilter = vtkLinearExtrusionFilter::New();
+#if VTK_MAJOR_VERSION>=6
+ linearExtrusionFilter->SetInputConnection( diskSource->GetOutputPort() );
+#else
+ linearExtrusionFilter->SetInput( diskSource->GetOutput() );
+#endif
+ linearExtrusionFilter->SetExtrusionTypeToNormalExtrusion();
+ linearExtrusionFilter->SetVector(0,0,length);
+
+ // create transform to correctly orient and move the cylinder shell
+ vtkTransform *transform = vtkTransform::New();
+ transform->PostMultiply();
+ double phi = atan2( dExtrusionVector[1], dExtrusionVector[0] );
+ double theta = acos( dExtrusionVector[2] / length );
+ transform->RotateY( theta / M_PI * 180 );
+ transform->RotateZ( phi / M_PI * 180 );
+ transform->Translate( dAxisStart );
+ if (tf_matrix)
+ transform->Concatenate( tf_matrix );
+
+ vtkTransformPolyDataFilter *transformFilter = vtkTransformPolyDataFilter::New();
+ transformFilter->SetInputConnection( linearExtrusionFilter->GetOutputPort() );
+ transformFilter->SetTransform( transform );
+
+ vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
+ mapper->SetInputConnection( transformFilter->GetOutputPort() );
+ mapper->ScalarVisibilityOff();
+ vtkActor *actor = vtkLODActor::New();
+ actor->SetMapper( mapper );
+
+ m_PolyDataCollection->AddInputConnection( transformFilter->GetOutputPort());
+ actor->GetProperty()->SetColor(dRGB);
+ actor->GetProperty()->SetOpacity(dOpacity);
+
+ ActorColl->AddItem(actor);
+ ren->AddActor(actor);
+}
+
+void VTKPrimitives::AddSphere(const double *dCenter, double fRadius, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix)
+{//complete
+ vtkSphereSource *Source = vtkSphereSource::New();
+ double center[3]={dCenter[0],dCenter[1],dCenter[2]};
+ Source->SetCenter(center);
+ Source->SetRadius(fRadius);
+ Source->SetPhiResolution(iResolution);
+ Source->SetThetaResolution(iResolution);
+
+ AddPolyData(Source->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+
+ Source->Delete();
+}
+
+void VTKPrimitives::AddSphericalShell(const double *dCenter, double r_i, double r_o, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix)
+{//complete
+#if (VTK_MAJOR_VERSION==5 && VTK_MINOR_VERSION>=10) || (VTK_MAJOR_VERSION>=6)
+ vtkSphereSource *Source_o = vtkSphereSource::New();
+ double center[3]={dCenter[0],dCenter[1],dCenter[2]};
+ Source_o->SetCenter(center);
+ Source_o->SetRadius(r_o);
+ Source_o->SetPhiResolution(iResolution);
+ Source_o->SetThetaResolution(iResolution);
+
+ vtkSphereSource *Source_i = vtkSphereSource::New();
+ Source_i->SetCenter(center);
+ Source_i->SetRadius(r_i);
+ Source_i->SetPhiResolution(iResolution);
+ Source_i->SetThetaResolution(iResolution);
+
+ vtkBooleanOperationPolyDataFilter* boolFilter = vtkBooleanOperationPolyDataFilter::New();
+ boolFilter->SetOperationToDifference();
+ boolFilter->SetInputConnection(0, Source_o->GetOutputPort());
+ boolFilter->SetInputConnection(1, Source_i->GetOutputPort());
+
+ //todo, we should remove the unnecessary scalar data produced by the filter...
+ AddPolyData(boolFilter->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+
+ boolFilter->Delete();
+ Source_o->Delete();
+ Source_i->Delete();
+#else
+ cerr << "VTKPrimitives::AddSphericalShell: Error, spherical shell not supported by this vkt version, you require vtk 5.10 or higher." << endl;
+#endif
+}
+
+
+void VTKPrimitives::AddArrow(double *dStart, double *dEnd, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix)
+{
+ double alpha=0,beta=0;
+ double dvector[3]={dEnd[0]-dStart[0],dEnd[1]-dStart[1],dEnd[2]-dStart[2]};
+ double length=sqrt( dvector[0]*dvector[0]+dvector[1]*dvector[1]+dvector[2]*dvector[2] ) ;
+ if (length==0) { fprintf(stderr," Error Arrow Length ist Zero.. Abort..."); exit(1); }
+ vtkArrowSource *Source = vtkArrowSource::New();
+ vtkTransform *transform = vtkTransform::New();
+ vtkTransformPolyDataFilter *transformFilter = vtkTransformPolyDataFilter::New();
+ Source->SetTipResolution(iResolution);
+ Source->SetShaftResolution(iResolution);
+ Source->SetTipLength(0.15);
+ Source->SetTipRadius(0.03);
+ Source->SetShaftRadius(0.01);
+
+ alpha=VectorAngel(dvector[0],sqrt(dvector[1]*dvector[1]+dvector[2]*dvector[2]),0,0,1,0);
+ beta=VectorAngel(0,dvector[1],dvector[2],0,1,0);
+ if (dvector[0]>0) alpha=-alpha;
+ if (dvector[2]<0) beta=-beta;
+ transform->RotateWXYZ(beta,1,0,0);
+ transform->RotateWXYZ(alpha,0,0,1);
+ transform->RotateWXYZ(90,0,0,1);
+
+ transform->PostMultiply();
+
+#if VTK_MAJOR_VERSION>=6
+ transformFilter->SetInputConnection(Source->GetOutputPort());
+#else
+ transformFilter->SetInput(Source->GetOutput());
+#endif
+ transformFilter->SetTransform(transform);
+
+ AddPolyData(transformFilter->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+
+ Source->Delete();
+ transform->Delete();
+ transformFilter->Delete();
+}
+
+void VTKPrimitives::AddLabel(char *cText, double *dCoords, double *dRGB, double dOpacity, double dscale, const double* tf_matrix)
+{
+ vtkVectorText *text = vtkVectorText::New();
+ vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
+ vtkFollower *Actor = vtkFollower::New();
+ text->SetText(cText);
+
+ vtkTransformPolyDataFilter* filter = vtkTransformPolyDataFilter::New();
+ vtkTransform* vtrans = vtkTransform::New();
+#if VTK_MAJOR_VERSION>=6
+ filter->SetInputConnection(text->GetOutputPort());
+#else
+ filter->SetInput(text->GetOutput());
+#endif
+
+ if (tf_matrix)
+ vtrans->SetMatrix(tf_matrix);
+ filter->SetTransform(vtrans);
+
+ m_PolyDataCollection->AddInputConnection(filter->GetOutputPort());
+ Mapper->SetInputConnection(filter->GetOutputPort());
+ Actor->SetMapper(Mapper);
+ Actor->SetScale(dscale);
+ Actor->SetCamera(ren->GetActiveCamera());
+ Actor->GetProperty()->SetColor(dRGB);
+ Actor->GetProperty()->SetOpacity(dOpacity);
+ Actor->SetPosition(dCoords);
+
+ ren->AddActor(Actor);
+ ActorColl->AddItem(Actor);
+
+ Mapper->Delete();
+ text->Delete();
+ filter->Delete();
+ vtrans->Delete();
+}
+
+void VTKPrimitives::AddRotationalPoly(const double *dCoords, unsigned int uiQtyCoords, const double *fRotAxis, double StartStopAngle[2], double *dRGB, double dOpacity, int iResolution, const double* tf_matrix)
+{
+ unsigned int i=0;
+ double start[3]={0,0,0},vector[3]={0,0,0};
+
+ vtkPoints *points = vtkPoints::New();
+ vtkCellArray *poly = vtkCellArray::New();
+ vtkPolyData *profile = vtkPolyData::New();
+ vtkRotationalExtrusionFilter *extrude = vtkRotationalExtrusionFilter::New();
+ vtkTransform *transform = vtkTransform::New();
+ vtkTransform *InvTransform = vtkTransform::New();
+ vtkTransformPolyDataFilter *transformFilter = vtkTransformPolyDataFilter::New();
+ vtkTransformPolyDataFilter *InvTransformFilter = vtkTransformPolyDataFilter::New();
+
+ vector[0]=fRotAxis[1]-fRotAxis[0];
+ vector[1]=fRotAxis[3]-fRotAxis[2];
+ vector[2]=fRotAxis[5]-fRotAxis[4];
+ double vec_len = sqrt(vector[0]*vector[0]+vector[1]*vector[1]+vector[2]*vector[2]);
+ double vec_unit[3]={vector[0]/vec_len,vector[1]/vec_len,vector[2]/vec_len};
+ start[0]=fRotAxis[0];
+ start[1]=fRotAxis[2];
+ start[2]=fRotAxis[4];
+
+ double d = sqrt(vec_unit[1]*vec_unit[1]+vec_unit[2]*vec_unit[2]);
+ double alpha = atan2(vec_unit[1],vec_unit[2])/acos(-1)*180;
+ double beta = atan2(-vec_unit[0],d)/acos(-1)*180;
+
+ for (i=0; i<uiQtyCoords;i++)
+ points->InsertPoint(i,dCoords[i],dCoords[uiQtyCoords+i],dCoords[2*uiQtyCoords+i]);
+ poly->InsertNextCell(uiQtyCoords+1);
+ for (i=0; i<uiQtyCoords ;i++) poly->InsertCellPoint(i);
+ poly->InsertCellPoint(0);
+ profile->SetPoints(points);
+ profile->SetPolys(poly);
+ vtkTriangleFilter *tf = vtkTriangleFilter::New();
+#if VTK_MAJOR_VERSION>=6
+ tf->SetInputData(profile);
+#else
+ tf->SetInput(profile);
+#endif
+
+ InvTransform->Translate(-start[0],-start[1],-start[2]);
+ InvTransform->RotateX(alpha);
+ InvTransform->RotateY(beta);
+
+ InvTransformFilter->SetInputConnection(tf->GetOutputPort());
+ InvTransformFilter->SetTransform(InvTransform);
+
+ extrude->SetInputConnection(InvTransformFilter->GetOutputPort());
+ extrude->SetResolution(iResolution);
+ extrude->SetAngle(StartStopAngle[1]-StartStopAngle[0]);
+
+ transform->RotateZ(-StartStopAngle[0]);
+
+ transform->Translate(-start[0],-start[1],-start[2]);
+ transform->RotateX(alpha);
+ transform->RotateY(beta);
+ transform->Inverse();
+
+ transform->PostMultiply();
+
+ transformFilter->SetInputConnection(extrude->GetOutputPort());
+ transformFilter->SetTransform(transform);
+
+ AddPolyData(transformFilter->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+
+ points->Delete();
+ poly->Delete();
+ profile->Delete();
+ extrude->Delete();
+ transform->Delete();
+ transformFilter->Delete();
+ InvTransform->Delete();
+ InvTransformFilter->Delete();
+}
+
+void VTKPrimitives::AddRotationalSolid(const double *dPoint, double fRadius, const double *fRotAxis, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix)
+{
+ vtkPoints *points = vtkPoints::New();
+ vtkCellArray *poly = vtkCellArray::New();
+ vtkPolyData *profile = vtkPolyData::New();
+ vtkRotationalExtrusionFilter *extrude = vtkRotationalExtrusionFilter::New();
+ vtkTransform *transform = vtkTransform::New();
+ vtkTransformPolyDataFilter *transformFilter = vtkTransformPolyDataFilter::New();
+
+ double vector[3]={0,0,0},start[3]={0,0,0},Footpoint[3]={0,0,0};
+ vector[0]=fRotAxis[1]-fRotAxis[0];
+ vector[1]=fRotAxis[3]-fRotAxis[2];
+ vector[2]=fRotAxis[5]-fRotAxis[4];
+ start[0]=fRotAxis[0];
+ start[1]=fRotAxis[2];
+ start[2]=fRotAxis[4];
+ double dSolidRadius=DistancePointLine(dPoint,start,vector,Footpoint);
+
+ poly->InsertNextCell(iResolution+1);
+ for (int i=0; i<iResolution; i++)
+ {
+ points->InsertPoint(i,dSolidRadius+fRadius*cos(i*2*PI/iResolution),0,fRadius*sin(i*2*PI/iResolution));
+ poly->InsertCellPoint(i);
+ }
+ poly->InsertCellPoint(0);
+ profile->SetPoints(points);
+ profile->SetLines(poly);
+
+#if VTK_MAJOR_VERSION>=6
+ extrude->SetInputData(profile);
+#else
+ extrude->SetInput(profile);
+#endif
+ extrude->SetResolution(iResolution);
+ extrude->SetAngle(360.0);
+
+ double alpha=VectorAngel(vector[0],sqrt(vector[1]*vector[1]+vector[2]*vector[2]),0,0,1,0);
+ double beta=VectorAngel(0,vector[1],vector[2],0,1,0);
+ if (vector[0]>0) alpha=-alpha;
+ if (vector[2]<0) beta=-beta;
+ transform->Translate(Footpoint);
+ transform->RotateWXYZ(beta,1,0,0);
+ transform->RotateWXYZ(alpha,0,0,1);
+ transform->RotateWXYZ(-90,1,0,0);
+
+ transform->PostMultiply();
+
+ transformFilter->SetInputConnection(extrude->GetOutputPort());
+ transformFilter->SetTransform(transform);
+
+ AddPolyData(transformFilter->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+
+ points->Delete();
+ poly->Delete();
+ profile->Delete();
+ extrude->Delete();
+ transform->Delete();
+ transformFilter->Delete();
+}
+
+
+void VTKPrimitives::AddSurface(double *dCoords, unsigned int uiQtyCoords, double *dRGB, double dOpacity, const double* tf_matrix)
+{//complete
+ unsigned int i=0;
+ vtkPoints *points = vtkPoints::New();
+ vtkCellArray *poly = vtkCellArray::New();
+ vtkPolyData *profile = vtkPolyData::New();
+ for (i=0; i<uiQtyCoords;i++) points->InsertPoint(i,dCoords[3*i],dCoords[3*i+1],dCoords[3*i+2]);
+ for (i=0; i<uiQtyCoords;)
+ {
+ poly->InsertNextCell(3);
+ poly->InsertCellPoint(i++);
+ poly->InsertCellPoint(i++);
+ poly->InsertCellPoint(i++);
+ }
+ profile->SetPoints(points);
+ profile->SetPolys(poly);
+
+ AddPolyData(profile, dRGB, dOpacity, tf_matrix);
+ points->Delete();
+ poly->Delete();
+ profile->Delete();
+}
+
+void VTKPrimitives::AddSTLObject(const char *Filename, double *dCenter, double *dRGB, double dOpacity, const double* tf_matrix)
+{ //complete??
+ vtkSTLReader *part = vtkSTLReader::New();
+ part->SetFileName(Filename);
+ vtkPolyDataMapper *partMapper = vtkPolyDataMapper::New();
+
+ vtkActor* actor = AddPolyData(part->GetOutputPort(), dRGB, dOpacity, tf_matrix);
+ actor->SetPosition(dCenter);
+
+ part->Delete();
+ partMapper->Delete();
+}
+
+vtkActor* VTKPrimitives::AddPolyData(vtkPolyData* polydata, double *dRGB, double dOpacity, const double* tf_matrix)
+{
+ vtkTransformPolyDataFilter* filter = vtkTransformPolyDataFilter::New();
+ vtkTransform* vtrans = vtkTransform::New();
+#if VTK_MAJOR_VERSION>=6
+ filter->SetInputData(polydata);
+#else
+ filter->SetInput(polydata);
+#endif
+ if (tf_matrix)
+ vtrans->SetMatrix(tf_matrix);
+ filter->SetTransform(vtrans);
+
+#if VTK_MAJOR_VERSION>=6
+ m_PolyDataCollection->AddInputData(filter->GetOutput());
+#else
+ m_PolyDataCollection->AddInput(filter->GetOutput());
+#endif
+
+ vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
+ Mapper->SetInputConnection(filter->GetOutputPort());
+ Mapper->ScalarVisibilityOff();
+ vtkLODActor *Actor = vtkLODActor::New();
+ Actor->SetMapper(Mapper);
+ Actor->GetProperty()->RemoveAllTextures();
+ Actor->GetProperty()->SetColor(dRGB);
+ Actor->GetProperty()->SetOpacity(dOpacity);
+
+ ActorColl->AddItem(Actor);
+ ren->AddActor(Actor);
+
+ filter->Delete();
+ vtrans->Delete();
+ Mapper->Delete();
+
+ return Actor;
+}
+
+vtkActor* VTKPrimitives::AddPolyData(vtkAlgorithmOutput* polydata_port, double *dRGB, double dOpacity, const double* tf_matrix)
+{
+ vtkTransformPolyDataFilter* filter = vtkTransformPolyDataFilter::New();
+ vtkTransform* vtrans = vtkTransform::New();
+ filter->SetInputConnection(polydata_port);
+ if (tf_matrix)
+ vtrans->SetMatrix(tf_matrix);
+ filter->SetTransform(vtrans);
+
+#if VTK_MAJOR_VERSION>=6
+ m_PolyDataCollection->AddInputData(filter->GetOutput());
+#else
+ m_PolyDataCollection->AddInput(filter->GetOutput());
+#endif
+
+ vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
+ Mapper->SetInputConnection(filter->GetOutputPort());
+ Mapper->ScalarVisibilityOff();
+ vtkLODActor *Actor = vtkLODActor::New();
+ Actor->SetMapper(Mapper);
+ Actor->GetProperty()->RemoveAllTextures();
+ Actor->GetProperty()->SetColor(dRGB);
+ Actor->GetProperty()->SetOpacity(dOpacity);
+
+ ActorColl->AddItem(Actor);
+ ren->AddActor(Actor);
+
+ filter->Delete();
+ vtrans->Delete();
+ Mapper->Delete();
+
+ return Actor;
+}
+
+void VTKPrimitives::SetOpacity2All(double opacity)
+{
+ ActorColl->InitTraversal();
+ vtkActor* act=NULL;
+ while ((act=ActorColl->GetNextActor()))
+ {
+ act->GetProperty()->SetOpacity(opacity);
+ }
+}
+
+void VTKPrimitives::WritePolyData2File(const char* filename, double scale)
+{
+ cout << "VTKPrimitives::WritePolyData2File: Dump to vtk file: " << filename << " -- Using scale: " << scale << endl;
+ vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New();
+ writer->SetFileName(filename);
+
+ if (scale==1.0)
+ {
+#if VTK_MAJOR_VERSION>=6
+ writer->SetInputData(m_PolyDataCollection->GetOutput());
+#else
+ writer->SetInput(m_PolyDataCollection->GetOutput());
+#endif
+ writer->Write();
+ }
+ else
+ {
+ vtkTransform *transform = vtkTransform::New();
+ vtkTransformPolyDataFilter *transformFilter = vtkTransformPolyDataFilter::New();
+
+#if VTK_MAJOR_VERSION>=6
+ transformFilter->SetInputData(m_PolyDataCollection->GetOutput());
+#else
+ transformFilter->SetInput(m_PolyDataCollection->GetOutput());
+#endif
+ transform->Scale(scale,scale,scale);
+ transformFilter->SetTransform(transform);
+
+#if VTK_MAJOR_VERSION>=6
+ writer->SetInputData(transformFilter->GetOutput());
+#else
+ writer->SetInput(transformFilter->GetOutput());
+#endif
+ writer->Write();
+
+ transform->Delete();
+ transformFilter->Delete();
+ }
+
+ writer->Delete();
+}
+
+void VTKPrimitives::WritePolyData2STL(const char* filename, double scale)
+{
+ cout << "VTKPrimitives::WritePolyData2STL: Dump to stl file: " << filename << " -- Using scale: " << scale << endl;
+
+ vtkTriangleFilter* filter = vtkTriangleFilter::New();
+
+#if VTK_MAJOR_VERSION>=6
+ filter->SetInputData(m_PolyDataCollection->GetOutput());
+#else
+ filter->SetInput(m_PolyDataCollection->GetOutput());
+#endif
+ vtkSTLWriter* writer = vtkSTLWriter::New();
+ writer->SetFileName(filename);
+
+ if (scale==1.0)
+ {
+ writer->SetInputConnection(filter->GetOutputPort());
+ writer->Write();
+ }
+ else
+ {
+ vtkTransform *transform = vtkTransform::New();
+ vtkTransformPolyDataFilter *transformFilter = vtkTransformPolyDataFilter::New();
+
+ transformFilter->SetInputConnection(filter->GetOutputPort());
+ transform->Scale(scale,scale,scale);
+ transformFilter->SetTransform(transform);
+
+#if VTK_MAJOR_VERSION>=6
+ writer->SetInputData(transformFilter->GetOutput());
+#else
+ writer->SetInput(transformFilter->GetOutput());
+#endif
+ writer->Write();
+
+ transform->Delete();
+ transformFilter->Delete();
+ }
+
+ writer->Delete();
+}
+
+void VTKPrimitives::WritePolyData2PLY(const char* filename, double scale)
+{
+ cout << "VTKPrimitives::WritePolyData2PLY: Dump to ply file: " << filename << " -- Using scale: " << scale << endl;
+
+ vtkTriangleFilter* filter = vtkTriangleFilter::New();
+
+#if VTK_MAJOR_VERSION>=6
+ filter->SetInputData(m_PolyDataCollection->GetOutput());
+#else
+ filter->SetInput(m_PolyDataCollection->GetOutput());
+#endif
+
+ vtkPLYWriter* writer = vtkPLYWriter::New();
+ writer->SetFileName(filename);
+
+ if (scale==1.0)
+ {
+ writer->SetInputConnection(filter->GetOutputPort());
+ writer->Write();
+ }
+ else
+ {
+ vtkTransform *transform = vtkTransform::New();
+ vtkTransformPolyDataFilter *transformFilter = vtkTransformPolyDataFilter::New();
+
+ transformFilter->SetInputConnection(filter->GetOutputPort());
+ transform->Scale(scale,scale,scale);
+ transformFilter->SetTransform(transform);
+
+#if VTK_MAJOR_VERSION>=6
+ writer->SetInputData(transformFilter->GetOutput());
+#else
+ writer->SetInput(transformFilter->GetOutput());
+#endif
+ writer->Write();
+
+ transform->Delete();
+ transformFilter->Delete();
+ }
+
+ writer->Delete();
+}
+
+
+double VTKPrimitives::VectorAngel(double dV1_1, double dV1_2, double dV1_3, double dV2_1, double dV2_2, double dV2_3)
+{
+ double angel=0,dV1L,dV2L;
+ double scalarP;
+ dV1L=sqrt(dV1_1*dV1_1+dV1_2*dV1_2+dV1_3*dV1_3);
+ dV2L=sqrt(dV2_1*dV2_1+dV2_2*dV2_2+dV2_3*dV2_3);
+ scalarP=dV1_1*dV2_1+dV1_2*dV2_2+dV1_3*dV2_3;
+ if ((dV1L*dV2L)==0) return 0;
+ angel=scalarP/(dV1L*dV2L);
+ if (angel>1) angel=0.0;
+ else if (angel<-1) angel=180.0;
+ else angel=acos(angel)*180/PI;
+ return angel;
+}
+
+double VTKPrimitives::DistancePointLine(const double *dpoint, const double *dstart, const double *dvector, double *dFootpoint)
+{
+ double dpos=0;
+ dpos= ( (dpoint[0]-dstart[0])*dvector[0]+(dpoint[1]-dstart[1])*dvector[1]+(dpoint[2]-dstart[2])*dvector[2] ) /(dvector[0]*dvector[0]+dvector[1]*dvector[1]+dvector[2]*dvector[2]);
+ for (int i=0; i<3; i++) dFootpoint[i]=dstart[i]+dpos*dvector[i];
+ return sqrt( (dpoint[0]-dFootpoint[0])*(dpoint[0]-dFootpoint[0]) + (dpoint[1]-dFootpoint[1])*(dpoint[1]-dFootpoint[1]) + (dpoint[2]-dFootpoint[2])*(dpoint[2]-dFootpoint[2]) );
+}
+
+double VTKPrimitives::DistancePointPoint(const double *dpoint1, const double *dpoint2)
+{
+ return sqrt( (dpoint1[0]-dpoint2[0])*(dpoint1[0]-dpoint2[0]) + (dpoint1[1]-dpoint2[1])*(dpoint1[1]-dpoint2[1]) + (dpoint1[2]-dpoint2[2])*(dpoint1[2]-dpoint2[2]) );
+}
+
+double* VTKPrimitives::TransformCylindricalCoords(const double* in, double* out, unsigned int nrPoints)
+{
+ unsigned int i,j,k;
+ for (unsigned int n=0;n<nrPoints;++n)
+ {
+ i = n;
+ j = nrPoints + n;
+ k = 2*nrPoints + n;
+
+ out[i] = in[i] * cos(in[j]);
+ out[j] = in[i] * sin(in[j]);
+ out[k] = in[k];
+ }
+ return out;
+}
diff --git a/QCSXCAD/VTKPrimitives.h b/QCSXCAD/VTKPrimitives.h
new file mode 100644
index 0000000..4d396d5
--- /dev/null
+++ b/QCSXCAD/VTKPrimitives.h
@@ -0,0 +1,143 @@
+/*
+* Copyright (C) 2005,2006,2007,2008,2009,2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*!
+\class VTKPrimitives
+\author Thorsten Liebig
+\version 2
+\date 7.8.2007
+\bug Methode AddRotationalPoly produces false 3D alignment
+\todo Methode AddDisc data structure has to be revised
+*/
+
+#ifndef _VTKPRIMITIVES_H
+#define _VTKPRIMITIVES_H
+
+class vtkRenderer;
+class vtkPolyData;
+class vtkActorCollection;
+class vtkAppendPolyData;
+class vtkActor;
+class vtkAlgorithmOutput;
+
+#define PI 3.141592654
+
+class VTKPrimitives
+{
+public:
+ /// Constructor needs a vtkRenderer for adding primitives
+ /*! \param *Renderer necessary for construction is a valid vtkRenderer \sa VTKVisualization */
+ VTKPrimitives(vtkRenderer *Renderer);
+ /// Deconstructor
+ ~VTKPrimitives();
+ /// Add a Cube to scene
+ /*! \param *dCoords Set points as room diagonal (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax) \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) */
+ void AddCube(double *dCoords, double *dRGB, double dOpacity, const double* tf_matrix=0); //complete
+ void AddCube(const double *dStart, const double *dStop, double *dRGB, double dOpacity, const double* tf_matrix=0); //complete
+ /// Add a Cube in cylindrical coordinates to scene
+ /*! \param *dCoords Set points as room diagonal (Rmin,Rmax,Amin,Amax,Zmin,Zmax) \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) */
+ void AddCylindricalCube(double *dCoords, double *dRGB, double dOpacity, const double* tf_matrix=0);
+ void AddCylindricalCube(const double *dStart, const double *dStop, double *dRGB, double dOpacity, const double* tf_matrix=0);
+ /// Add a Plane to scene
+ /*! \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) */
+ void AddPlane(double *dOrigin, double* dP1, double* dP2, double *dRGB, double dOpacity, const double* tf_matrix=0); //complete
+ /// Add a discrete object (many cubes) to scene
+ /*! \param *dCoords Set Points as X1,X2,...,Xn,Y1,Y2,...,Yn,Z1,Z2,...Zn. \param uiQtyCoords Set quantity of Points X,Y,Z. \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) */
+ void AddDisc(double *dCoords, unsigned int uiQtyCoords, double *dRGB, double dOpacity, const double* tf_matrix=0);
+ /// Add a closed polygon to scene
+ /*! \param *dCoords Set Points as X1,X2,...,Xn,Y1,Y2,...,Yn,Z1,Z2,...Zn for polygon. \param uiQtyCoords Set Quantity of Points X,Y,Z \param dExtrusionVector Give extrusion vector (X,Y,Z) \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness)*/
+ void AddClosedPoly(double *dCoords, unsigned int uiQtyCoords, double *dExtrusionVector, double *dRGB, double dOpacity, const double* tf_matrix=0);//complete
+ /// Add a linear polygon to scene
+ /*! \param *dCoords Set Points as X1,X2,...,Xn,Y1,Y2,...,Yn,Z1,Z2,...Zn for polygon. \param uiQtyCoords Set Quantity of Points X,Y,Z \param LineWidth Set line width \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness)*/
+ void AddLinePoly(const double *dCoords, unsigned int uiQtyCoords,unsigned int LineWidth, double *dRGB, double dOpacity, const double* tf_matrix=0);//complete
+ /// Add a linear polygon as tubes to scene
+ /*! \param *dCoords Set Points as X1,X2,...,Xn,Y1,Y2,...,Yn,Z1,Z2,...Zn for polygon. \param uiQtyCoords Set Quantity of Points X,Y,Z \param TubeRadius Set tube radius \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness)*/
+ void AddTubePoly(const double *dCoords, unsigned int uiQtyCoords, double TubeRadius, double *dRGB, double dOpacity, int iResolution=8, const double* tf_matrix=0);//complete
+ /// Add a cylinder to scene
+ /*! \param *dCenterAxis Set Base Point in 3D space \param *dExtrusionVector Set height (absolute value) and direction \param fRadius Set Radius \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) \param iResolution Set resolution of discretisation*/
+ void AddCylinder(const double *dCenterAxis, const double *dExtrusionVector, float fRadius, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix=0); //complete
+ /*! \param *dAxisStart Cylinder axis start point \param *dAxisStop Cylinder axis end point \param fRadius Set Radius \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) \param iResolution Set resolution of discretisation*/
+ void AddCylinder2(const double *dAxisStart, const double* dAxisStop, float fRadius, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix=0); //complete
+ /*! \brief Add a cylindrical shell to the scene. \param *dAxisStart Cylinder axis start point \param *dAxisStop Cylinder axis end point \param r_i Set inner radius \param r_o Set outer radius \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) \param iResolution Set resolution of discretisation*/
+ void AddCylindricalShell(const double *dAxisStart, const double* dAxisStop, double r_i, double r_o, double *dRGB, double dOpacity, int iResolution, const double *tf_matrix=0);
+ /// Add a Sphere to scene
+ /*! \param *dCenter Set Center Point in 3D space \param fRadius Set Radius \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) \param iResolution Set resolution of discretisation*/
+ void AddSphere(const double *dCenter, double fRadius, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix=0); //complete
+ /// Add a Spherical shell to scene
+ /*! \param *dCenter Set Center Point in 3D space \param r_i Set inner radius \param r_o Set outer radius \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) \param iResolution Set resolution of discretisation*/
+ void AddSphericalShell(const double *dCenter, double r_i, double r_o, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix=0); //complete
+ /// Add an arrow to scene
+ /*! \param *dStart Set start point \param *dEnd Set end point \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) \param iResolution Set resolution of discretisation*/
+ void AddArrow(double *dStart, double *dEnd, double *dRGB, double dOpacity, int iResolution=6, const double* tf_matrix=0);
+ /// Add a text-label to scene
+ /*! \param *cText Set text for the label \param *dCoords Set point of label origin \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) \param dscale Scale the size of the label*/
+ void AddLabel(char *cText, double *dCoords, double *dRGB, double dOpacity, double dscale=1.0, const double* tf_matrix=0);
+ /// Add a rotated polygon to scene
+ /*! \param *dCoords Set Points as X1,X2,...,Xn,Y1,Y2,...,Yn,Z1,Z2,...Zn for polygon. \param uiQtyCoords Set Quantity of Points X,Y,Z \param *fRotAxis Set rotation axis (X1,X2,Y1,Y2,Z1,Z2) \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) \param iResolution Set resolution of discretisation*/
+ void AddRotationalPoly(const double *dCoords, unsigned int uiQtyCoords, const double *fRotAxis, double StartStopAngle[2], double *dRGB, double dOpacity, int iResolution, const double* tf_matrix=0);//complete
+ /// Add a rotated circle (torus) to scene
+ /*! \param dPoint Set point in 3D space \param fRadius Set radius of the torus \param *fRotAxis Set rotation axis (X1,X2,Y1,Y2,Z1,Z2) \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness) \param iResolution Set resolution of discretisation*/
+ void AddRotationalSolid(const double *dPoint, double fRadius, const double *fRotAxis, double *dRGB, double dOpacity, int iResolution, const double* tf_matrix=0); //complete
+ /// Add a surface (triangles) to scene
+ /*! \param *dCoords Set Points as X1,X2,...,Xn,Y1,Y2,...,Yn,Z1,Z2,...Zn for triangles of surface. \param uiQtyCoords Set Quantity of Points X,Y,Z \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness)*/
+ void AddSurface(double *dCoords, unsigned int uiQtyCoords, double *dRGB, double dOpacity, const double* tf_matrix=0);//complete
+ /// Add a STL-object to scene
+ /*! \param *Filename Set filename of STL object \param *dCenter Set point of origin for STL object \param *dRGB Set RGB Colors (range 0 to 1 for red, green, blue) \param dOpacity Set opacity (0 complete transparency to 1 complete opaqueness)*/
+ void AddSTLObject(const char *Filename, double *dCenter, double *dRGB, double dOpacity, const double* tf_matrix=0);//complete
+
+ //! Add the given polydata to the scene
+ vtkActor* AddPolyData(vtkAlgorithmOutput* polydata_port, double *dRGB, double dOpacity, const double* tf_matrix=0);
+ //! Add the given polydata to the scene
+ vtkActor* AddPolyData(vtkPolyData* polydata, double *dRGB, double dOpacity, const double* tf_matrix=0);
+
+ void SetOpacity2All(double opacity);
+
+ //! Write the collected poly-data into a vtk xml file (should be a *.vtp)
+ void WritePolyData2File(const char* filename, double scale=1.0);
+
+ //! Write the collected poly-data into a stl file (should be a *.stl)
+ void WritePolyData2STL(const char* filename, double scale=1.0);
+
+ //! Write the collected poly-data into a ply file (should be a *.ply)
+ void WritePolyData2PLY(const char* filename, double scale=1.0);
+
+protected:
+ /// unusable constructor, only for inheritance
+ VTKPrimitives();
+ /// vtkRenderer, has to be set by constructor
+ vtkRenderer *ren;
+ /// Collection of all Actors generated in this class so far
+ vtkActorCollection *ActorColl;
+ /// Calculate angle between 2 vectors
+ double VectorAngel(double dV1_1, double dV1_2, double dV1_3, double dV2_1, double dV2_2, double dV2_3);
+ /// Calculate distance between a point and an axis
+ /*! \param *dpoint Set point \param *dstart Set footpoint of axis \param *dvector Set direction of axis \param *dFootpoint Returns the point on axis, that is nearest to the input point \return Methode returns distance */
+ double DistancePointLine(const double *dpoint, const double *dstart, const double *dvector, double *dFootpoint);
+ /// Calculate distance between one point and another
+ /*! \param *dpoint1 Set first point \param *dpoint2 Set second point \return Methode returns distance */
+ double DistancePointPoint(const double *dpoint1, const double *dpoint2);
+
+ //! A Collection of all incoming poly-data
+ vtkAppendPolyData* m_PolyDataCollection;
+
+ double m_ArcDelta;
+
+ //! This internal methode will transform cylindrical coords into cartesian coords used by vtk.
+ double* TransformCylindricalCoords(const double* in, double* out, unsigned int nrPoints=1);
+};
+
+#endif
diff --git a/QCSXCAD/cmake/Modules/FindTinyXML.cmake b/QCSXCAD/cmake/Modules/FindTinyXML.cmake
new file mode 100644
index 0000000..aabb323
--- /dev/null
+++ b/QCSXCAD/cmake/Modules/FindTinyXML.cmake
@@ -0,0 +1,74 @@
+##################################################################################################
+#
+# CMake script for finding TinyXML.
+#
+# Input variables:
+#
+# - TinyXML_ROOT_DIR (optional): When specified, header files and libraries will be searched for in
+# ${TinyXML_ROOT_DIR}/include
+# ${TinyXML_ROOT_DIR}/libs
+# respectively, and the default CMake search order will be ignored. When unspecified, the default
+# CMake search order is used.
+# This variable can be specified either as a CMake or environment variable. If both are set,
+# preference is given to the CMake variable.
+# Use this variable for finding packages installed in a nonstandard location, or for enforcing
+# that one of multiple package installations is picked up.
+#
+#
+# Cache variables (not intended to be used in CMakeLists.txt files)
+#
+# - TinyXML_INCLUDE_DIR: Absolute path to package headers.
+# - TinyXML_LIBRARY: Absolute path to library.
+#
+#
+# Output variables:
+#
+# - TinyXML_FOUND: Boolean that indicates if the package was found
+# - TinyXML_INCLUDE_DIRS: Paths to the necessary header files
+# - TinyXML_LIBRARIES: Package libraries
+#
+#
+# Example usage:
+#
+# find_package(TinyXML)
+# if(NOT TinyXML_FOUND)
+# # Error handling
+# endif()
+# ...
+# include_directories(${TinyXML_INCLUDE_DIRS} ...)
+# ...
+# target_link_libraries(my_target ${TinyXML_LIBRARIES})
+#
+##################################################################################################
+
+# Get package location hint from environment variable (if any)
+if(NOT TinyXML_ROOT_DIR AND DEFINED ENV{TinyXML_ROOT_DIR})
+ set(TinyXML_ROOT_DIR "$ENV{TinyXML_ROOT_DIR}" CACHE PATH
+ "TinyXML base directory location (optional, used for nonstandard installation paths)")
+endif()
+
+# Search path for nonstandard package locations
+if(TinyXML_ROOT_DIR)
+ set(TinyXML_INCLUDE_PATH PATHS "${TinyXML_ROOT_DIR}/include" NO_DEFAULT_PATH)
+ set(TinyXML_LIBRARY_PATH PATHS "${TinyXML_ROOT_DIR}/lib" NO_DEFAULT_PATH)
+endif()
+
+# Find headers and libraries
+find_path(TinyXML_INCLUDE_DIR NAMES tinyxml.h PATH_SUFFIXES "tinyxml" ${TinyXML_INCLUDE_PATH})
+find_library(TinyXML_LIBRARY NAMES tinyxml PATH_SUFFIXES "tinyxml" ${TinyXML_LIBRARY_PATH})
+
+mark_as_advanced(TinyXML_INCLUDE_DIR
+ TinyXML_LIBRARY)
+
+# Output variables generation
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(TinyXML DEFAULT_MSG TinyXML_LIBRARY
+ TinyXML_INCLUDE_DIR)
+
+set(TinyXML_FOUND ${TINYXML_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
+unset(TINYXML_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args
+
+if(TinyXML_FOUND)
+ set(TinyXML_INCLUDE_DIRS ${TinyXML_INCLUDE_DIR})
+ set(TinyXML_LIBRARIES ${TinyXML_LIBRARY})
+endif()
diff --git a/QCSXCAD/export_pov.cpp b/QCSXCAD/export_pov.cpp
new file mode 100644
index 0000000..07f6fb5
--- /dev/null
+++ b/QCSXCAD/export_pov.cpp
@@ -0,0 +1,267 @@
+/*
+* Copyright (C) 2010 Sebastian Held (sebastian.held@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QMessageBox>
+#include <QtXml>
+
+#include <QVTKWidget.h>
+#include <vtkRendererCollection.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderer.h>
+#include <vtkCamera.h>
+
+#include <vector>
+#include <ContinuousStructure.h>
+
+#include "CSPrimBox.h"
+#include "CSPrimCylinder.h"
+#include "CSPrimPolygon.h"
+#include "CSPrimCurve.h"
+#include "CSPrimWire.h"
+
+#include "QVTKStructure.h"
+#include "QCSXCAD.h"
+#include "export_pov.h"
+
+export_pov::export_pov( QCSXCAD *CSX ) : m_CSX(CSX)
+{
+ m_epsilon = 1; // FIXME this should be small compared to any other linear dimension of any object in the scene
+
+}
+
+void export_pov::save( QString filename )
+{
+ QFile file( filename );
+ if (!file.open( QFile::WriteOnly )) {
+ QMessageBox::warning( m_CSX, QObject::tr("save failed"), QObject::tr("Cannot save to the file %1").arg(filename), QMessageBox::Ok );
+ return;
+ }
+ QTextStream stream(&file);
+ stream.setCodec( "UTF-8" );
+
+ stream << "// povray-file exported by QCSXCAD" << endl;
+ stream << "// render with:" << endl;
+ stream << "// povray -W640 -H480 +A " << QFileInfo(filename).fileName() << endl;
+ stream << endl;
+ stream << "#declare TRANSPARENT = off; // if on, also use the \"+ua\" command line flag" << endl;
+ stream << endl;
+ stream << "#include \"colors.inc\"" << endl;
+ stream << "#include \"metals.inc\"" << endl;
+ stream << "#include \"textures.inc\"" << endl;
+ stream << "#include \"transforms.inc\"" << endl;
+ stream << "background { color rgb<1.000000,1.000000,1.000000> #if(TRANSPARENT) transmit 1.0 #end }" << endl;
+
+ // export material
+ std::vector<CSProperties*> properties = m_CSX->GetPropertyByType( CSProperties::MATERIAL );
+ export_properties( stream, properties, "pigment { color rgbt <0.000, 0.533, 0.800,0.0> } finish { diffuse 0.6 }" );
+
+ // export metal
+ properties = m_CSX->GetPropertyByType( CSProperties::METAL );
+ export_properties( stream, properties, "texture { Copper_Metal }" );
+
+ // create camera
+ stream << get_camera() << endl;
+
+ // create light
+ stream << get_light() << endl;
+
+ stream.flush();
+ file.close();
+}
+
+void export_pov::export_properties( QTextStream &stream, std::vector<CSProperties*> properties, QString default_obj_modifier )
+{
+ foreach( CSProperties* prop, properties )
+ {
+ int size = prop->GetQtyPrimitives();
+ for( int i=0; i<size; i++ )
+ {
+ CSPrimitives *prim = prop->GetPrimitive(i);
+ if (prim->GetType() == CSPrimitives::BOX)
+ {
+ CSPrimBox *box = prim->ToBox();
+ double start[] = {box->GetCoord(0),box->GetCoord(2),box->GetCoord(4)};
+ double stop[] = {box->GetCoord(1),box->GetCoord(3),box->GetCoord(5)};
+ export_box( stream, start, stop, default_obj_modifier );
+ }
+ else if (prim->GetType() == CSPrimitives::POLYGON)
+ {
+ CSPrimPolygon *polygon = prim->ToPolygon();
+ size_t count = -1;
+ double *array = 0;
+ array = polygon->GetAllCoords( count, array );
+ int normDir = polygon->GetNormDir();
+ double elevation = polygon->GetElevation();
+ export_polygon( stream, count, array, elevation, normDir, default_obj_modifier );
+ }
+ else if (prim->GetType() == CSPrimitives::CYLINDER)
+ {
+ CSPrimCylinder *primitive = prim->ToCylinder();
+ double start[] = {primitive->GetCoord(0),primitive->GetCoord(2),primitive->GetCoord(4)};
+ double stop[] = {primitive->GetCoord(1),primitive->GetCoord(3),primitive->GetCoord(5)};
+ double radius = primitive->GetRadius();
+ export_cylinder( stream, start, stop, radius, default_obj_modifier );
+ }
+ else if (prim->GetType() == CSPrimitives::WIRE)
+ {
+ CSPrimWire *primitive = prim->ToWire();
+ double radius = primitive->GetWireRadius();
+ size_t count = primitive->GetNumberOfPoints();
+ double *array = new double[count*3];
+ for (unsigned int i=0; i<count; i++)
+ primitive->GetPoint(i,array+i*3, CARTESIAN);
+ export_wire( stream, count, array, radius, default_obj_modifier );
+ delete[] array;
+ }
+ else if (prim->GetType() == CSPrimitives::CURVE)
+ {
+ CSPrimCurve *primitive = prim->ToCurve();
+ double radius = m_epsilon;
+ size_t count = primitive->GetNumberOfPoints();
+ double *array = new double[count*3];
+ for (unsigned int i=0; i<count; i++)
+ primitive->GetPoint(i,array+i*3, CARTESIAN);
+ export_wire( stream, count, array, radius, default_obj_modifier );
+ delete[] array;
+ }
+ }
+ }
+}
+
+void export_pov::export_box( QTextStream &stream, double start[3], double stop[3], QString object_modifier )
+{
+ for (int i=0; i<3; i++)
+ if (start[i] == stop[i]) {
+ // 2D box
+ // povray supports 2D polygons, but has no priority concept, therefore we use the box primitive
+ start[i] -= m_epsilon;
+ stop[i] += m_epsilon;
+ }
+ QString box = "box { %1, %2 %3 }";
+ box = box.arg(pov_vect(start),pov_vect(stop),object_modifier);
+ stream << box << endl;
+}
+
+void export_pov::export_polygon( QTextStream &stream, size_t count, double *array, double elevation, int normDir, QString object_modifier )
+{
+ UNUSED(normDir);
+ Q_ASSERT((count%2)==0);
+
+ count = count / 2; // now count is the number of 2D-vectors
+ if (count < 2)
+ return;
+
+ elevation = -elevation;
+ //NormDir = [CSX_polygon.NormDir.ATTRIBUTE.X CSX_polygon.NormDir.ATTRIBUTE.Y CSX_polygon.NormDir.ATTRIBUTE.Z];
+ QString str = "prism { linear_spline linear_sweep %1, %2, %3";
+ str = str.arg(elevation - m_epsilon).arg(elevation + m_epsilon).arg(count+1);
+ for (unsigned int a=0; a<count; a++)
+ {
+ // iterate over all vertices
+ str += ", " + pov_vect2( array + a*2 );
+ }
+ str += ", " + pov_vect2( array ); // close the prism
+ str += " " + object_modifier + " rotate<-90,0,0> }";
+
+ stream << str << endl;
+}
+
+void export_pov::export_cylinder( QTextStream &stream, double start[3], double stop[3], double radius, QString object_modifier )
+{
+ QString str = "cylinder { %1, %2, %3 %4 }";
+ str = str.arg(pov_vect(start)).arg(pov_vect(stop)).arg(radius).arg(object_modifier);
+ stream << str << endl;
+}
+
+void export_pov::export_wire( QTextStream &stream, size_t count, double *array, double radius, QString object_modifier )
+{
+ QString str = "sphere_sweep { linear_spline, " + QString::number(count);
+ for (unsigned int a=0; a<count; a++)
+ {
+ // iterate over all vertices
+ str += ", " + pov_vect(array+a*3) + ", " + QString::number(radius);
+ }
+ str += " " + object_modifier + " }";
+ stream << str << endl;
+}
+
+QString export_pov::get_camera()
+{
+ vtkRendererCollection* collection = ((QVTKWidget*)(m_CSX->StructureVTK->GetVTKWidget()))->GetRenderWindow()->GetRenderers();
+ vtkRenderer *r = collection->GetFirstRenderer();
+ if (!r)
+ return QString();
+ vtkCamera *c = r->GetActiveCamera();
+ if (!c)
+ return QString();
+
+ double *pos = c->GetPosition();
+// cout << "Camera position: " << pos[0] << ", " << pos[1] << ", " << pos[2] << endl;
+ double *focalpos = c->GetFocalPoint();
+// cout << "Camera focal point: " << focalpos[0] << ", " << focalpos[1] << ", " << focalpos[2] << endl;
+// double distance = c->GetDistance();
+// cout << "Camera distance (position to focal point): " << distance << endl;
+// double roll = c->GetRoll();
+// cout << "Camera roll angle (about direction of projection): " << roll << "°" << endl;
+ double angle = c->GetViewAngle();
+// cout << "Camera view angle: " << angle << "°" << endl;
+ double *up = c->GetViewUp();
+// cout << "Camera up vector: " << up[0] << ", " << up[1] << ", " << up[2] << endl;
+
+ QString camera_str;
+ camera_str = "camera { perspective location %1 look_at %2 sky %3 right -1.33*x angle %4 }";
+ camera_str = camera_str.arg(pov_vect(pos),pov_vect(focalpos),pov_vect(up)).arg(angle);
+
+ return camera_str;
+}
+
+QString export_pov::get_light()
+{
+ vtkRendererCollection* collection = ((QVTKWidget*)(m_CSX->StructureVTK->GetVTKWidget()))->GetRenderWindow()->GetRenderers();
+ vtkRenderer *r = collection->GetFirstRenderer();
+ if (!r)
+ return QString();
+ vtkCamera *c = r->GetActiveCamera();
+ if (!c)
+ return QString();
+
+ double *pos = c->GetPosition();
+// double *focalpos = c->GetFocalPoint();
+// double distance = c->GetDistance();
+// double roll = c->GetRoll();
+// double angle = c->GetViewAngle();
+// double *up = c->GetViewUp();
+
+ QString light_str;
+ light_str = "light_source { %1, rgb <1,1,1> }";
+ light_str = light_str.arg(pov_vect(pos));
+
+ return light_str;
+}
+
+QString export_pov::pov_vect( double *v )
+{
+ QString v_str = "<%1,%2,%3>";
+ v_str = v_str.arg(v[0]).arg(v[1]).arg(v[2]);
+ return v_str;
+}
+QString export_pov::pov_vect2( double *v )
+{
+ QString v_str = "<%1,%2>";
+ v_str = v_str.arg(v[0]).arg(v[1]);
+ return v_str;
+}
diff --git a/QCSXCAD/export_pov.h b/QCSXCAD/export_pov.h
new file mode 100644
index 0000000..a59917f
--- /dev/null
+++ b/QCSXCAD/export_pov.h
@@ -0,0 +1,49 @@
+/*
+* Copyright (C) 2010 Sebastian Held (sebastian.held@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef EXPORT_POV_H
+#define EXPORT_POV_H
+
+#include <QtXml>
+#include <QString>
+
+class QCSXCAD;
+class CSProperties;
+
+class export_pov
+{
+public:
+ export_pov( QCSXCAD * );
+ void save( QString filename );
+
+protected:
+ void export_properties( QTextStream &stream, std::vector<CSProperties*> properties, QString default_obj_modifier = QString() );
+ void export_box( QTextStream &stream, double start[3], double stop[3], QString obj_modifier = QString() );
+ void export_polygon( QTextStream &stream, size_t count, double *array, double elevation, int normDir, QString obj_modifier = QString() );
+ void export_cylinder( QTextStream &stream, double start[3], double stop[3], double radius, QString object_modifier = QString() );
+ void export_wire( QTextStream &stream, size_t count, double *array, double radius, QString object_modifier );
+ QString get_camera();
+ QString get_light();
+ QString pov_vect( double *v );
+ QString pov_vect2( double *v );
+
+protected:
+ QCSXCAD *m_CSX;
+ double m_epsilon; //!< this should be very small compared to every object inside m_CSX; used to make 2D boxes -> 3D
+};
+
+#endif // EXPORT_POV_H
diff --git a/QCSXCAD/export_x3d.cpp b/QCSXCAD/export_x3d.cpp
new file mode 100644
index 0000000..347463d
--- /dev/null
+++ b/QCSXCAD/export_x3d.cpp
@@ -0,0 +1,201 @@
+/*
+* Copyright (C) 2010 Sebastian Held (sebastian.held@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QMessageBox>
+
+#include <QVTKWidget.h>
+#include <vtkRendererCollection.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderer.h>
+#include <vtkCamera.h>
+
+#include <QtXml>
+#include <vector>
+#include <ContinuousStructure.h>
+#include "CSPrimBox.h"
+#include "CSPrimPolygon.h"
+
+#include "QVTKStructure.h"
+#include "QCSXCAD.h"
+#include "export_x3d.h"
+
+export_X3D::export_X3D( QCSXCAD *CSX ) : m_CSX(CSX)
+{
+}
+
+void export_X3D::save( QString filename )
+{
+ QDomImplementation impl;
+ QDomDocument doc( impl.createDocumentType ( "X3D", "ISO//Web3D//DTD X3D 3.2//EN", "http://www.web3d.org/specifications/x3d-3.2.dtd" ) );
+ doc.appendChild( doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" )); // FIXME this is not a processing instruction!
+ QDomElement X3D = doc.createElement( "X3D" );
+ X3D.setAttribute( "version", "3.2" );
+ X3D.setAttribute( "profile", "Immersive" );
+ doc.appendChild( X3D );
+ QDomElement head = doc.createElement( "head" );
+ X3D.appendChild( head );
+ QDomElement meta = doc.createElement( "meta" );
+ meta.setAttribute( "name", "description" );
+ meta.setAttribute( "content", "X3D model exported by QCSXCAD" );
+ head.appendChild( meta );
+ QDomElement Scene = doc.createElement( "Scene" );
+ X3D.appendChild( Scene );
+
+ QDomElement NavigationInfo = doc.createElement( "NavigationInfo" );
+ NavigationInfo.setAttribute( "headlight", "true" );
+// NavigationInfo.setAttribute( "avatarSize", "0.25 1.6 0.75" );
+ NavigationInfo.setAttribute( "type", "EXAMINE" );
+ Scene.appendChild( NavigationInfo );
+
+ std::vector<CSProperties*> properties = m_CSX->GetPropertyByType( CSProperties::MATERIAL );
+ export_properties( Scene, properties );
+
+ properties = m_CSX->GetPropertyByType( CSProperties::METAL );
+ QDomElement Material = doc.createElement( "Material" );
+ Material.setAttribute( "diffuseColor", "0.0 1.0 0.0" );
+ export_properties( Scene, properties, Material );
+
+ // create camera
+ vtkRendererCollection* collection = ((QVTKWidget*)(m_CSX->StructureVTK->GetVTKWidget()))->GetRenderWindow()->GetRenderers();
+ vtkRenderer *r = collection->GetFirstRenderer();
+ if (!r)
+ return;
+ vtkCamera *c = r->GetActiveCamera();
+ if (!c)
+ return;
+
+ QDomElement Viewpoint = doc.createElement( "Viewpoint" );
+ double *pos = c->GetPosition();
+ Viewpoint.setAttribute( "position", QString::number(pos[0]) + " " + QString::number(pos[1]) + " " + QString::number(pos[2]) );
+// double *focalpos = c->GetFocalPoint();
+// Viewpoint.setAttribute( "centerOfRotation", QString::number(focalpos[0]) + " " + QString::number(focalpos[1]) + " " + QString::number(focalpos[2]) );
+ double angle = c->GetViewAngle();
+ Viewpoint.setAttribute( "fieldOfView", QString::number(angle/180.0*M_PI) );
+ double *WXYZ = c->GetOrientationWXYZ();
+ Viewpoint.setAttribute( "orientation", QString::number(WXYZ[1]) + " " + QString::number(WXYZ[2]) + " " + QString::number(WXYZ[3]) + " " + QString::number((360.0-WXYZ[0])/180.0*M_PI) ); // WXYZ[0] is wrong VTK-BUG!?
+ Scene.appendChild( Viewpoint );
+
+// cout << doc.toString(4).toStdString() << endl;
+
+ QFile file( filename );
+ if (!file.open( QFile::WriteOnly )) {
+ QMessageBox::warning( m_CSX, QObject::tr("save failed"), QObject::tr("Cannot save to the file %1").arg(filename), QMessageBox::Ok );
+ return;
+ }
+ QTextStream stream(&file);
+ stream.setCodec( "UTF-8" );
+ doc.save( stream, 4, QDomNode::EncodingFromTextStream );
+}
+
+void export_X3D::export_properties( QDomElement Scene, std::vector<CSProperties*> properties, QDomElement Material )
+{
+ foreach( CSProperties* prop, properties )
+ {
+ int size = prop->GetQtyPrimitives();
+ for( int i=0; i<size; i++ )
+ {
+ CSPrimitives *prim = prop->GetPrimitive(i);
+ if (prim->GetType() == CSPrimitives::BOX)
+ {
+ CSPrimBox *box = prim->ToBox();
+ double start[] = {box->GetCoord(0),box->GetCoord(2),box->GetCoord(4)};
+ double stop[] = {box->GetCoord(1),box->GetCoord(3),box->GetCoord(5)};
+ export_box( Scene, start, stop, Material.cloneNode().toElement() );
+ }
+ else if (prim->GetType() == CSPrimitives::POLYGON)
+ {
+ CSPrimPolygon *polygon = prim->ToPolygon();
+ size_t count = -1;
+ double *array = 0;
+ array = polygon->GetAllCoords( count, array );
+ int normDir = polygon->GetNormDir();
+ double elevation = polygon->GetElevation();
+ export_polygon( Scene, count, array, elevation, normDir, Material.cloneNode().toElement() );
+ }
+ }
+ }
+}
+
+void export_X3D::export_box( QDomElement &elem, double start[3], double stop[3], QDomElement Material )
+{
+ double center[3], size[3];
+ for (int i=0; i<3; i++)
+ {
+ center[i] = (stop[i]+start[i])/2.0;// * GetGrid()->GetDeltaUnit();
+ size[i] = fabs(stop[i]-start[i]);// * GetGrid()->GetDeltaUnit();
+ }
+
+ QDomDocument doc = elem.ownerDocument();
+ QDomElement Transform = doc.createElement( "Transform" );
+ Transform.setAttribute( "translation", QString::number(center[0]) + " " + QString::number(center[1]) + " " + QString::number(center[2]) );
+ QDomElement Shape = doc.createElement( "Shape" );
+ Transform.appendChild( Shape );
+ QDomElement Box = doc.createElement( "Box" );
+ Box.setAttribute( "size", QString::number(size[0]) + " " + QString::number(size[1]) + " " + QString::number(size[2]) );
+ Shape.appendChild( Box );
+ QDomElement Appearance = doc.createElement( "Appearance" );
+ Shape.appendChild( Appearance );
+ if (Material.isNull())
+ {
+ Material = doc.createElement( "Material" );
+ Material.setAttribute( "diffuseColor", "1.0 0.0 0.0" );
+ }
+ Appearance.appendChild( Material );
+
+ elem.appendChild( Transform );
+}
+
+void export_X3D::export_polygon( QDomElement &elem, size_t count, double *array, double elevation, int normDir, QDomElement Material )
+{
+ if (count < 2)
+ return;
+
+ // VRML: cross section in xz-plane
+ QString crossSection;
+ crossSection = QString::number( array[0] ) + " " + QString::number( array[1] );
+ for (size_t i=2; i<count; i=i+2)
+ {
+ crossSection += ", " + QString::number( array[i] ) + " " + QString::number( array[i+1] );
+ }
+
+ QDomDocument doc = elem.ownerDocument();
+ QDomElement Transform = doc.createElement( "Transform" );
+// Transform.setAttribute( "translation", QString::number(center[0]) + " " + QString::number(center[1]) + " " + QString::number(center[2]) );
+ QDomElement Shape = doc.createElement( "Shape" );
+ Transform.appendChild( Shape );
+ QDomElement Extrusion = doc.createElement( "Extrusion" );
+ Extrusion.setAttribute( "crossSection", crossSection );
+ if (normDir == 0)
+ Extrusion.setAttribute( "orientation", "0 0 1 0" ); // FIXME not tested
+ else if (normDir == 1)
+ Extrusion.setAttribute( "orientation", "0 1 0 0" ); // FIXME not tested
+ else
+ Extrusion.setAttribute( "orientation", "1 0 0 " + QString::number(M_PI) );
+ float delta = 1;
+ Extrusion.setAttribute( "spine", "0 0 " + QString::number(elevation-delta) + ", 0 0 " + QString::number(elevation+delta) );
+ Shape.appendChild( Extrusion );
+ QDomElement Appearance = doc.createElement( "Appearance" );
+ Shape.appendChild( Appearance );
+ if (Material.isNull())
+ {
+ Material = doc.createElement( "Material" );
+ Material.setAttribute( "diffuseColor", "1.0 0.0 0.0" );
+ }
+ Appearance.appendChild( Material );
+
+ elem.appendChild( Transform );
+}
diff --git a/QCSXCAD/export_x3d.h b/QCSXCAD/export_x3d.h
new file mode 100644
index 0000000..9a4cbeb
--- /dev/null
+++ b/QCSXCAD/export_x3d.h
@@ -0,0 +1,42 @@
+/*
+* Copyright (C) 2010 Sebastian Held (sebastian.held@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef EXPORT_X3D_H
+#define EXPORT_X3D_H
+
+#include <QtXml>
+#include <QString>
+
+class QCSXCAD;
+class CSProperties;
+
+class export_X3D
+{
+public:
+ export_X3D( QCSXCAD * );
+ void save( QString filename );
+
+protected:
+ void export_properties( QDomElement Scene, std::vector<CSProperties*> properties, QDomElement Material = QDomElement() );
+ void export_box( QDomElement &elem, double start[3], double stop[3], QDomElement Material = QDomElement() );
+ void export_polygon( QDomElement &elem, size_t count, double *array, double elevation, int normDir, QDomElement Material = QDomElement() );
+
+protected:
+ QCSXCAD *m_CSX;
+};
+
+#endif // EXPORT_X3D_H
diff --git a/QCSXCAD/images/Arrows/Arrows.odg b/QCSXCAD/images/Arrows/Arrows.odg
new file mode 100644
index 0000000..b5210d9
--- /dev/null
+++ b/QCSXCAD/images/Arrows/Arrows.odg
Binary files differ
diff --git a/QCSXCAD/images/Arrows/ArrowsXY.png b/QCSXCAD/images/Arrows/ArrowsXY.png
new file mode 100644
index 0000000..dba241e
--- /dev/null
+++ b/QCSXCAD/images/Arrows/ArrowsXY.png
Binary files differ
diff --git a/QCSXCAD/images/Arrows/ArrowsXZ.odg b/QCSXCAD/images/Arrows/ArrowsXZ.odg
new file mode 100644
index 0000000..de87dba
--- /dev/null
+++ b/QCSXCAD/images/Arrows/ArrowsXZ.odg
Binary files differ
diff --git a/QCSXCAD/images/Arrows/ArrowsXZ.png b/QCSXCAD/images/Arrows/ArrowsXZ.png
new file mode 100644
index 0000000..439c52e
--- /dev/null
+++ b/QCSXCAD/images/Arrows/ArrowsXZ.png
Binary files differ
diff --git a/QCSXCAD/images/Arrows/ArrowsYZ.odg b/QCSXCAD/images/Arrows/ArrowsYZ.odg
new file mode 100644
index 0000000..80084b2
--- /dev/null
+++ b/QCSXCAD/images/Arrows/ArrowsYZ.odg
Binary files differ
diff --git a/QCSXCAD/images/Arrows/ArrowsYZ.png b/QCSXCAD/images/Arrows/ArrowsYZ.png
new file mode 100644
index 0000000..c7285e6
--- /dev/null
+++ b/QCSXCAD/images/Arrows/ArrowsYZ.png
Binary files differ
diff --git a/QCSXCAD/images/ArrowsXY.png b/QCSXCAD/images/ArrowsXY.png
new file mode 100644
index 0000000..dba241e
--- /dev/null
+++ b/QCSXCAD/images/ArrowsXY.png
Binary files differ
diff --git a/QCSXCAD/images/ArrowsXZ.png b/QCSXCAD/images/ArrowsXZ.png
new file mode 100644
index 0000000..439c52e
--- /dev/null
+++ b/QCSXCAD/images/ArrowsXZ.png
Binary files differ
diff --git a/QCSXCAD/images/ArrowsYZ.png b/QCSXCAD/images/ArrowsYZ.png
new file mode 100644
index 0000000..c7285e6
--- /dev/null
+++ b/QCSXCAD/images/ArrowsYZ.png
Binary files differ
diff --git a/QCSXCAD/images/CVS/Entries b/QCSXCAD/images/CVS/Entries
new file mode 100644
index 0000000..3593808
--- /dev/null
+++ b/QCSXCAD/images/CVS/Entries
@@ -0,0 +1,40 @@
+/GeoEdit.png/1.1/Mon Oct 20 07:11:47 2003/-kb/
+/ParaSetup.png/1.1/Mon Oct 20 07:11:13 2003/-kb/
+/Thumbs.db/1.2/Tue Jun 27 14:51:16 2006/-kb/
+/accept.png/1.1/Mon Aug 29 14:17:00 2005/-kb/
+/bulb.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/bulb_off.png/1.1/Wed Oct 11 20:48:27 2006/-kb/
+/cancel.png/1.1/Mon Oct 20 07:16:21 2003/-kb/
+/close.png/1.1/Mon Oct 20 07:16:25 2003/-kb/
+/configure.png/1.1/Mon Oct 10 19:03:03 2005/-kb/
+/down.png/1.1/Mon Oct 10 19:03:03 2005/-kb/
+/edit.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/edit_add.png/1.1/Mon Oct 20 07:16:24 2003/-kb/
+/edit_remove.png/1.1/Mon Oct 20 07:16:25 2003/-kb/
+/editcopy.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/exit.png/1.1/Mon Oct 20 07:16:26 2003/-kb/
+/failed.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/filenew.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/fileopen.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/filesave.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/filesaveas.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/folder.png/1.1/Fri Apr 4 12:47:44 2003/-kb/
+/funct.png/1.1/Mon Oct 20 07:16:30 2003/-kb/
+/hourglass.png/1.1/Wed Sep 28 17:56:00 2005/-kb/
+/icon.gif/1.1/Sun Aug 28 21:13:00 2005/-kb/
+/launch.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/qt-logo.png/1.1/Wed Dec 14 17:02:26 2005/-kb/
+/reload.png/1.1/Mon Dec 16 23:41:14 2002/-kb/
+/result_small.png/1.1/Mon Oct 20 07:16:29 2003/-kb/
+/results.png/1.1/Mon Oct 20 07:11:58 2003/-kb/
+/setup.png/1.1/Sun Aug 14 17:45:15 2005/-kb/
+/simulation.png/1.1/Fri Jan 6 12:43:58 2006/-kb/
+/simulation_icon.png/1.1/Fri Jan 6 14:24:45 2006/-kb/
+/simulation_small.png/1.1/Thu Jun 29 20:43:26 2006/-kb/
+/simulation_tr.png/1.1/Fri Jan 6 14:23:52 2006/-kb/
+/up.png/1.1/Mon Oct 10 19:03:03 2005/-kb/
+/viewmag+.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/viewmag-.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/viewmagfit.png/1.1/Fri Apr 4 12:47:42 2003/-kb/
+/window_icon2.png/1.1/Mon Aug 29 14:17:00 2005/-kb/
+/work.png/1.1/Mon Oct 20 07:14:09 2003/-kb/
diff --git a/QCSXCAD/images/CVS/Repository b/QCSXCAD/images/CVS/Repository
new file mode 100644
index 0000000..d336c21
--- /dev/null
+++ b/QCSXCAD/images/CVS/Repository
@@ -0,0 +1 @@
+StaticSimulator/images
diff --git a/QCSXCAD/images/CVS/Root b/QCSXCAD/images/CVS/Root
new file mode 100644
index 0000000..800d2fc
--- /dev/null
+++ b/QCSXCAD/images/CVS/Root
@@ -0,0 +1 @@
+:extssh:coft@atex.ate.uni-duisburg.de:/srv/CVS
diff --git a/QCSXCAD/images/GeoEdit.png b/QCSXCAD/images/GeoEdit.png
new file mode 100644
index 0000000..2b4ed78
--- /dev/null
+++ b/QCSXCAD/images/GeoEdit.png
Binary files differ
diff --git a/QCSXCAD/images/ParaSetup.png b/QCSXCAD/images/ParaSetup.png
new file mode 100644
index 0000000..c49947f
--- /dev/null
+++ b/QCSXCAD/images/ParaSetup.png
Binary files differ
diff --git a/QCSXCAD/images/QCSXCAD_Icon.png b/QCSXCAD/images/QCSXCAD_Icon.png
new file mode 100644
index 0000000..a1530be
--- /dev/null
+++ b/QCSXCAD/images/QCSXCAD_Icon.png
Binary files differ
diff --git a/QCSXCAD/images/accept.png b/QCSXCAD/images/accept.png
new file mode 100644
index 0000000..a24d605
--- /dev/null
+++ b/QCSXCAD/images/accept.png
Binary files differ
diff --git a/QCSXCAD/images/bulb.png b/QCSXCAD/images/bulb.png
new file mode 100644
index 0000000..8d72794
--- /dev/null
+++ b/QCSXCAD/images/bulb.png
Binary files differ
diff --git a/QCSXCAD/images/bulb_off.png b/QCSXCAD/images/bulb_off.png
new file mode 100644
index 0000000..8407b89
--- /dev/null
+++ b/QCSXCAD/images/bulb_off.png
Binary files differ
diff --git a/QCSXCAD/images/cancel.png b/QCSXCAD/images/cancel.png
new file mode 100644
index 0000000..57fdcb9
--- /dev/null
+++ b/QCSXCAD/images/cancel.png
Binary files differ
diff --git a/QCSXCAD/images/close.png b/QCSXCAD/images/close.png
new file mode 100644
index 0000000..07e8886
--- /dev/null
+++ b/QCSXCAD/images/close.png
Binary files differ
diff --git a/QCSXCAD/images/configure.png b/QCSXCAD/images/configure.png
new file mode 100644
index 0000000..33ad550
--- /dev/null
+++ b/QCSXCAD/images/configure.png
Binary files differ
diff --git a/QCSXCAD/images/down.png b/QCSXCAD/images/down.png
new file mode 100644
index 0000000..9fd08a2
--- /dev/null
+++ b/QCSXCAD/images/down.png
Binary files differ
diff --git a/QCSXCAD/images/edit.png b/QCSXCAD/images/edit.png
new file mode 100644
index 0000000..1d69145
--- /dev/null
+++ b/QCSXCAD/images/edit.png
Binary files differ
diff --git a/QCSXCAD/images/edit_add.png b/QCSXCAD/images/edit_add.png
new file mode 100644
index 0000000..072ac68
--- /dev/null
+++ b/QCSXCAD/images/edit_add.png
Binary files differ
diff --git a/QCSXCAD/images/edit_remove.png b/QCSXCAD/images/edit_remove.png
new file mode 100644
index 0000000..78cb1de
--- /dev/null
+++ b/QCSXCAD/images/edit_remove.png
Binary files differ
diff --git a/QCSXCAD/images/editcopy.png b/QCSXCAD/images/editcopy.png
new file mode 100644
index 0000000..cfa9cb4
--- /dev/null
+++ b/QCSXCAD/images/editcopy.png
Binary files differ
diff --git a/QCSXCAD/images/exit.png b/QCSXCAD/images/exit.png
new file mode 100644
index 0000000..cade942
--- /dev/null
+++ b/QCSXCAD/images/exit.png
Binary files differ
diff --git a/QCSXCAD/images/failed.png b/QCSXCAD/images/failed.png
new file mode 100644
index 0000000..1cabc6e
--- /dev/null
+++ b/QCSXCAD/images/failed.png
Binary files differ
diff --git a/QCSXCAD/images/filenew.png b/QCSXCAD/images/filenew.png
new file mode 100644
index 0000000..8a303b7
--- /dev/null
+++ b/QCSXCAD/images/filenew.png
Binary files differ
diff --git a/QCSXCAD/images/fileopen.png b/QCSXCAD/images/fileopen.png
new file mode 100644
index 0000000..503a004
--- /dev/null
+++ b/QCSXCAD/images/fileopen.png
Binary files differ
diff --git a/QCSXCAD/images/filesave.png b/QCSXCAD/images/filesave.png
new file mode 100644
index 0000000..dd00abd
--- /dev/null
+++ b/QCSXCAD/images/filesave.png
Binary files differ
diff --git a/QCSXCAD/images/filesaveas.png b/QCSXCAD/images/filesaveas.png
new file mode 100644
index 0000000..61a080e
--- /dev/null
+++ b/QCSXCAD/images/filesaveas.png
Binary files differ
diff --git a/QCSXCAD/images/folder.png b/QCSXCAD/images/folder.png
new file mode 100644
index 0000000..b5e286a
--- /dev/null
+++ b/QCSXCAD/images/folder.png
Binary files differ
diff --git a/QCSXCAD/images/funct.png b/QCSXCAD/images/funct.png
new file mode 100644
index 0000000..4171db5
--- /dev/null
+++ b/QCSXCAD/images/funct.png
Binary files differ
diff --git a/QCSXCAD/images/hourglass.png b/QCSXCAD/images/hourglass.png
new file mode 100644
index 0000000..c3ffd08
--- /dev/null
+++ b/QCSXCAD/images/hourglass.png
Binary files differ
diff --git a/QCSXCAD/images/icon.gif b/QCSXCAD/images/icon.gif
new file mode 100644
index 0000000..35e9499
--- /dev/null
+++ b/QCSXCAD/images/icon.gif
Binary files differ
diff --git a/QCSXCAD/images/launch.png b/QCSXCAD/images/launch.png
new file mode 100644
index 0000000..5f61bea
--- /dev/null
+++ b/QCSXCAD/images/launch.png
Binary files differ
diff --git a/QCSXCAD/images/launch2.png b/QCSXCAD/images/launch2.png
new file mode 100644
index 0000000..50d8029
--- /dev/null
+++ b/QCSXCAD/images/launch2.png
Binary files differ
diff --git a/QCSXCAD/images/launch3.png b/QCSXCAD/images/launch3.png
new file mode 100644
index 0000000..cad0e5e
--- /dev/null
+++ b/QCSXCAD/images/launch3.png
Binary files differ
diff --git a/QCSXCAD/images/opening.png b/QCSXCAD/images/opening.png
new file mode 100644
index 0000000..9539266
--- /dev/null
+++ b/QCSXCAD/images/opening.png
Binary files differ
diff --git a/QCSXCAD/images/qt-logo.png b/QCSXCAD/images/qt-logo.png
new file mode 100644
index 0000000..a8b452e
--- /dev/null
+++ b/QCSXCAD/images/qt-logo.png
Binary files differ
diff --git a/QCSXCAD/images/reload.png b/QCSXCAD/images/reload.png
new file mode 100644
index 0000000..9cec493
--- /dev/null
+++ b/QCSXCAD/images/reload.png
Binary files differ
diff --git a/QCSXCAD/images/result_small.png b/QCSXCAD/images/result_small.png
new file mode 100644
index 0000000..00dc24a
--- /dev/null
+++ b/QCSXCAD/images/result_small.png
Binary files differ
diff --git a/QCSXCAD/images/results.png b/QCSXCAD/images/results.png
new file mode 100644
index 0000000..6f11252
--- /dev/null
+++ b/QCSXCAD/images/results.png
Binary files differ
diff --git a/QCSXCAD/images/setup.png b/QCSXCAD/images/setup.png
new file mode 100644
index 0000000..874c686
--- /dev/null
+++ b/QCSXCAD/images/setup.png
Binary files differ
diff --git a/QCSXCAD/images/simulation.png b/QCSXCAD/images/simulation.png
new file mode 100644
index 0000000..9983830
--- /dev/null
+++ b/QCSXCAD/images/simulation.png
Binary files differ
diff --git a/QCSXCAD/images/simulation_icon.png b/QCSXCAD/images/simulation_icon.png
new file mode 100644
index 0000000..8f249f3
--- /dev/null
+++ b/QCSXCAD/images/simulation_icon.png
Binary files differ
diff --git a/QCSXCAD/images/simulation_small.png b/QCSXCAD/images/simulation_small.png
new file mode 100644
index 0000000..801fa6a
--- /dev/null
+++ b/QCSXCAD/images/simulation_small.png
Binary files differ
diff --git a/QCSXCAD/images/simulation_tr.png b/QCSXCAD/images/simulation_tr.png
new file mode 100644
index 0000000..1552c45
--- /dev/null
+++ b/QCSXCAD/images/simulation_tr.png
Binary files differ
diff --git a/QCSXCAD/images/up.png b/QCSXCAD/images/up.png
new file mode 100644
index 0000000..6fe4ead
--- /dev/null
+++ b/QCSXCAD/images/up.png
Binary files differ
diff --git a/QCSXCAD/images/viewmag+.png b/QCSXCAD/images/viewmag+.png
new file mode 100644
index 0000000..15b2fa1
--- /dev/null
+++ b/QCSXCAD/images/viewmag+.png
Binary files differ
diff --git a/QCSXCAD/images/viewmag-.png b/QCSXCAD/images/viewmag-.png
new file mode 100644
index 0000000..18002f9
--- /dev/null
+++ b/QCSXCAD/images/viewmag-.png
Binary files differ
diff --git a/QCSXCAD/images/viewmagfit.png b/QCSXCAD/images/viewmagfit.png
new file mode 100644
index 0000000..2ef0fd5
--- /dev/null
+++ b/QCSXCAD/images/viewmagfit.png
Binary files differ
diff --git a/QCSXCAD/images/vtk-logo.png b/QCSXCAD/images/vtk-logo.png
new file mode 100644
index 0000000..4129025
--- /dev/null
+++ b/QCSXCAD/images/vtk-logo.png
Binary files differ
diff --git a/QCSXCAD/images/window_icon2.png b/QCSXCAD/images/window_icon2.png
new file mode 100644
index 0000000..a24d605
--- /dev/null
+++ b/QCSXCAD/images/window_icon2.png
Binary files differ
diff --git a/QCSXCAD/images/work.png b/QCSXCAD/images/work.png
new file mode 100644
index 0000000..e0dadb1
--- /dev/null
+++ b/QCSXCAD/images/work.png
Binary files differ
diff --git a/QCSXCAD/linux/QCSXCAD.dsc b/QCSXCAD/linux/QCSXCAD.dsc
new file mode 100644
index 0000000..49f13a5
--- /dev/null
+++ b/QCSXCAD/linux/QCSXCAD.dsc
@@ -0,0 +1,9 @@
+Format: 1.0
+Source: qcsxcad
+Version: 0.3.0-1
+Binary: qcsxcad, qcsxcad-dev
+Maintainer: Thorsten Liebig <thorsten.liebig@uni-due.de>, Sebastian Held <sebastian.held@gmx.de>
+Homepage: http://www.openems.de
+Architecture: any
+Build-Depends: debhelper (>=7.0.50~), libqt4-dev, qt4-qmake, libtinyxml-dev, libvtk5-qt4-dev, csxcad-dev
+DEBTRANSFORM-TAR: QCSXCAD-0.3.0.tar.bz2
diff --git a/QCSXCAD/linux/QCSXCAD.spec b/QCSXCAD/linux/QCSXCAD.spec
new file mode 100644
index 0000000..05579ca
--- /dev/null
+++ b/QCSXCAD/linux/QCSXCAD.spec
@@ -0,0 +1,115 @@
+#
+# spec file for package [spectemplate]
+#
+# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
+#
+# All modifications and additions to the file contributed by third parties
+# remain the property of their copyright owners, unless otherwise agreed
+# upon. The license for this file, and modifications and additions to the
+# file, is the same license as for the pristine package itself (unless the
+# license for the pristine package is not an Open Source License, in which
+# case the license is the MIT License). An "Open Source License" is a
+# license that conforms to the Open Source Definition (Version 1.9)
+# published by the Open Source Initiative.
+
+# Please submit bugfixes or comments via http://bugs.opensuse.org/
+#
+
+# norootforbuild
+
+Name: QCSXCAD
+Version: 0.3.0
+Release: 1
+Summary: Qt bindings for CSXCAD
+Group: Development/Languages/C and C++
+License: LGPLv3
+URL: http://www.openems.de
+Source0: %{name}-%{version}.tar.bz2
+Patch0: fedora17.diff
+# BuildArch: noarch
+BuildRoot: %_tmppath/%name-%version-build
+
+BuildRequires: libqt4-devel gcc-c++ tinyxml-devel vtk-devel vtk-qt CSXCAD-devel
+#Requires:
+
+
+# determine qt4 qmake executable
+%if 0%{?fedora}
+ %global qmake qmake-qt4
+%else
+ %global qmake qmake
+%endif
+
+
+
+%description
+Qt bindings for CSXCAD.
+
+%package -n lib%{name}0
+Summary: Shared Library for %{name}
+Group: Development/Languages/C and C++
+
+%description -n lib%{name}0
+The lib%{name}0 package contains the shared library.
+
+%package devel
+Summary: Development files for %{name}
+Group: Development/Languages/C and C++
+Requires: %{name} = %{version}-%{release}
+Requires: lib%{name}0 = %{version}-%{release}
+
+%description devel
+The %{name}-devel package contains libraries and header files for
+developing applications that use %{name}.
+
+
+%prep
+%setup -q
+%if 0%{?fedora} >= 17
+%patch0 -p1
+%endif
+
+%build
+%qmake QMAKE_CFLAGS="%optflags" QMAKE_CXXFLAGS="%optflags" LIB_SUFFIX="$(echo %_lib | cut -b4-)"
+make %{?_smp_mflags}
+
+
+%install
+make INSTALL_ROOT=%{buildroot} install
+find %{buildroot} -name '*.la' -exec rm -f {} ';'
+
+
+%clean
+rm -rf %{buildroot}
+
+
+%post -n lib%{name}0 -p /sbin/ldconfig
+
+%postun -n lib%{name}0 -p /sbin/ldconfig
+
+
+%files
+%defattr(-,root,root)
+%doc COPYING
+
+
+%files -n lib%{name}0
+%defattr(-,root,root)
+%{_libdir}/*.so.*
+
+
+%files devel
+%defattr(-,root,root)
+%{_includedir}/*
+%{_libdir}/*.so
+
+
+%changelog
+* Sun Jun 17 2012 Sebastian Held <sebastian.held@gmx.de> - 0.3.0-1
+- new upstream version
+* Thu Dec 29 2011 Sebastian Held <sebastian.held@gmx.de> - 0.1.3-3
+- new upstream version
+* Wed Dec 28 2011 Sebastian Held <sebastian.held@gmx.de> - 0.1.3-2
+- Fedora 16 build support
+* Sun Dec 04 2011 Sebastian Held <sebastian.held@gmx.de> - 0.1.3-1
+- initial version
diff --git a/QCSXCAD/linux/debian.changelog b/QCSXCAD/linux/debian.changelog
new file mode 100644
index 0000000..aa7f02a
--- /dev/null
+++ b/QCSXCAD/linux/debian.changelog
@@ -0,0 +1,9 @@
+qcsxcad (0.3.0-1) stable; urgency=low
+ * New upstream version
+ -- Sebastian Held <sebastian.held@gmx.de> Sun, 17 Jun 2012 21:51:14 +0200
+qcsxcad (0.1.3-2) stable; urgency=low
+ * New upstream version
+ -- Sebastian Held <sebastian.held@gmx.de> Thu, 29 Dec 2011 18:01:00 +0100
+qcsxcad (0.1.3-1) stable; urgency=low
+ * Initial Release
+ -- Sebastian Held <sebastian.held@gmx.de> Sun, 4 Dec 2011 19:03:00 +0100
diff --git a/QCSXCAD/linux/debian.control b/QCSXCAD/linux/debian.control
new file mode 100644
index 0000000..20286da
--- /dev/null
+++ b/QCSXCAD/linux/debian.control
@@ -0,0 +1,17 @@
+Source: qcsxcad
+Section: contrib/libdevel
+Priority: optional
+Maintainer: Sebastian Held <sebastian.held@gmx.de>
+Build-Depends: debhelper (>=7.0.50~), libqt4-dev, qt4-qmake, libtinyxml-dev, libvtk5-qt4-dev, csxcad-dev
+
+Package: qcsxcad
+Architecture: any
+Depends: ${shlibs:Depends}
+Description: Qt bindings for CSXCAD
+ Qt bindings for CSXCAD
+
+Package: qcsxcad-dev
+Architecture: any
+Depends: ${shlibs:Depends} qcsxcad (= ${binary:Version})
+Description: Development files for qcsxcad
+ The qcsxcad-dev package contains libraries and header files for developing applications that use qcsxcad.
diff --git a/QCSXCAD/linux/debian.rules b/QCSXCAD/linux/debian.rules
new file mode 100644
index 0000000..874a39c
--- /dev/null
+++ b/QCSXCAD/linux/debian.rules
@@ -0,0 +1,7 @@
+#!/usr/bin/make -f
+
+export DH_VERBOSE=1
+export DH_OPTIONS=-v
+
+%:
+ dh $@
diff --git a/QCSXCAD/linux/fedora17.diff b/QCSXCAD/linux/fedora17.diff
new file mode 100644
index 0000000..33c78b4
--- /dev/null
+++ b/QCSXCAD/linux/fedora17.diff
@@ -0,0 +1,13 @@
+diff --git a/QCSXCAD.pro b/QCSXCAD.pro
+index 7cbf438..7d9e75c 100644
+--- a/QCSXCAD.pro
++++ b/QCSXCAD.pro
+@@ -79,7 +79,7 @@ unix {
+ /usr/include/vtk-5.10 \
+ /usr/include/vtk
+ INCLUDEPATH += /usr/include/CSXCAD
+- LIBS += -lvtkCommon \
++ LIBS += -L/usr/lib/vtk -L/usr/lib64/vtk -lvtkCommon \
+ -lvtkDICOMParser \
+ -lvtkFiltering \
+ -lvtkGenericFiltering \
diff --git a/QCSXCAD/resources.qrc b/QCSXCAD/resources.qrc
new file mode 100644
index 0000000..3a223d0
--- /dev/null
+++ b/QCSXCAD/resources.qrc
@@ -0,0 +1,49 @@
+<!DOCTYPE RCC>
+<RCC version="1.0">
+ <qresource>
+ <file>images/QCSXCAD_Icon.png</file>
+ <file>images/accept.png</file>
+ <file>images/failed.png</file>
+ <file>images/hourglass.png</file>
+ <file>images/qt-logo.png</file>
+ <file>images/vtk-logo.png</file>
+ <file>images/simulation_tr.png</file>
+ <file>images/simulation_small.png</file>
+ <file>images/simulation_icon.png</file>
+ <file>images/filesave.png</file>
+ <file>images/filesaveas.png</file>
+ <file>images/fileopen.png</file>
+ <file>images/filenew.png</file>
+ <file>images/exit.png</file>
+ <file>images/results.png</file>
+ <file>images/work.png</file>
+ <file>images/setup.png</file>
+ <file>images/GeoEdit.png</file>
+ <file>images/ParaSetup.png</file>
+ <file>images/launch.png</file>
+ <file>images/launch2.png</file>
+ <file>images/launch3.png</file>
+ <file>images/result_small.png</file>
+ <file>images/configure.png</file>
+ <file>images/down.png</file>
+ <file>images/up.png</file>
+ <file>images/funct.png</file>
+ <file>images/edit_remove.png</file>
+ <file>images/edit_add.png</file>
+ <file>images/edit.png</file>
+ <file>images/reload.png</file>
+ <file>images/cancel.png</file>
+ <file>images/close.png</file>
+ <file>images/viewmagfit.png</file>
+ <file>images/viewmag-.png</file>
+ <file>images/viewmag+.png</file>
+ <file>images/bulb.png</file>
+ <file>images/bulb_off.png</file>
+ <file>images/editcopy.png</file>
+ <file>images/folder.png</file>
+ <file>images/ArrowsXY.png</file>
+ <file>images/ArrowsXZ.png</file>
+ <file>images/ArrowsYZ.png</file>
+ <file>images/opening.png</file>
+ </qresource>
+</RCC>
diff --git a/QCSXCAD/vtkInteractorStyleRubberBand2DPlane.cpp b/QCSXCAD/vtkInteractorStyleRubberBand2DPlane.cpp
new file mode 100644
index 0000000..1bd9bdf
--- /dev/null
+++ b/QCSXCAD/vtkInteractorStyleRubberBand2DPlane.cpp
@@ -0,0 +1,73 @@
+/*
+* Copyright (C) 2010-2013 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "vtkInteractorStyleRubberBand2DPlane.h"
+
+#include "vtkCamera.h"
+#include "vtkCommand.h"
+#include "vtkObjectFactory.h"
+#include "vtkRenderer.h"
+#include "vtkRenderWindow.h"
+#include "vtkRenderWindowInteractor.h"
+
+vtkStandardNewMacro(vtkInteractorStyleRubberBand2DPlane);
+
+vtkInteractorStyleRubberBand2DPlane::vtkInteractorStyleRubberBand2DPlane() : vtkInteractorStyleRubberBand2D()
+{
+}
+
+void vtkInteractorStyleRubberBand2DPlane::OnMouseMove()
+{
+ if (this->Interaction == PANNING)
+ {
+ vtkRenderWindowInteractor* rwi = this->GetInteractor();
+ int lastPt[] = {0, 0};
+ rwi->GetLastEventPosition(lastPt);
+ int curPt[] = {0, 0};
+ rwi->GetEventPosition(curPt);
+
+ vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
+ double lastScale = 2.0 * camera->GetParallelScale() / this->CurrentRenderer->GetSize()[1];
+ double lastFocalPt[] = {0, 0, 0};
+ camera->GetFocalPoint(lastFocalPt);
+ double lastPos[] = {0, 0, 0};
+ camera->GetPosition(lastPos);
+
+ double dop[3];
+ camera->GetDirectionOfProjection(dop);
+
+ int n_dir=-1;
+ for (int n=0;n<3;++n)
+ if ((dop[n]!=0) && (dop[(n+1)%2]==0) && (dop[(n+2)%3]==0))
+ n_dir = n;
+ if (n_dir<0)
+ {
+ cerr << __func__ << ": Error, no view in x-, y- or z-direction, skipping panning!";
+ return;
+ }
+
+ double delta[] = {0, 0, 0};
+ delta[(n_dir+1)%3] = -lastScale*(curPt[0] - lastPt[0]);
+ delta[(n_dir+2)%3] = -lastScale*(curPt[1] - lastPt[1]);
+ camera->SetFocalPoint(lastFocalPt[0] + delta[0], lastFocalPt[1] + delta[1], lastFocalPt[2] + delta[2]);
+ camera->SetPosition(lastPos[0] + delta[0], lastPos[1] + delta[1], lastPos[2] + delta[2]);
+ this->InvokeEvent(vtkCommand::InteractionEvent);
+ rwi->Render();
+ }
+ else
+ vtkInteractorStyleRubberBand2D::OnMouseMove();
+}
diff --git a/QCSXCAD/vtkInteractorStyleRubberBand2DPlane.h b/QCSXCAD/vtkInteractorStyleRubberBand2DPlane.h
new file mode 100644
index 0000000..62725b9
--- /dev/null
+++ b/QCSXCAD/vtkInteractorStyleRubberBand2DPlane.h
@@ -0,0 +1,35 @@
+/*
+* Copyright (C) 2010-2013 Thorsten Liebig (Thorsten.Liebig@gmx.de)
+*
+* This program 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 3 of the License, or
+* (at your option) any later version.
+*
+* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef VTKINTERACTORSTYLERUBBERBAND2DPLANE_H
+#define VTKINTERACTORSTYLERUBBERBAND2DPLANE_H
+
+#include "vtkInteractorStyleRubberBand2D.h"
+
+class vtkInteractorStyleRubberBand2DPlane : public vtkInteractorStyleRubberBand2D
+{
+public:
+ static vtkInteractorStyleRubberBand2DPlane *New();
+ vtkTypeMacro(vtkInteractorStyleRubberBand2DPlane, vtkInteractorStyle);
+
+ virtual void OnMouseMove();
+
+protected:
+ vtkInteractorStyleRubberBand2DPlane();
+};
+
+#endif // VTKINTERACTORSTYLERUBBERBAND2DPLANE_H