Example #1
0
void ClsQHarborImpl::slotRefresh(){
#ifdef DEBUG_CLSQHARBORIMPL
    cout << "ClsQHarborImpl::slotRefresh" << endl;
#endif
    if(bSimulationRunning){
	for(int ii = 0; ii<tableWidget->rowCount(); ii++){
	    if(getItemValue(ii, COL_PARAM_NAME).length()>0){ /* cos we deleted this entry for
								       invalid param names */
		string strItemType = getItemValue(ii, COL_TYPE);
		string strID  = getItemValue(ii, COL_ID);
		string strParamName = getItemValue(ii, COL_PARAM_NAME); 
		
		ClsItem* clsItemTemp = NULL;
		if(!strItemType.compare("Group")){
#ifndef _WINDOWS // cannot get this to work under minGW at the moment...
		    clsItemTemp = ClsFESystemManager::Instance()->getFEGroup( strID );
#endif
		} else if (!strItemType.compare("Connection")){
#ifndef _WINDOWS // cannot get this to work under minGW at the moment...
		    clsItemTemp = ClsFESystemManager::Instance()->getFEConnection( strID );
#endif		    
		}
		
		if(clsItemTemp!=NULL){
		    fillMinMaxValueField(clsItemTemp, strParamName, ii);
		} 
	    }
	}
	tableWidget->resizeColumnToContents(COL_VALUE);    
    }
}
Example #2
0
bool ClsQHarborImpl::checkForItem(string _strItemID, string _strParamName){
#ifdef DEBUG_CLSQHARBORIMPL
    cout << "checkForItem(string strItemID, string strParamName)" << endl;
#endif
/*FIX*/
    for(int ii = 0; ii<tableWidget->rowCount(); ii++){
	string strItemID = getItemValue(ii, COL_ID);
	string strParamName = getItemValue(ii, COL_PARAM_NAME);
	if(!strItemID.compare(_strItemID) && !strParamName.compare(_strParamName)){
	    return true;
	}
    }
    return false;
}
Example #3
0
void ClsQHarborImpl::slotCellDoubleClicked(int row, int col){
#ifdef DEBUG_CLSQHARBORIMPL
    cout << "ClsQHarborImpl::slotCellDoubleClicked(int row, int col)" << endl;
#endif
    string _strID = getItemValue(row, COL_ID);
//    cout << _strID << endl;
    int iItemType = -1;
    string strItemType = getItemValue(row, COL_TYPE);
    if(!strItemType.compare("Group")){
	iItemType = ClsFESystemManager::ITEM_GROUP;
    } 
    else if(!strItemType.compare("Connection")){
	iItemType = ClsFESystemManager::ITEM_CONNECTION;
    }
    
    if(col == COL_PARAM_LABEL){
//	cout << "col == COL_PARAM_LABEL" << endl;
	doDialog(iItemType, _strID, row);
    } else if(col == COL_VALUE){
//	cout << "col == COL_VALUE" << endl;
	string strParamLabel = getItemValue(row, COL_PARAM_LABEL);
	string strParamName = getItemValue(row, COL_PARAM_NAME);
	double fMin = QString(getItemValue(row, COL_MIN).c_str()).toDouble();
	double fMax = QString(getItemValue(row, COL_MAX).c_str()).toDouble();
	double fValue = QString(getItemValue(row, COL_VALUE).c_str()).toDouble();

	doValueDialog(iItemType, _strID, row, strParamName, strParamLabel, fMin, fMax, fValue);
    } else {
//	cout << "other col" << endl;
    }
}
Example #4
0
// 이 함수를 부르기 전에 몇 명의 상대방이 있는지를 보여주고 선택한 상대방이 무슨 아이템을 가지고 있는지 보여줘야 함.
// 아이템이나 돈이 없을 경우 예외처리 필요
void Deal::Buy(Character* byWho, int itemId, int howMany) {
	int price = getItemValue(itemId) * howMany;

	if (checkMoneyForDeal(price, me.wallet(CHECK))) {
		byWho->removeItem(itemId, howMany);
		me.getItem(itemId, howMany);
		byWho->incMoney(price);
		me.decMoney(price);
	}
}
Example #5
0
// 인자로 받은 itemId를 toWho의 인벤토리에 넣고, 실행한 측의 인벤토리에선 삭제해야 함. 아이템의 가격이 설정된 함수를 불러 toWho의 money에서 빼야함.
// 아이템이나 돈이 없을 경우 예외처리 필요
void Deal::Sell(Character* toWho, int itemId, int howMany) {
	int price = getItemValue(itemId);

	if (checkMoneyForDeal(price, toWho->wallet(CHECK))){
		toWho->getItem(itemId, howMany);
		me.removeItem(itemId, howMany);
		toWho->decMoney(price);
		me.incMoney(price);
	}
}
Example #6
0
void ClsQHarborImpl::slotItemDeleted(int /*_iType*/, string _strID ){
#ifdef DEBUG_CLSQHARBORIMPL
    cout << "ClsQHarborImpl::slotItemDeleted(int iType, string strID )" << endl;
#endif
    /* remove item from the list */
    for(int ii = tableWidget->rowCount()-1; ii>=0; ii--){ 
	string strID = getItemValue(ii, COL_ID);
	if(!strID.compare(_strID)){
	    tableWidget->removeRow(ii);
	}
    }
    for(int ii = 0; ii<tableWidget->rowCount(); ii++){
	tableWidget->resizeColumnToContents(ii);
    }

};
Example #7
0
list<ClsParamTrade> ClsQHarborImpl::getParamTrades(){
#ifdef DEBUG_CLSQHARBORIMPL
    cout << "ClsQHarborImpl::getParamTrades()" << endl;
#endif
    list<ClsParamTrade> lstParamTrades;

    for(int ii = 0; ii<tableWidget->rowCount(); ii++){
	if(getItemValue(ii, COL_PARAM_NAME).length()>0){ 
	    ClsParamTrade paramTrade;
	    string strType = getItemValue(ii, COL_TYPE);                          paramTrade.Type = strType;
	    string strName = getItemValue(ii, COL_NAME);                          paramTrade.Name = strName ;
	    string strID  = getItemValue(ii, COL_ID);                             paramTrade.ID  = strID  ;
	    string strChild = getItemValue(ii, COL_CHILD);                        paramTrade.Child = strChild;
	    string strParam = getItemValue(ii, COL_PARAM_NAME);                   paramTrade.Param = strParam;
	    double fMin   = iqrUtils::string2double(getItemValue(ii, COL_MIN));   paramTrade.Min = fMin ;
	    double fMax   = iqrUtils::string2double(getItemValue(ii, COL_MAX));   paramTrade.Max = fMax ;
	    double fValue = iqrUtils::string2double(getItemValue(ii, COL_VALUE)); paramTrade.Value = fValue;
	    lstParamTrades.push_back(paramTrade);
	}
    }
    
//    cout << "ClsQHarborImpl::lstParamTrades.size(): " << lstParamTrades.size() << endl;
    return lstParamTrades;
};
Example #8
0
void ClsQHarborImpl::slotSaveParamSet(){
#ifdef DEBUG_CLSQHARBORIMPL
    cout << "ClsQHarborImpl::slotSaveParamSet()" << endl;
#endif


    QString qstrFileName = "";
    bool bValidFile = false;
    while(!bValidFile){
	qstrFileName = QFileDialog::getSaveFileName(
	    this, 
	    "Save File"
	    "Choose a filename to save under",
	    "",
 	    "Harbor ParamSet (*.pconf)" );

	QFileInfo qFileInfo(qstrFileName );
	QString qstrPath = qFileInfo.dirPath(true);
	qFileInfo.setFile (qstrPath);
	if ( !qFileInfo.isWritable() ) {
	    int iReturn = QMessageBox::critical( this, "iqr",
						 "No permission to write in this directory\n",
						 "Retry", "Cancel", 0, 0, 1 );
	    if(iReturn == 1){
		return;
	    }
	} else {
	    bValidFile = true;
	}
    }
    
    if(qstrFileName.length()<=0){
	return;
    }


    if ( QFile::exists(qstrFileName) ) {
/*      warning on overwrite */
	int iReturn = QMessageBox::warning( this, "iqr",
					    "A file with the seleteced name exists\n",
					    "Overwrite", "Cancel", 0, 0, 1 );
	if(iReturn == 1){
	    return;
	}
    }


    QDomDocument doc( "ParamSet" );
    QDomElement root = doc.createElement( "ParamSet" );
    doc.appendChild( root );

    
    for(int ii = 0; ii<tableWidget->rowCount(); ii++){
	QDomElement parameter = doc.createElement( "Parameter" );
	parameter.setAttribute ( "itemType", getItemValue(ii, COL_TYPE).c_str() );
	parameter.setAttribute ( "itemID", getItemValue(ii, COL_ID).c_str() );
	parameter.setAttribute ( "name", getItemValue(ii, COL_PARAM_NAME).c_str() );
	parameter.setAttribute ( "value", getItemValue(ii, COL_VALUE).c_str() );
	
	root.appendChild( parameter );

    }	    
    QString xml = doc.toString();
//    cout << xml << endl;


    QFile file(qstrFileName);
    if ( file.open( QIODevice::WriteOnly ) ) {
        QTextStream stream( &file );
	stream << doc.toString() << "\n";
        file.close();
    }


}
Example #9
0
void ClsQHarborImpl::slotItemChanged(int iItemType, string _strID ){
#ifdef DEBUG_CLSQHARBORIMPL
    cout << "ClsQHarborImpl::slotItemChanged(int iType, string strID )" << endl;
#endif
#ifndef _WINDOWS // cannot get this to work under minGW at the moment...

    if(!bSimulationRunning){
	ClsItem* clsItemTemp = NULL;
	ParameterList paramLst;
	string _strSubItemName;
	string _strItemName;
	if(iItemType == ClsFESystemManager::ITEM_GROUP){
	    clsItemTemp = ClsFESystemManager::Instance()->getFEGroup( _strID );
	    if(clsItemTemp!=NULL){
		_strItemName = dynamic_cast<ClsFEGroup*>(clsItemTemp)->getGroupName();
		ClsNeuron* clsNeuron = dynamic_cast<ClsFEGroup*>(clsItemTemp)->getNeuron( );
		if(clsNeuron!=NULL){
		    _strSubItemName = dynamic_cast<ClsFEGroup*>(clsItemTemp)->getGroupNeuronLabel();
		    paramLst = clsNeuron->getListParameters();
		}
	    }
	} else if (iItemType == ClsFESystemManager::ITEM_CONNECTION){
	    clsItemTemp = ClsFESystemManager::Instance()->getFEConnection( _strID );
	    if(clsItemTemp!=NULL){
		_strItemName = dynamic_cast<ClsFEConnection*>(clsItemTemp)->getConnectionName();
		ClsSynapse* clsSynapse = dynamic_cast<ClsFEConnection*>(clsItemTemp)->getSynapse( );
		if(clsSynapse!=NULL){
		    _strSubItemName = dynamic_cast<ClsFEConnection*>(clsItemTemp)->getConnectionSynapseLabel();
		    paramLst = clsSynapse->getListParameters();
		}
	    }
	}

	list<string> lstParams;
	for(ParameterList::iterator it=paramLst.begin(); it!=paramLst.end(); it++){
	    if(dynamic_cast<ClsDoubleParameter*>(*it)){
		lstParams.push_back((*it)->getName());
	    }
	}

	
/* checks:
   - item name
   - item subtype
   - subtype parameter
   - subtype min, max, value
*/

	if(clsItemTemp!=NULL){
//	cout << "/* check the min, max, value settings */" << endl;
	    for(int ii = 0; ii<tableWidget->rowCount(); ii++){
		string strID = getItemValue(ii, COL_ID);
		if(!strID.compare(_strID)){
		    bool bSubItemTypeChanged = false;
		    /* check (omitted) + change name */
		    changeItem(ii, COL_NAME, _strItemName.c_str());
		
		    string str = getItemValue(ii, COL_CHILD);
//		cout << "str: " << str << endl;
//		cout << "_strSubItemName: " << _strSubItemName << endl;
		    if(_strSubItemName.compare(str)){
//		    cout << "subitem type changed" << endl;
			bSubItemTypeChanged = true;
			changeItem(ii, COL_CHILD, _strSubItemName.c_str());
		    } else {
//		    cout << "subitem type NOT changed" << endl;
			bSubItemTypeChanged = false;
		    }

		    bool bParameterSupported = true;
		    if(bSubItemTypeChanged){
			/* check if subitem supports parameter */
			string str = getItemValue(ii, COL_PARAM_NAME);
			if(std::find(lstParams.begin(), lstParams.end(), str)!=lstParams.end()){
//			cout << "PARAMETER SUPPORTED" << endl;
			} else {
//			cout << "PARAMETER _NOT_ SUPPORTED" << endl;
			    bParameterSupported = false;
			}
		    }
		
		    if(bParameterSupported){
			string strParamName = getItemValue(ii, COL_PARAM_NAME);
			fillMinMaxValueField(clsItemTemp, strParamName, ii);
		    
		    }
		    else {
			changeItem(ii, COL_PARAM_LABEL, "");
			changeItem(ii, COL_PARAM_NAME, "");
			changeItem(ii, COL_MIN, "");
			changeItem(ii, COL_MAX, "");
			changeItem(ii, COL_VALUE, "");

		    }
		}
	    }
	}
	for(int ii = 0; ii<tableWidget->rowCount(); ii++){
	    tableWidget->resizeColumnToContents(ii);
	}
    }
#endif
};