示例#1
0
Id ReadCell::addChannel( 
	Id compt,
	Id proto,
	double value,
	double dia,
	double length )
{
	Id copy = shell_->doCopy(
		proto,
		compt,
		"",     // newName: same as old name.
		1,      // n: number of copies
		false,  // toGlobal
		false   // copyExtMsgs
	);
/////////////////////////////
        assert( copy.element()->getName() == proto.element()->getName() );
/////////////////////////////
	assert( copy != Id() );
	
	if ( addCanonicalChannel( compt, copy, value, dia, length ) ) return copy;
	if ( addSpikeGen( compt, copy, value, dia, length ) ) return copy;
	if ( addCaConc( compt, copy, value, dia, length ) ) return copy;
	if ( addNernst( compt, copy, value ) ) return copy;
	
	return Id();
}
示例#2
0
void ZombiePool::vSetSolver( Id ksolve, Id dsolve )
{
	// Nasty unsafe typecast. I would have preferred to pass in a 
	// safely typed pointer but that would have exposed a low-level
	// class for the ZombiePoolInterface.
	if ( ksolve.element()->cinfo()->isA( "Ksolve" ) ||
					ksolve.element()->cinfo()->isA( "Gsolve" ) ) {
			ksolve_= reinterpret_cast< ZombiePoolInterface *>(
					ObjId( ksolve, 0 ).data() );
	} else if ( ksolve == Id() ) {
			ksolve_ = 0;
	} else {
			cout << "Warning:ZombiePool::vSetSolver: solver class " << 
					ksolve.element()->cinfo()->name() << 
					" not known.\nShould be Ksolve or Gsolve\n";
			ksolve_ = 0;
	}
	
	if ( dsolve.element()->cinfo()->isA( "Dsolve" ) ) {
			dsolve_= reinterpret_cast< ZombiePoolInterface *>(
					ObjId( dsolve, 0 ).data() );
	} else if ( dsolve == Id() ) {
			dsolve_ = 0;
	} else {
			cout << "Warning:ZombiePool::vSetSolver: solver class " << 
					dsolve.element()->cinfo()->name() << 
					" not known.\nShould be Dsolve\n";
			dsolve_ = 0;
	}
}
示例#3
0
void RefactoringApplier::changeElementInModel(const Id &changeFromId, const Id &changeToId)
{
	if (mLogicalModelApi.isLogicalId(changeFromId)) {
		return;
	}
	if (!refactoringElements.contains(changeToId.element())) {
		IdList const inLinks = mGraphicalModelApi.mutableGraphicalRepoApi().incomingLinks(changeFromId);
		IdList const outLinks = mGraphicalModelApi.mutableGraphicalRepoApi().outgoingLinks(changeFromId);
		Id const parentId = mGraphicalModelApi.mutableGraphicalRepoApi().parent(changeFromId);
		QVariant const position = mGraphicalModelApi.mutableGraphicalRepoApi().position(changeFromId);
		bool const isFromLogicalModel = false;
		QString const refactoringsMetamodel = "RefactoringsMetamodel";
		QString newEditor = changeToId.editor();
		newEditor.chop(refactoringsMetamodel.length());
		Id const newId = Id(newEditor, changeToId.diagram(), changeToId.element(), QUuid::createUuid().toString());
		Id const newElementId = mGraphicalModelApi.createElement(parentId, newId
				, isFromLogicalModel, "ololo", position.toPointF());
		for (Id idLink : inLinks) {
			mGraphicalModelApi.mutableGraphicalRepoApi().setTo(idLink, newElementId);
		}
		for (Id idLink : outLinks) {
			mGraphicalModelApi.mutableGraphicalRepoApi().setFrom(idLink, newElementId);
		}
		mGraphicalModelApi.mutableGraphicalRepoApi().removeChild(parentId, changeFromId);
		mGraphicalModelApi.mutableGraphicalRepoApi().removeElement(changeFromId);
	}
}
示例#4
0
void RefactoringApplier::changeElement(Id const &changeFromId, Id const &changeToId)
{
	Id const beforeId = beforeIdInRule(changeToId);
	if (isElementTypesInRuleIdentical(beforeId, changeToId)) {
		if (changeToId.element() == "Element") {
			if (mRefactoringRepoApi->name(changeToId) == "(Element)") {
				return;
			}
			changeElementName(changeFromId, changeToId);
		}
		else if (changeToId.element() == "Link") {
			if (mRefactoringRepoApi->name(changeToId) != "(Link)") {
				changeElementName(changeFromId, changeToId);
			}
			checkDirection(changeFromId, changeToId, beforeId);
		}
		else {
			changePropertiesInModel(changeFromId, changeToId);
			if (!isNodeInRule(beforeId) && !isNodeInRule(changeToId)) {
				checkDirection(changeFromId, changeToId, beforeId);
			}
		}
	}
	else {
		changeElementInModel(changeFromId, changeToId);
	}
}
示例#5
0
void ZombieFunction::setSolver( Id ksolve, Id dsolve )
{
	if ( ksolve.element()->cinfo()->isA( "Ksolve" ) ||
					ksolve.element()->cinfo()->isA( "Gsolve" ) ) {
		Id sid = Field< Id >::get( ksolve, "stoich" );
		_stoich = ObjId( sid, 0 ).data();
		if ( _stoich == 0 )
			cout << "Warning:ZombieFunction::setSolver: Empty Stoich on Ksolve" << ksolve.path() << endl;
	} else if ( ksolve == Id() ) {
			_stoich = 0;
	} else {
			cout << "Warning:ZombieFunction::setSolver: solver class " <<
					ksolve.element()->cinfo()->name() <<
					" not known.\nShould be Ksolve or Gsolve\n";
			_stoich = 0;
	}

	/*
	if ( dsolve.element()->cinfo()->isA( "Dsolve" ) ) {
			dsolve_= ObjId( dsolve, 0 ).data();
	} else if ( dsolve == Id() ) {
			dsolve_ = 0;
	} else {
			cout << "Warning:ZombieFunction::vSetSolver: solver class " <<
					dsolve.element()->cinfo()->name() <<
					" not known.\nShould be Dsolve\n";
			dsolve_ = 0;
	}
	*/
}
示例#6
0
void ZombieMMenz::setSolver( Id solver, Id orig )
{
	static const DestFinfo* enz = dynamic_cast< const DestFinfo* >(
		EnzBase::initCinfo()->findFinfo( "enzDest" ) );
	static const SrcFinfo* sub = dynamic_cast< const SrcFinfo* >(
		EnzBase::initCinfo()->findFinfo( "toSub" ) );
	static const SrcFinfo* prd = dynamic_cast< const SrcFinfo* >(
		EnzBase::initCinfo()->findFinfo( "toPrd" ) );
	assert( enz );
	assert( sub );
	assert( prd );

	stoich_ = reinterpret_cast< Stoich* >( solver.eref().data() );

	/// Now set up the RateTerm
	vector< Id > subvec;
	vector< Id > prdvec;
	unsigned int rateIndex = stoich_->convertIdToReacIndex( orig );
	unsigned int num = orig.element()->getNeighbours( subvec, enz );
	unsigned int enzIndex = stoich_->convertIdToPoolIndex( subvec[0] );
	MMEnzymeBase* meb;

	double numKm = 1.0; // Dummy default initial values, later to be reset
	double kcat = 1.0;
	/*
	double numKm = base->zGetNumKm( orig.eref(), 0 );
	double kcat = base->zGetKcat( orig.eref(), 0 );
	*/

	num = orig.element()->getNeighbours( subvec, sub );
	if ( num == 1 ) {
		unsigned int subIndex = stoich_->convertIdToPoolIndex( subvec[0] );
		meb = new MMEnzyme1( numKm, kcat, enzIndex, subIndex );
	} else if ( num > 1 ) {
		vector< unsigned int > v;
		for ( unsigned int i = 0; i < num; ++i )
			v.push_back( stoich_->convertIdToPoolIndex( subvec[i] ) );
		ZeroOrder* rateTerm = new NOrder( 1.0, v );
		meb = new MMEnzyme( numKm, kcat, enzIndex, rateTerm );
	} else {
		cout << "Error: ZombieMMenz::zombify: No substrates for "  <<
			orig.path() << endl;
		cout << "Will ignore and continue, but don't be surprised if "
		"simulation fails.\n";
		// assert( 0 );
		return;
	}
	num = orig.element()->getNeighbours( prdvec, prd );
	stoich_->installMMenz( meb, rateIndex, subvec, prdvec );
}
示例#7
0
void Gsolve::setDsolve( Id dsolve )
{
	if ( dsolve == Id () ) {
		dsolvePtr_ = 0;
		dsolve_ = Id();
	} else if ( dsolve.element()->cinfo()->isA( "Dsolve" ) ) {
		dsolve_ = dsolve;
		dsolvePtr_ = reinterpret_cast< ZombiePoolInterface* >( 
						dsolve.eref().data() );
	} else {
		cout << "Warning: Gsolve::setDsolve: Object '" << dsolve.path() <<
				"' should be class Dsolve, is: " << 
				dsolve.element()->cinfo()->name() << endl;
	}
}
示例#8
0
bool Shell::isRunning() const
{
	static Id clockId( 1 );
	assert( clockId.element() != 0 );

	return ( reinterpret_cast< const Clock* >( clockId.eref().data() ) )->isRunning();
}
示例#9
0
void Shell::doMove( Id orig, ObjId newParent )
{
	if ( orig == Id() ) {
		cout << "Error: Shell::doMove: Cannot move root Element\n";
		return;
	}

	if ( newParent.element() == 0 ) {
		cout << "Error: Shell::doMove: Cannot move object to null parent \n";
		return;
	}
	if ( Neutral::isDescendant( newParent, orig ) ) {
		cout << "Error: Shell::doMove: Cannot move object to descendant in tree\n";
		return;
		
	}
	const string& name = orig.element()->getName();
	if ( Neutral::child( newParent.eref(), name ) != Id() ) {
			stringstream ss;
			ss << "Shell::doMove: Object with same name already present: '"
			   	<< newParent.path() << "/" << name << "'. Move failed.";
			warning( ss.str() );
			return;
	}

	SetGet2< Id, ObjId >::set( ObjId(), "move", orig, newParent );
	// innerMove( orig, newParent );
}
示例#10
0
void Element::dropAllMsgsFromSrc( Id src ) 
{
	static Id clockId( 1 );
	const Element* clock = clockId.element();
	vector< ObjId > msgs;
	for ( vector< ObjId >::const_iterator i = m_.begin(); 
		i != m_.end(); ++i )
	{
		const Msg* m = Msg::getMsg( *i );
		const Element* src;
		if ( m->e1() == this ) {
			src = m->e2();
		} else {
			src = m->e1();
		}
		if ( src == clock ) {
			msgs.push_back( *i );
		}
	}
	sort( msgs.begin(), msgs.end() ); 
	// C++ detritus.
	msgs.erase( unique( msgs.begin(), msgs.end() ), msgs.end() );
	for( vector< ObjId >::iterator 
					i = msgs.begin(); i != msgs.end(); ++i )
		Msg::deleteMsg( *i );
}
示例#11
0
文件: exploser.cpp 项目: timbog/qreal
void Exploser::refreshPalette(gui::PaletteTreeWidget * const tree, Id const &diagram)
{
	QMap<QString, QList<gui::PaletteElement> > groups;
	QMap<QString, QString> descriptions;
	descriptions[mUserGroupTitle] = mUserGroupDescription;

	IdList const childTypes = mApi.editorManagerInterface().elements(diagram);
	foreach (Id const &child, childTypes) {
		QList<Explosion> const explosions = mApi.editorManagerInterface().explosions(child);
		foreach (Explosion const &explosion, explosions) {
			if (!explosion.isReusable()) {
				continue;
			}
			Id const target = explosion.target();
			IdList const allTargets = mApi.logicalRepoApi().elementsByType(target.element(), true);
			foreach (Id const &targetInstance, allTargets) {
				if (mApi.isLogicalId(targetInstance) &&
						!mApi.logicalRepoApi().incomingExplosions(targetInstance).isEmpty())
				{
					groups[mUserGroupTitle] << gui::PaletteElement(child
							, mApi.logicalRepoApi().name(targetInstance)
							, QString(), mApi.editorManagerInterface().icon(child)
							, mApi.editorManagerInterface().iconSize(child)
							, targetInstance);
				}
			}
		}
	}
示例#12
0
bool ReadCell::addSpikeGen( 
	Id compt,
	Id chan, 
	double value,
	double dia,
	double length )
{
    string className = chan.element()->cinfo()->name();
	if ( className == "SpikeGen" ) {
		shell_->doAddMsg(
			"Single",
			compt,
			"VmSrc",
			chan,
			"Vm"
		);
		
		if ( !graftFlag_ )
			++numOthers_;
		
		return Field< double >::set( chan, "threshold", value );
	}
	
	return 0;
}
示例#13
0
/// Returns the Id of the loaded model.
Id Shell::doLoadModel( const string& fileName, const string& modelPath, const string& solverClass )
{
    ifstream fin( fileName.c_str() );
    if ( !fin )
    {
        LOG( moose::failed, "Shell::doLoadModel: could not open file " << fileName );
        return Id();
    }

    string modelName;
    Id parentId;

    if ( !( findModelParent ( cwe_, modelPath, parentId, modelName ) ) )
        return Id();

    string line;
    switch ( findModelType( fileName, fin, line ) )
    {
    case DOTP:
    {
        ReadCell rc;
        return rc.read( fileName, modelName, parentId );
        return Id();
    }
    case SWC:
    {
        LOG( moose::info, "In doLoadModel for SWC" );
        ReadSwc rs( fileName );
        Id model = parentId;
        if ( !parentId.element()->cinfo()->isA( "Neuron" ) )
        {
            model = doCreate( "Neuron", parentId, modelName, 1 );
        }
        rs.build( model, 0.5e-3, 1.0, 1.0, 0.01 );
        return model;
    }
    case KKIT:
    {
        string sc = solverClass;
        ReadKkit rk;
        Id ret = rk.read( fileName, modelName, parentId, sc);
        return ret;
    }
    break;
    case CSPACE:
    {
        string sc = solverClass;
        ReadCspace rc;
        Id ret = rc.readModelString( line, modelName, parentId, sc);
        rc.makePlots( 1.0 );
        return ret;
    }
    case UNKNOWN:
    default:
        cout << "Error: Shell::doLoadModel: File type of '" <<
             fileName << "' is unknown\n";
    }
    return Id();
}
示例#14
0
bool isDoingReinit()
{
	static Id clockId( 1 );
	assert( clockId.element() != 0 );

	return ( reinterpret_cast< const Clock* >( 
		clockId.eref().data() ) )->isDoingReinit();
}
示例#15
0
void Exploser::refreshPalette(gui::PaletteTreeWidget * const tree, Id const &diagram)
{
	QList<QPair<QString, QList<gui::PaletteElement>>> groups;
	QMap<QString, QString> descriptions;
	descriptions[mUserGroupTitle] = mUserGroupDescription;

	IdList const childTypes = mApi.editorManagerInterface().elements(diagram);

	for (Id const &child : childTypes) {
		QList<Explosion> const explosions = mApi.editorManagerInterface().explosions(child);

		for (Explosion const &explosion : explosions) {
			if (!explosion.isReusable()) {
				continue;
			}

			Id const targetNodeOrGroup = explosion.target();
			Id target;
			if (mApi.editorManagerInterface().isNodeOrEdge(targetNodeOrGroup.editor(), targetNodeOrGroup.element())) {
				target = targetNodeOrGroup;
			} else {
				Pattern const pattern = mApi.editorManagerInterface().getPatternByName(targetNodeOrGroup.element());
				target = Id(targetNodeOrGroup.editor(), targetNodeOrGroup.diagram(), pattern.rootType());
			}

			IdList const allTargets = mApi.logicalRepoApi().elementsByType(target.element(), true);
			QList<gui::PaletteElement> groupElements;
			for (Id const &targetInstance : allTargets) {
				if (mApi.isLogicalId(targetInstance)) {
					groupElements << gui::PaletteElement(child
							, mApi.logicalRepoApi().name(targetInstance)
							, QString(), mApi.editorManagerInterface().icon(child)
							, mApi.editorManagerInterface().iconSize(child)
							, targetInstance);
				}
			}

			if (!groupElements.isEmpty()) {
				groups << qMakePair(mUserGroupTitle, groupElements);
			}
		}
	}

	tree->addGroups(groups, descriptions, true, mApi.editorManagerInterface().friendlyName(diagram), true);
}
示例#16
0
TEST(IdsTest, gettersTest) {
	Id id = Id::loadFromString("qrm:/editor/diagram/element/id");

	EXPECT_EQ(id.editor(), "editor");
	EXPECT_EQ(id.diagram(), "diagram");
	EXPECT_EQ(id.element(), "element");
	EXPECT_EQ(id.id(), "id");
	EXPECT_EQ(id.type() ,Id("editor", "diagram", "element"));
}
示例#17
0
void ZombieCaConc::vSetSolver( const Eref& e, Id hsolve )
{
	if ( !hsolve.element()->cinfo()->isA( "HSolve" ) ) {
		cout << "Error: ZombieCaConc::vSetSolver: Object: " <<
				hsolve.path() << " is not an HSolve. Aborted\n";
		hsolve_ = 0;
		return;
	}
	hsolve_ = reinterpret_cast< HSolve* >( hsolve.eref().data() );
}
示例#18
0
Id InterpreterEditorManager::element(Id const &id, qrRepo::RepoApi const * const repo, Id const &diagram) const
{
	foreach (Id const &element, repo->children(diagram)) {
		if (id.element() == repo->name(element) && repo->isLogicalElement(element)) {
			return element;
		}
	}

	return Id();
}
示例#19
0
int main( int argc, char** argv )
{
	bool doUnitTests = 0;
	bool doRegressionTests = 0;
	unsigned int benchmark = 0;
	// This reorders the OpFunc to Fid mapping to ensure it is node and
	// compiler independent.
	Id shellId = init( argc, argv, doUnitTests, doRegressionTests, benchmark );
	// Note that the main loop remains the parser loop, though it may
	// spawn a lot of other stuff.
	Element* shelle = shellId.element();
	Shell* s = reinterpret_cast< Shell* >( shelle->data( 0 ) );
	if ( doUnitTests )
		nonMpiTests( s ); // These tests do not need the process loop.

	if ( Shell::myNode() == 0 ) {
		if ( Shell::numNodes() > 1 ) {
			// Use the last clock for the postmaster, so that it is called
			// after everything else has been processed and all messages
			// are ready to send out.
			s->doUseClock( "/postmaster", "process", 9 );
			s->doSetClock( 9, 1.0 ); // Use a sensible default.
		}
#ifdef DO_UNIT_TESTS
		if ( doUnitTests ) {
			mpiTests();
			processTests( s );
		}
		// if ( doRegressionTests ) regressionTests();
#endif
		// These are outside unit tests because they happen in optimized
		// mode, using a command-line argument. As soon as they are done
		// the system quits, in order to estimate timing.
		if ( benchmark != 0 ) {
			mooseBenchmarks( benchmark );
			s->doQuit();
		} else {
			// Here we set off a little event loop to poll user input. 
			// It deals with the doQuit call too.
                        if(! quitFlag)
                            Shell::launchParser(); 
		}
	} else {
		PostMaster* p = reinterpret_cast< PostMaster* >( ObjId( 3 ).data());
		while ( Shell::keepLooping() ) {
			p->clearPending();
		}
	}
	Msg::clearAllMsgs();
	Id::clearAllElements();
#ifdef USE_MPI
	MPI_Finalize();
#endif
	return 0;
}
示例#20
0
void SbmlReader::getRules() {
    unsigned int nr = model_->getNumRules();
    //if (nr > 0)
    //  cout << "\n ##### Need to populate funcpool and sumtotal which is pending due to equations \n";
    Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
    for ( unsigned int r = 0; r < nr; r++ ) {

        Rule * rule = model_->getRule(r);
        bool assignRule = rule->isAssignment();
        if ( assignRule ) {
            string rule_variable = rule->getVariable();
            map< string,Id >::iterator v_iter;
            map< string,Id >::iterator m_iter;
            v_iter = molSidMIdMap_.find( rule_variable );
            if (v_iter != molSidMIdMap_.end()) {
                Id rVariable = molSidMIdMap_.find(rule_variable)->second;
                string rstring =molSidMIdMap_.find(rule_variable)->first;
                Id sumId = shell->doCreate( "SumFunc", rVariable, "func", 1 );
                rVariable.element()->zombieSwap( FuncPool::initCinfo() );
                ObjId ret = shell->doAddMsg( "single",
                                             ObjId( sumId, 0 ), "output",
                                             ObjId( rVariable, 0 ), "input" );
                assert( ret != ObjId() );
                const ASTNode * ast = rule->getMath();
                vector< string > ruleMembers;
                ruleMembers.clear();
                printMembers( ast,ruleMembers );
                for ( unsigned int rm = 0; rm < ruleMembers.size(); rm++ ) {
                    m_iter = molSidMIdMap_.find( ruleMembers[rm] );
                    if ( m_iter != molSidMIdMap_.end() ) {
                        Id rMember = molSidMIdMap_.find(ruleMembers[rm])->second;
                        ObjId ret = shell->doAddMsg( "single",
                                                     ObjId( rMember, 0 ), "nOut",
                                                     ObjId( sumId, 0 ), "input" );
                        string test = molSidMIdMap_.find(ruleMembers[rm])->first;
                    } else {
                        cerr << "SbmlReader::getRules: Assignment rule member is not a species" << endl;
                        // In assignment rule there are constants instead of molecule which is yet to deal in moose.
                        errorFlag_ = true;
                    }
                }
            }
        }
        bool rateRule = rule->isRate();
        if ( rateRule ) {
            cout << "warning : for now Rate Rule is not handled " << endl;
            errorFlag_ = true;
        }
        bool  algebRule = rule->isAlgebraic();
        if ( algebRule ) {
            cout << "warning: for now Algebraic Rule is not handled" << endl;
            errorFlag_ = true;
        }
    }
}
示例#21
0
void HSolve::setSeed( Id seed )
{
    if ( !seed.element()->cinfo()->isA( "Compartment" ) )
    {
        cerr << "Error: HSolve::setSeed(): Seed object '" << seed.path()
             << "' is not derived from type 'Compartment'." << endl;
        return;
    }

    seed_ = seed;
}
示例#22
0
void Gsolve::setStoich( Id stoich )
{
	// This call is done _before_ setting the path on stoich
	assert( stoich.element()->cinfo()->isA( "Stoich" ) );
	stoich_ = stoich;
	stoichPtr_ = reinterpret_cast< Stoich* >( stoich.eref().data() );
	sys_.stoich = stoichPtr_;
	sys_.isReady = false;
	for ( unsigned int i = 0; i < pools_.size(); ++i )
		pools_[i].setStoich( stoichPtr_ );
}
// See what Element::getNeighbors does with 2 sub <----> prd.
void testTwoReacGetNeighbors()
{
	Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
	Id comptId = shell->doCreate( "CubeMesh", Id(), "cube", 1 );
	Id meshId( comptId.value() + 1 );
	Id subId = shell->doCreate( "Pool", comptId, "sub", 1 );
	Id prdId = shell->doCreate( "Pool", comptId, "prd", 1 );
	Id reacId = shell->doCreate( "Reac", comptId, "reac", 1 );

	ObjId mid = shell->doAddMsg( "OneToOne", 
		subId, "requestVolume", meshId, "get_volume" );
	assert( mid != ObjId() );
	mid = shell->doAddMsg( "OneToOne", 
		prdId, "requestVolume", meshId, "get_volume" );
	assert( mid != ObjId() );

	ObjId ret = shell->doAddMsg( "Single", reacId, "sub", subId, "reac" );
	assert( ret != ObjId() );
	ret = shell->doAddMsg( "Single", reacId, "sub", subId, "reac" );
	assert( ret != ObjId() );

	ret = shell->doAddMsg( "Single", reacId, "prd", prdId, "reac" );
	assert( ret != ObjId() );

	vector< Id > pools;
	unsigned int num = reacId.element()->getNeighbors( pools, 
		Reac::initCinfo()->findFinfo( "toSub" ) );
	assert( num == 2 );
	assert( pools[0] == subId );
	assert( pools[1] == subId );

	pools.clear();
	num = reacId.element()->getNeighbors( pools, 
		Reac::initCinfo()->findFinfo( "sub" ) );
	assert( num == 2 );
	assert( pools[0] == subId );
	assert( pools[1] == subId );

	shell->doDelete( comptId );
	cout << "." << flush;
}
示例#24
0
void ContextMenuActionTrigger::contextMenuActionTriggered(QString const &name)
{
	QString actionName = name.section("###", 0, 0);
	QString uuid = name.section("###", 1, 1);

	if (actionName == "Add method") {
		MethodEditorDialog dialog;
		int dialogResult = dialog.exec();	
		
		if (dialogResult) {
			qDebug() << "ACCEPTED!!!";

			Id id = Id::loadFromString(uuid);
			if (id.element() == "MethodsContainer") {
				Id newMethodId = mApi->createElement(id, Id("Kernel_metamodel", "Kernel",
							"Method"));
				mApi->setProperty(newMethodId, Qt::DisplayRole, QVariant(dialog.generateMethodString()));	
			} else if (id.element() == "Class") {
				//Id newMethodId = mApi->createElement(id, Id("Kernel_metamodel", "Kernel",
				//			"Method"));
			}
		}
	} else if (actionName == "Add field") {
		FieldEditorDialog dialog;
		int dialogResult = dialog.exec();	
		
		if (dialogResult) {
			qDebug() << "ACCEPTED!!!";

			Id id = Id::loadFromString(uuid);
			if (id.element() == "FieldsContainer") {
				Id newMethodId = mApi->createElement(id, Id("Kernel_metamodel", "Kernel",
							"Field"));
				mApi->setProperty(newMethodId, Qt::DisplayRole, QVariant(dialog.generateFieldString()));	
			} else if (id.element() == "Class") {
				//Id newMethodId = mApi->createElement(id, Id("Kernel_metamodel", "Kernel",
				//			"Method"));
			}
		}
	}
}
示例#25
0
void checkChildren( Id parent, const string& info )
{
    vector< Id > ret;
    Neutral::children( parent.eref(), ret );
    cout << info << " checkChildren of " <<
         parent.element()->getName() << ": " <<
         ret.size() << " children\n";
    for ( vector< Id >::iterator i = ret.begin(); i != ret.end(); ++i )
    {
        cout << i->element()->getName() << endl;
    }
}
示例#26
0
Id ModelsAssistApi::createElement(Id const &parent, Id const &id, Id const &logicalId
		, bool isFromLogicalModel, QString const &name, QPointF const &position)
{
	Q_ASSERT(parent.idSize() == 4);
	Id newId = id;
	Id realLogicalId = logicalId;
	if (isFromLogicalModel) {
		realLogicalId = id;
		newId = Id(id.editor(), id.diagram(), id.element(), QUuid::createUuid().toString());
	}
	mModel.addElementToModel(parent, newId, realLogicalId, name, position);
	return newId;
}
示例#27
0
文件: ReadKkit.cpp 项目: csiki/MOOSE
/**
 * Return the MeshEntry into which the enzyme should be placed.
 * This is simple: Just identify the compartment holding the enzyme
 * molecule.
 */
Id findMeshOfEnz( Id enz )
{
	static const Finfo* enzFinfo =
		   	EnzBase::initCinfo()->findFinfo( "enzOut" );
	assert( enzFinfo );

		vector< Id > enzVec;
		unsigned int numEnz = 
				enz.element()->getNeighbors( enzVec, enzFinfo );
		assert( numEnz == 1 );
		vector< Id > meshEntries;
		return getCompt( enzVec[0] );
}
示例#28
0
文件: ReadKkit.cpp 项目: csiki/MOOSE
void ReadKkit::buildSumTotal( const string& src, const string& dest )
{
	map< string, Id >::iterator i = poolIds_.find( dest );
	assert( i != poolIds_.end() );
	Id destId = i->second;
	
	// Don't bother on buffered pool.
	if ( destId.element()->cinfo()->isA( "BufPool" ) ) 
		return;

	Id sumId;
	// Check if the pool has not yet been converted to handle SumTots.
	if ( destId.element()->cinfo()->name() == "Pool" ) {
		sumId = shell_->doCreate( "SumFunc", destId, "func", 1 );
		// Turn dest into a FuncPool.
		destId.element()->zombieSwap( FuncPool::initCinfo() );

		ObjId ret = shell_->doAddMsg( "single", 
			ObjId( sumId, 0 ), "output",
			ObjId( destId, 0 ), "input" ); 
		assert( ret != ObjId() );
	} else {
		sumId = Neutral::child( destId.eref(), "func" );
	}

	if ( sumId == Id() ) {
		cout << "Error: ReadKkit::buildSumTotal: could not make SumFunc on '"
		<< dest << "'\n";
		return;
	}
	
	Id srcId = findSumTotSrc( src );

	ObjId ret = shell_->doAddMsg( "single", 
		ObjId( srcId, 0 ), "nOut",
		ObjId( sumId, 0 ), "input" ); 
	assert( ret != ObjId() );

}
示例#29
0
Id LogicalModelAssistApi::createElement(const Id &parent, const Id &type)
{
	Q_ASSERT(type.idSize() == 3);
	Q_ASSERT(parent.idSize() == 4);

	const Id newElementId = type.sameTypeId();
	const QString elementFriendlyName = mModelsAssistApi.editorManagerInterface().friendlyName(type);
	const bool isEdge = mModelsAssistApi.editorManagerInterface().isNodeOrEdge(
			newElementId.editor(), newElementId.element()) == -1;
	ElementInfo newElement(newElementId, Id(), parent, Id(), {{"name", elementFriendlyName}}, {}, Id(), isEdge);
	mLogicalModel.addElementToModel(newElement);
	return newElementId;
}
示例#30
0
/**
 * This function performs a depth-first search (for a compartment) in the tree
 * with its root at 'base'. Returns (Id of) a compartment if found, else a
 * blank Id.
 */
Id HSolve::deepSearchForCompartment( Id base )
{
    /*
     * 'cstack' is a stack-of-stacks used to perform the depth-first search.
     *     The 0th entry in 'cstack' is a stack containing simply the base.
     *     The i-th entry in 'cstack' contains children of the node at the top
     *         of the stack at position ( i - 1 ).
     *     Hence, at any time, the top of the i-th stack is the i-th node on
     *     the ancestral path from the 'base' node to the 'current' node
     *     (more below) which is being examined. Also, the remaining nodes in
     *     the i-th stack are the siblings of this ancestor.
     *
     * 'current' is the node at the top of the top of 'cstack'. If this node is
     *     a Compartment, then the search is completed, returning 'current'.
     *     Otherwise, the children of 'current' are pushed onto 'cstack' for a
     *     deeper search. If the deeper search yields nothing, then this
     *     'current' node is discarded. When an entire stack of siblings is
     *     exhausted in this way, then this empty stack is discarded, and
     *     the search moves 1 level up.
     *
     * 'result' is a blank Id (moose root element) if the search failed.
     *     Otherwise, it is a compartment that was found under 'base'.
     */
    vector< vector< Id > > cstack( 1, vector< Id >( 1, base ) );
    Id current;
    Id result;

    while ( !cstack.empty() )
        if ( cstack.back().empty() )
        {
            cstack.pop_back();

            if ( !cstack.empty() )
                cstack.back().pop_back();
        }
        else
        {
            current = cstack.back().back();

            // if ( current()->cinfo() == moose::Compartment::initCinfo() )
            // Compartment is base class for SymCompartment.
            if ( current.element()->cinfo()->isA( "Compartment" ) )
            {
                result = current;
                break;
            }
            cstack.push_back( children( current ) );
        }

    return result;
}