Commit d738a486 authored by hungdangquoc's avatar hungdangquoc
Browse files

[ADD #132]_user_is_able_to_select_valid_columns

parent da76bf5b
//---------------------------------------------------------------------------
//
// 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 <string>
#include "WDatatype.h"
std::string WDatatype::getInt()
{
return "int";
}
std::string WDatatype::getDouble()
{
return "double";
}
std::string WDatatype::getString()
{
return "string";
}
//---------------------------------------------------------------------------
//
// 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 WDATATYPE_H
#define WDATATYPE_H
#include <string>
/**
* Holds the datatypes as string
*/
class WDatatype
{
public:
/**
* getter
* \return datatype int as string
*/
static std::string getInt();
/**
* getter
* \return datatype double as string
*/
static std::string getDouble();
/**
* getter
* \return datatype string as string
*/
static std::string getString();
};
#endif // WDATATYPE_H
......@@ -143,14 +143,31 @@ std::string WProtonData::determineColumnTypeByString( std::string cellValue )
if( std::regex_search( cellValue, regexInt ) )
{
return "int";
return WDatatype::getInt();
}
else if( std::regex_search( cellValue, regexDouble ) )
{
return "double";
return WDatatype::getDouble();
}
else
{
return "string";
return WDatatype::getString();
}
}
std::vector< std::string > WProtonData::getHeaderFromType( std::string typeName )
{
std::vector< std::string > header = m_csvHeader->at( 0 );
std::vector< std::string > columnTypes = *m_columnTypes;
std::vector< std::string > filterHeader;
for( size_t i = 0; i < columnTypes.size(); i++)
{
if( columnTypes[i] == typeName )
{
filterHeader.push_back( header[i] );
}
}
return filterHeader;
}
......@@ -28,8 +28,10 @@
#include <regex>
#include <map>
#include <string>
#include <vector>
#include "core/dataHandler/WDataSetCSV.h"
#include "WDatatype.h"
/**
......@@ -121,6 +123,13 @@ public:
*/
WDataSetCSV::ContentElemSPtr getColumnTypes();
/**
* Return a vector of filtered Headers
* \param type Type of filter
* \return Return a vector of filtered Headers
*/
std::vector< std::string > getHeaderFromType( std::string typeName );
private:
/**
* Stores column index of data.
......
......@@ -62,61 +62,75 @@ std::string WSingleSelectorName::getParentId()
return "Parent id";
}
WSingleSelectorName::NameDescriptionSearch WSingleSelectorName::getXwithDescription()
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getXwithDescription()
{
return WSingleSelectorName::NameDescriptionSearch( getX(),
return WSingleSelectorName::NameDescriptionSearchTyp(
getX(),
"Choose the column which should be used to determine the x coordinate.",
"posX" );
"posX",
WDatatype::getDouble() );
}
WSingleSelectorName::NameDescriptionSearch WSingleSelectorName::getYwithDescription()
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getYwithDescription()
{
return WSingleSelectorName::NameDescriptionSearch( getY(),
return WSingleSelectorName::NameDescriptionSearchTyp(
getY(),
"Choose the column which should be used to determine the y coordinate.",
"posY" );
"posY",
WDatatype::getDouble() );
}
WSingleSelectorName::NameDescriptionSearch WSingleSelectorName::getZwithDescription()
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getZwithDescription()
{
return WSingleSelectorName::NameDescriptionSearch( getZ(),
return WSingleSelectorName::NameDescriptionSearchTyp(
getZ(),
"Choose the column which should be used to determine the z coordinate.",
"posZ" );
"posZ",
WDatatype::getDouble() );
}
WSingleSelectorName::NameDescriptionSearch WSingleSelectorName::getPDGwithDescription()
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getPDGwithDescription()
{
return WSingleSelectorName::NameDescriptionSearch( getPDG(),
return WSingleSelectorName::NameDescriptionSearchTyp(
getPDG(),
"Choose the column which should be used to determine the particle data group.",
"PDGEncoding" );
"PDGEncoding",
WDatatype::getInt() );
}
WSingleSelectorName::NameDescriptionSearch WSingleSelectorName::getEdepWithDescription()
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getEdepWithDescription()
{
return WSingleSelectorName::NameDescriptionSearch( getEdep(),
return WSingleSelectorName::NameDescriptionSearchTyp(
getEdep(),
"Choose the column which should be used to determine the energy deposition.",
"edep" );
"edep",
WDatatype::getDouble() );
}
WSingleSelectorName::NameDescriptionSearch WSingleSelectorName::getEventIdWithDescription()
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getEventIdWithDescription()
{
return WSingleSelectorName::NameDescriptionSearch( getEventId(),
return WSingleSelectorName::NameDescriptionSearchTyp(
getEventId(),
"Choose the column which should be used to determine the event id."
"Tracks will be drawn based on the the event id, all particles with the same event id will be connected.",
"eventID" );
"eventID",
WDatatype::getInt() );
}
WSingleSelectorName::NameDescriptionSearch WSingleSelectorName::getParentIdWithDescription()
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getParentIdWithDescription()
{
return WSingleSelectorName::NameDescriptionSearch( getParentId(),
return WSingleSelectorName::NameDescriptionSearchTyp(
getParentId(),
"Choose the column which should be used to determine the parent id."
"Primaries and secondaries filtering is based on that id, if a "
"particle has the parent id 0 it is a primary otherwise it is a secondary.",
"parentID" );
"parentID",
WDatatype::getInt() );
}
std::list< WSingleSelectorName::NameDescriptionSearch > WSingleSelectorName::getListOfSelectorContent()
std::list< WSingleSelectorName::NameDescriptionSearchTyp > WSingleSelectorName::getListOfSelectorContent()
{
std::list< WSingleSelectorName::NameDescriptionSearch > list;
std::list< WSingleSelectorName::NameDescriptionSearchTyp > list;
list.push_back( getXwithDescription() );
list.push_back( getYwithDescription() );
......
......@@ -29,6 +29,8 @@
#include <list>
#include <string>
#include "WDatatype.h"
/**
* Holds the single selector content.
......@@ -42,7 +44,7 @@ public:
* 2. Desciption of single-selector,
* 3. Value that is searched for in the csv header
*/
typedef std::tuple< std::string, std::string , std::string > NameDescriptionSearch;
typedef std::tuple< std::string, std::string, std::string, std::string > NameDescriptionSearchTyp;
/**
* getter
......@@ -90,49 +92,49 @@ public:
* getter
* \return the name of the single-selector (X) with Description
*/
static WSingleSelectorName::NameDescriptionSearch getXwithDescription();
static WSingleSelectorName::NameDescriptionSearchTyp getXwithDescription();
/**
* getter
* \return the name of the single-selector (Y) with Description
*/
static WSingleSelectorName::NameDescriptionSearch getYwithDescription();
static WSingleSelectorName::NameDescriptionSearchTyp getYwithDescription();
/**
* getter
* \return the name of the single-selector (Z) with Description
*/
static WSingleSelectorName::NameDescriptionSearch getZwithDescription();
static WSingleSelectorName::NameDescriptionSearchTyp getZwithDescription();
/**
* getter
* \return the name of the single-selector (pdg) with Description
*/
static WSingleSelectorName::NameDescriptionSearch getPDGwithDescription();
static WSingleSelectorName::NameDescriptionSearchTyp getPDGwithDescription();
/**
* getter
* \return the name of the single-selector (edep) with Description
*/
static WSingleSelectorName::NameDescriptionSearch getEdepWithDescription();
static WSingleSelectorName::NameDescriptionSearchTyp getEdepWithDescription();
/**
* getter
* \return the name of the single-selector (Event id) with Description
*/
static WSingleSelectorName::NameDescriptionSearch getEventIdWithDescription();
static WSingleSelectorName::NameDescriptionSearchTyp getEventIdWithDescription();
/**
* getter
* \return the name of the single-selector (Parent id) with Description
*/
static WSingleSelectorName::NameDescriptionSearch getParentIdWithDescription();
static WSingleSelectorName::NameDescriptionSearchTyp getParentIdWithDescription();
/**
* getter
* \return Vector of names of the single-selectors with Description and Value that is searched for in the csv header
*/
static std::list< WSingleSelectorName::NameDescriptionSearch > getListOfSelectorContent();
static std::list< WSingleSelectorName::NameDescriptionSearchTyp > getListOfSelectorContent();
};
#endif // WSINGLESELECTORNAME_H
......@@ -44,19 +44,15 @@ void WColumnPropertyHandler::createProperties()
WPropertyBase::PropertyChangeNotifierType notifier = boost::bind( &WColumnPropertyHandler::propertyNotifier,
this, boost::placeholders::_1 );
InitializeSelectionItem();
m_columnSelectionGroup = m_properties->addPropertyGroup( "Select columns", "Select the columns which should be used" );
std::list< std::tuple< std::string, std::string, std::string > > names = WSingleSelectorName::getListOfSelectorContent();
for( std::tuple< std::string, std::string, std::string > selectorElement : names )
std::list< std::tuple< std::string, std::string, std::string, std::string > > names = WSingleSelectorName::getListOfSelectorContent();
for( std::tuple< std::string, std::string, std::string, std::string > selectorElement : names )
{
std::string columnName = std::get< 0 >( selectorElement );
std::string desciption = std::get< 1 >( selectorElement );
std::string defName = std::get< 2 >( selectorElement );
mapPropSelectionsToString.insert(
std::map< WPropSelection, std::string >::value_type( addHeaderProperty( columnName, desciption, defName, notifier ), columnName )
std::map< WPropSelection, std::string >::value_type( addHeaderProperty( selectorElement, notifier ), columnName )
);
}
}
......@@ -70,27 +66,66 @@ void WColumnPropertyHandler::updateProperty()
{
}
void WColumnPropertyHandler::InitializeSelectionItem()
boost::shared_ptr< WItemSelection > WColumnPropertyHandler::InitializeSelectionItem( std::string typeName )
{
m_possibleSelectionsUsingTypes = WItemSelection::SPtr( new WItemSelection() );
boost::shared_ptr< WItemSelection > possibleSelectionsUsingTypes = WItemSelection::SPtr( new WItemSelection() );
std::vector< std::string > header = m_protonData->getHeaderFromType( typeName );
std::vector< std::string > header = m_protonData->getCSVHeader()->at( 0 );
for( std::vector<std::string>::iterator colName = header.begin(); colName != header.end(); colName++ )
{
m_possibleSelectionsUsingTypes->addItem( ItemType::create( *colName, *colName, "", NULL ) );
possibleSelectionsUsingTypes->addItem( ItemType::create( *colName, *colName, "", NULL ) );
}
possibleSelectionsUsingTypes->addItem( ItemType::create( "- no selection -", "- no selection -", "", NULL ) );
return possibleSelectionsUsingTypes;
}
int WColumnPropertyHandler::getfilterIndex( int index, std::string typeName )
{
std::vector< std::string > headerToSearch = m_protonData->getCSVHeader()->at( 0 );
std::string refheader = headerToSearch.at( index );
std::vector< std::string > singleSelectorContent = m_protonData->getHeaderFromType( typeName );
size_t indexCounter = 0;
std::cout << "START " << singleSelectorContent.size() << " | " << typeName << std::endl;
for( std::vector<std::string>::iterator colName = singleSelectorContent.begin(); colName != singleSelectorContent.end(); colName++ )
{
std::cout << "DEBUG: " << refheader << " | " << *colName << " | " << indexCounter << std::endl << std::endl;
if( *colName == refheader )
{
return indexCounter;
}
indexCounter++;
}
m_possibleSelectionsUsingTypes->addItem( ItemType::create( "- no selection -", "- no selection -", "", NULL ) );
std::cout << "ENDE " << std::endl << std::endl;
return -1;
}
WPropSelection WColumnPropertyHandler::addHeaderProperty( std::string columnName, std::string description, std::string defName,
WPropSelection WColumnPropertyHandler::addHeaderProperty( WColumnPropertyHandler::NameDescriptionSearchTyp ndst,
WPropertyBase::PropertyChangeNotifierType notifier )
{
std::string columnName = std::get< 0 >( ndst );
std::string description = std::get< 1 >( ndst );
std::string defName = std::get< 2 >( ndst );
std::string type = std::get< 3 >( ndst );
int index = m_protonData->getColumnIndex( defName );
int indexSingleSelector = index < 0 ? -1 : getfilterIndex( index, type );
m_protonData->setStateIndex( columnName, index );
WItemSelector selector = index < 0 ? m_possibleSelectionsUsingTypes->getSelectorLast() : m_possibleSelectionsUsingTypes->getSelector( index );
boost::shared_ptr< WItemSelection > possibleSelectionsUsingTypes = InitializeSelectionItem( type );
WItemSelector selector = index < 0 ? possibleSelectionsUsingTypes->getSelectorLast() :
possibleSelectionsUsingTypes->getSelector( indexSingleSelector );
WPropSelection selection = m_columnSelectionGroup->addProperty(
columnName,
description,
......@@ -103,19 +138,6 @@ WPropSelection WColumnPropertyHandler::addHeaderProperty( std::string columnName
return selection;
}
int WColumnPropertyHandler::getColumnNumberByName( std::string columnNameToMatch )
{
std::vector< std::string > headerToSearchIn = m_protonData->getCSVHeader()->at( 0 );
int pos = 0;
for( std::vector< std::string >::iterator it = headerToSearchIn.begin(); it != headerToSearchIn.end(); it++ )
{
if( *it == columnNameToMatch ) return pos;
pos++;
}
return -1;
}
void WColumnPropertyHandler::propertyNotifier( WPropertyBase::SPtr property )
{
const WItemSelector* selector = NULL;
......@@ -137,7 +159,7 @@ void WColumnPropertyHandler::propertyNotifier( WPropertyBase::SPtr property )
{
std::string selectedValue = selector->at( 0 )->getAs< ItemType >()->getValue();
m_protonData->setStateIndex( columnName, getColumnNumberByName( selectedValue ) );
m_protonData->setStateIndex( columnName, m_protonData->getColumnIndex( selectedValue ) );
m_dataUpdate();
if(m_externEventMethod != NULL)
......@@ -146,8 +168,3 @@ void WColumnPropertyHandler::propertyNotifier( WPropertyBase::SPtr property )
}
}
}
boost::shared_ptr< WItemSelection > WColumnPropertyHandler::getColumnItems()
{
return m_possibleSelectionsUsingTypes;
}
......@@ -44,6 +44,14 @@
class WColumnPropertyHandler
{
public:
/**
* tuple with 3 string as value
* 1. Name of single-selector,
* 2. Desciption of single-selector,
* 3. Value that is searched for in the csv header
*/
typedef std::tuple< std::string, std::string, std::string, std::string > NameDescriptionSearchTyp;
/**
* Function variables for updating the data
*/
......@@ -70,11 +78,6 @@ public:
*/
void createProperties();
/**
* \return boost::shared_ptr< WItemSelection > Reference of selectable column types
*/
boost::shared_ptr< WItemSelection > getColumnItems();
/**
* update current group property and subproperty
*/
......@@ -114,13 +117,10 @@ private:
/**
* Creates the individual WItemSelection
* \param headerName The name of the selection
* \param description The description of the selection
* \param notifier The notifier for the selection
* \param defName The default name of the selection
* \param ndst ( n = Name, d = Description, s = Search, t = Typ )
* \return WPropSelection The created selection
*/
WPropSelection addHeaderProperty( std::string headerName, std::string description, std::string defName,
WPropSelection addHeaderProperty( WColumnPropertyHandler::NameDescriptionSearchTyp ndst,
WPropertyBase::PropertyChangeNotifierType notifier );
/**
......@@ -134,11 +134,6 @@ private:
*/
WPropGroup m_columnSelectionGroup;
/**
* A list of items that can be selected using m_aSingleSelectionUsingTypes property.
*/
boost::shared_ptr< WItemSelection > m_possibleSelectionsUsingTypes;
/**
* represents the item type for item-selection
*/
......@@ -150,17 +145,19 @@ private:
typedef std::map< WPropSelection, std::string >::iterator PropMapEntry;
/**
* Get column number by name from header
*
* \param columnNameToMatch Search for the specified column name.
* \return Column number, where columnToMatch is in headerToSearchIn
* creates the content (options) of the WItemSelection
* \param typeName Type of column.
* \return content of WItemSelection
*/
int getColumnNumberByName( std::string columnNameToMatch );
boost::shared_ptr< WItemSelection > InitializeSelectionItem( std::string typeName );
/**
* creates the content (options) of the WItemSelection
* converts the index to the filtered index
* \param index index to search.
* \param typeName Type of column.
* \return filterd index
*/
void InitializeSelectionItem();
int getfilterIndex( int index, std::string typeName );
};
#endif // WCOLUMNPROPERTYHANDLER_H
......@@ -242,20 +242,23 @@ public:
WProtonData protonData( boost::make_shared< WDataSetCSV::Content >( sampleColumnNames ),
boost::make_shared< WDataSetCSV::Content >( sampleDataRows ) );
std::vector< std::string > testIntList{
std::vector< std::string > testIntList
{
"1", "0", "10", "+1", "-1",
"1e+1", "+1e+1", "-1e+1",
"1e1", "+1e1", "-1e1",
};
std::vector< std::string > testDoubleList{
std::vector< std::string > testDoubleList
{
"1000.1", "1.", ".1", "1.1",
"+1.", "-1.", "+.1", "-.1",
"+1e-1", "0.001e-12",
"0.111111111111111"
};
std::vector< std::string > testStringList{
std::vector< std::string > testStringList
{
".", "1a", "++1",
"+-1", "+", "-.",
"-", "--1.", "1.e.1",
......@@ -286,10 +289,11 @@ public:
WProtonData protonData( boost::make_shared< WDataSetCSV::Content >( sampleColumnNames ),
boost::make_shared< WDataSetCSV::Content >( sampleDataRows ) );
std::vector< std::string > refColumnTypes {
"int", "int", "int", "double", "double", "double", "double","double","double", "double",
std::vector< std::string > refColumnTypes
{
"int", "int", "int", "double", "double", "double", "double", "double", "double", "double",
"double", "double", "double", "double", "double" , "double", "double" , "int", "int", "int", "int",
"int", "int", "int", "int", "int", "int", "int", "int", "double","double",
"int", "int", "int", "int", "int", "int", "int", "int", "double", "double",
"int", "int", "int", "int", "double", "int", "string", "string", "string", "string",
};
......