Commit 45883d7a authored by reichenbach's avatar reichenbach

[MERGE]

parents 12d73a8a 66434683
......@@ -26,7 +26,6 @@
####################################################################
# Toolbars
# useToolBarBreak = no # put compatibles toolbar in separate row
useAutoDisplay = no # automatically add a standard module after loading a data module.
# The next property controls the style of ALL toolbars in OpenWalnut.
......@@ -37,24 +36,9 @@ useAutoDisplay = no # automatically add a standard module after loading a data m
toolBarStyle = 0
compatiblesToolBarStyle = 0 # this pref allows the compatibles toolbar to have a different style (overrides toolBarStyle)
# Position of the compatibles toolbar
# 0 -> top
# 1 -> bottom
# 2 -> left
# 3 -> right
# 4 -> hide completely
# 5 -> inside the control panel ( not possible for compatiblesToolBarPos! This will be mapped to right (=3) )
toolBarPos = 0 # default position of the toolbars
compatiblesToolBarPos = 0 # position of the compatibles toolbar (overrides toolBarPos)
####################################################################
# Control panel
# combineTreeAndRoiAndTextureSorter = yes # should the module tree, ROI tree and the Texture Sorter be combined in ONE Tab widget?
# dsbWidth = 400 # the width of the control panel
# dsbInvisibleByDefault = yes # hide the control panel on startup. Can be shown using F9.
# dsbFloatingByDefault = yes # should the control panel be undocked on startup?
# Here you can put any key sequence you would like to result in removing modules or ROIs
# Examples:
# deleteKey = Backspace
......@@ -66,6 +50,14 @@ deleteROIKey = Del
####################################################################
# Other GUI settings
# With this option, you are able to let OpenWalnut load another window state. OpenWalnut stores and resotres the window
# positions, sizes and so on on quit and startup. If you are an developer and have multiple compiled OW versions and you want
# each version to have other window state files set some name here which is unique.
# stateNamePostfix = someName
# This option allows you to turn off that the GUI stores its state.
# saveState = no
# hideMenuBar = yes # hide the menu bar
[ge] ## Settings for the graphics engine
......
......@@ -29,7 +29,6 @@ whiteList = Arbitrary Plane,Coordinate System,Image Extractor,Paint Texture,Arbi
####################################################################
# Toolbars
# useToolBarBreak = no # put compatibles toolbar in separate row
# useAutoDisplay = no # automatically add a standard module after loading a data module.
# The next property controls the style of ALL toolbars in OpenWalnut.
......@@ -40,24 +39,9 @@ whiteList = Arbitrary Plane,Coordinate System,Image Extractor,Paint Texture,Arbi
toolBarStyle = 0
compatiblesToolBarStyle = 0 # this pref allows the compatibles toolbar to have a different style (overrides toolBarStyle)
# Position of the compatibles toolbar
# 0 -> top
# 1 -> bottom
# 2 -> left
# 3 -> right
# 4 -> hide completely
# 5 -> inside the control panel ( not possible for compatiblesToolBarPos! This will be mapped to right (=3) )
toolBarPos = 0 # default position of the toolbars
compatiblesToolBarPos = 0 # position of the compatibles toolbar (overrides toolBarPos)
####################################################################
# Control panel
# combineTreeAndRoiAndTextureSorter = yes # should the module tree, ROI tree and the Texture Sorter be combined in ONE Tab widget?
# dsbWidth = 400 # the width of the control panel
# dsbInvisibleByDefault = yes # hide the control panel on startup. Can be shown using F9.
# dsbFloatingByDefault = yes # should the control panel be undocked on startup?
# Here you can put any key sequence you would like to result in removing modules or ROIs
# Examples:
# deleteKey = Backspace
......@@ -69,6 +53,14 @@ deleteROIKey = Del
####################################################################
# Other GUI settings
# With this option, you are able to let OpenWalnut load another window state. OpenWalnut stores and resotres the window
# positions, sizes and so on on quit and startup. If you are an developer and have multiple compiled OW versions and you want
# each version to have other window state files set some name here which is unique.
# stateNamePostfix = someName
# This option allows you to turn off that the GUI stores its state.
# saveState = no
# hideMenuBar = yes # hide the menu bar
[ge] ## Settings for the graphics engine
......
......@@ -107,7 +107,7 @@ osg::ref_ptr< osg::Image > wge::genWhiteNoiseImage( size_t sizeX, size_t sizeY,
for( size_t i = 0; i < channels * sizeX * sizeY * sizeZ; ++i )
{
// - stylechecker says "use rand_r" but I am not sure about portability.
unsigned char r = ( unsigned char )( std::rand() % 255 ); // NOLINT
unsigned char r = static_cast< unsigned char >( std::rand() % 255 ); // NOLINT - no we want std::rand instead of rand_r
randomLuminance[ i ] = r;
}
......
......@@ -12,7 +12,6 @@ SET( QT_LIBS ${QT_QTCORE_LIBRARY}
# add here all classes that inherit from QObject
SET(GUI_QT4_MOC_HDRS
WMainWindow.h
WQtConfigWidget.h
WQtNavGLWidget.h
WQtGLWidget.h
WQtCombinerToolbar.h
......@@ -35,9 +34,18 @@ SET(GUI_QT4_MOC_HDRS
controlPanel/WQtTreeWidget.h
controlPanel/WQtTreeItem.h
controlPanel/WQtTextureSorter.h
networkEditor/WQtNetworkEditor.h
networkEditor/WQtNetworkScene.h
networkEditor/WQtNetworkItem.h
networkEditor/WQtNetworkPort.h
networkEditor/WQtNetworkInputPort.h
networkEditor/WQtNetworkOutputPort.h
networkEditor/WQtNetworkArrow.h
commandPrompt/WQtCommandPromptToolbar.h
commandPrompt/WQtCommandPrompt.h
)
IF( CMAKE_HOST_SYSTEM MATCHES Darwin )
LIST( APPEND GUI_QT4_MOC_HDRS platformDependent/WQtGLWidgetMac.h )
LIST( APPEND GUI_QT4_MOC_HDRS platformDependent/WQtGLWidgetMac.h )
ELSE()
IF( CMAKE_GENERATOR MATCHES "Visual Studio" )
......@@ -49,23 +57,24 @@ ENDIF()
QT4_WRAP_CPP(GUI_QT4_MOC_SRCS ${GUI_QT4_MOC_HDRS} )
FILE(GLOB GUI_QT4_SRC "*.cpp" "guiElements/*.cpp" "controlPanel/*.cpp" "ribbonMenu/*.cpp" "events/*.cpp" "*.h" "guiElements/*.h" "controlPanel/*.h" "ribbonMenu/*.h" "events/*.h" "../icons/WIcons.h" )
FILE(GLOB GUI_QT4_SRC "*.cpp" "guiElements/*.cpp" "controlPanel/*.cpp" "events/*.cpp" "networkEditor/*.cpp" "*.h" "guiElements/*.h"
"controlPanel/*.h" "events/*.h" "networkEditor/*.h" "../icons/WIcons.h" "commandPrompt/*.h" "commandPrompt/*.cpp" )
IF( CMAKE_HOST_SYSTEM MATCHES Darwin )
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetMac.cpp"
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetMac.cpp"
"platformDependent/WQtGLWidgetMac.h" )
ELSE()
IF( CMAKE_GENERATOR MATCHES "Visual Studio" )
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetWin.cpp"
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetWin.cpp"
"platformDependent/WQtGLWidgetWin.h" )
ELSE( CMAKE_GENERATOR MATCHES "Visual Studio" )
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetAll.cpp"
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetAll.cpp"
"platformDependent/WQtGLWidgetAll.h" )
ENDIF( CMAKE_GENERATOR MATCHES "Visual Studio" )
ENDIF()
SET( LIB_NAME "${OWguiqt4Name}" )
SET( ${LIB_NAME}_COMBINER_SRC ${GUI_QT4_SRC} ${GUIQT4_PLATFORMDEPENDENT_SRC} ${GUI_QT4_MOC_SRCS} )
......@@ -79,14 +88,14 @@ LIST( REMOVE_ITEM ${LIB_NAME}_ALL_CPP_WITHOUT_MOC ${${LIB_NAME}_REMOVE_H} )
IF( OW_BUILD_AS_ONE_BIG_FILE )
SET( UNITY_BUILD_FILE_NAME "${LIB_NAME}UnityBuildFile.cpp" )
GENERATE_UNITY_BUILD_FILE( ${LIB_NAME}_ALL_CPP )
ADD_LIBRARY( ${LIB_NAME} ${UNITY_BUILD_FILE_NAME} ${${LIB_NAME}_COMBINER_SRC} )
ENDIF( OW_BUILD_AS_ONE_BIG_FILE )
IF( NOT OW_BUILD_AS_ONE_BIG_FILE )
ADD_LIBRARY( ${LIB_NAME} ${${LIB_NAME}_COMBINER_SRC} )
ENDIF( NOT OW_BUILD_AS_ONE_BIG_FILE )
#IF( OW_BUILD_AS_ONE_BIG_FILE )
# SET( ALL_GUI_QT4_COMBINER_SRC ${GUI_QT4_SRC} ${GUIQT4_PLATFORMDEPENDENT_SRC} ${GUI_QT4_MOC_SRCS} )
# SET( UNITY_BUILD_FILE_NAME "GuiQt4UnityBuildFile.cpp" )
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut 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.
//
// OpenWalnut 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 OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <QtCore/QString>
#include "../../common/WStringUtils.h"
#include "WCfgOperations.h"
std::vector< std::string > WCfgOperations::readCfg( const std::string fileName )
{
std::ifstream ifs( fileName.c_str(), std::ifstream::in );
std::vector< std::string > lines;
std::string line;
while ( !ifs.eof() )
{
getline( ifs, line );
lines.push_back( std::string( line ) );
}
ifs.close();
return lines;
}
void WCfgOperations::writeCfg( const std::string fileName, const std::vector< std::string > lines )
{
std::ofstream ofs( fileName.c_str(), std::ofstream::out | std::ios_base::binary );
std::stringstream mendl;
mendl << std::endl;
if ( !ofs )
{
std::cout << "A problem occurred while writing " << fileName << std::endl;
std::cout << "File might be write protected, you may have no writing rights or disc is full" << std::endl;
std::cout << "File would look like: " << std::endl << std::endl;
for ( size_t i = 0; i < lines.size(); ++i )
{
std::cout << lines[i];
// if there is no newline character add it
if ( (lines[i]).find( mendl.str() ) == std::string::npos )
{
std::cout << std::endl;
}
}
std::cout << std::endl;
return;
}
for ( size_t i = 0; i < lines.size(); ++i )
{
ofs << lines[i];
// if there is no newline character add it
if ( (lines[i]).find( mendl.str() ) == std::string::npos )
{
ofs << std::endl;
}
}
ofs.close();
}
bool WCfgOperations::isComment( const std::string line )
{
if ( line.length() == 0 )
{
return false;
}
return string_utils::lTrim( line )[0] == '#';
}
bool WCfgOperations::isAssignment( const std::string line )
{
if ( line.length() == 0 )
{
return false;
}
// a comment is never an Assignment
if ( isComment( line ) )
{
return false;
}
// no equals sign means no assignment
if ( line.find( '=' ) == std::string::npos )
{
return false;
}
// left and right from equals there has to be at least one none whitespace char
bool hasLeftChar = false;
bool hasRightChar = false;
std::string toTest = removeComment( line );
size_t p = toTest.find( '=' );
size_t i;
for ( i = 0; i < p - 1; ++i )
{
if ( toTest[i] != ' ' )
{
hasLeftChar = true;
}
}
for ( i = p + 1; i < toTest.length(); ++i )
{
if ( toTest[i] != ' ' )
{
hasRightChar = true;
}
}
return hasLeftChar && hasRightChar;
}
std::string WCfgOperations::removeComment( const std::string line )
{
std::string lineWithoutComment = line;
size_t p = lineWithoutComment.find( '#' );
if ( p == std::string::npos )
{
return lineWithoutComment;
}
lineWithoutComment.erase( p, lineWithoutComment.length() - p );
return lineWithoutComment;
}
void WCfgOperations::getAssignementComponents( const std::string line, std::string *left, std::string *right )
{
if ( !isAssignment( line ) )
{
return;
}
size_t p = line.find( '=' );
( *left ) = removeComment( line );
left->erase( p, left->length() - p );
( *left ) = string_utils::trim( *left );
( *right ) = removeComment( line );
right->erase( 0, p + 1 );
( *right ) = string_utils::trim( *right );
}
bool WCfgOperations::isCommentedAssignment( const std::string line )
{
std::string toTest = line;
if ( !isComment( line ) )
{
return false;
}
while ( isComment( toTest ) )
{
toTest = string_utils::lTrim( toTest, "#" );
}
return isAssignment( toTest );
}
bool WCfgOperations::isSection( const std::string line )
{
bool res = false;
size_t leftB = line.find( '[' );
size_t rightB = line.find( ']' );
size_t comment = line.find( '#' );
if ( leftB != std::string::npos && rightB != std::string::npos && leftB < rightB && ( comment == std::string::npos || rightB < comment ) )
{
res = true;
}
return res;
}
std::string WCfgOperations::getSectionName( const std::string line )
{
std::string res = line;
if ( isSection(res) )
{
size_t leftB = res.find( '[' );
res.erase( 0, leftB + 1 );
size_t rightB = res.find( ']' );
res.erase( rightB, res.length() - rightB );
}
else
{
res = std::string( "" );
}
return res;
}
std::string WCfgOperations::uncommentLine( const std::string line )
{
std::string res = line;
if ( !isComment( res ) )
{
return res;
}
while ( res.length() > 0 && ( res[0] == '#' || res[0] == '\t' || res[0] == ' ' ) )
{
res.erase( 0, 1 );
}
return res;
}
bool WCfgOperations::isBool( const std::string line )
{
bool res = false;
if ( line == std::string( "yes" ) || line == std::string( "no" ) )
{
res = true;
}
return res;
}
bool WCfgOperations::getAsBool( const std::string line )
{
bool res = false;
if ( line == std::string( "yes" ) )
{
res = true;
}
return res;
}
bool WCfgOperations::isInt( const std::string line )
{
bool res = false;
QString l2 = QString::fromStdString( line );
l2.toInt( &res );
return res;
}
int WCfgOperations::getAsInt( const std::string line )
{
bool ok = false;
QString l2 = QString::fromStdString( line );
int res = l2.toInt( &ok );
if ( !ok )
{
res = 0;
}
return res;
}
bool WCfgOperations::isDouble( const std::string line )
{
bool res = false;
QString l2 = QString::fromStdString( line );
l2.toDouble( &res );
return res;
}
double WCfgOperations::getAsDouble( const std::string line )
{
bool ok = false;
QString l2 = QString::fromStdString( line );
double res = l2.toDouble( &ok );
if ( !ok )
{
res = 0.0;
}
return res;
}
bool WCfgOperations::isString( const std::string line, bool useColon )
{
bool res = false;
if ( useColon )
{
if ( line.length() > 1 && line[0] == '\"' && line[line.length() - 1] == '\"' )
{
res = true;
}
}
else
{
res = line.length() > 0;
}
return res;
}
std::string WCfgOperations::getAsString( const std::string line, bool useColon )
{
std::string res = line;
if ( useColon )
{
if ( !isString( line ) )
{
return std::string( "" );
}
res.erase( 0, 1 );
res.erase( res.length() - 1, 1 );
}
return res;
}
std::string WCfgOperations::getPropValAsString( boost::shared_ptr< WProperties > prop, bool useColon )
{
std::string result = "";
switch ( prop->getType() )
{
case PV_STRING:
{
result = prop->toPropString()->get();
if ( useColon )
result = "\"" + result + "\"";
break;
}
case PV_BOOL:
{
if ( prop->toPropBool()->get() == true )
{
result = "yes";
}
else
{
result = "no";
}
break;
}
case PV_DOUBLE:
{
result = boost::lexical_cast< std::string >( prop->toPropDouble()->get() );
// make sure to only have a max of 2 digits after the dot, and if there is only a 0 before the
// dot to delete that
if ( result[0] == '0' && result.find( '.' ) == 1 )
{
result.erase( 0, 1 );
}
size_t digitsAfterDot;
size_t dotPos = result.find( '.' );
if ( dotPos != std::string::npos )
{
digitsAfterDot = result.length() - ( dotPos + 1 );
if ( digitsAfterDot > 2 )
{
result.erase( dotPos + 3, result.length() - dotPos - 3 );
}
}
// also remove the last zeros if they are not directly after the dot
if ( result.length() > 2 ) // at least a dot and and digit
{
while ( result[ result.length() - 1 ] == '0' )
{
dotPos = result.find( '.' );
if ( dotPos + 2 < result.length() )
{
result.erase( result.length() - 1, 1 );
}
else
{
break;
}
}
}
break;
}
case PV_INT:
{
result = boost::lexical_cast< std::string >( prop->toPropInt()->get() );
break;
}
default:
{
result = "";
break;
}
}
return result;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut 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.
//
// OpenWalnut 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 OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WCFGOPERATIONS_H
#define WCFGOPERATIONS_H
#include <string>
#include <vector>
#include "../../common/WProperties.h"
/**
* static class that provides string and file operation functions
* to operate on a config file
*/
class WCfgOperations
{
public: