[gme-users] cloning of models using BON

Zoltan Molnar zolmol at isis.vanderbilt.edu
Thu Mar 27 17:19:53 CDT 2008


FYI, new method in BON1.
The new method for cloning, CloneHere, implemented as a public member of
CBuilderModel, found below:

CBuilderObject *CBuilderModel::CloneHere( CBuilderObject* orig)
{
	CComPtr<IMgaFCO>   src_obj = orig->GetIObject();
	CComPtr<IMgaModel> par_obj = GetIModel();

	CComPtr<IMgaFCOs>       fco_coll;  // ptr to a collection of
IMgaFCO objects
	CComPtr<IMgaMetaRoles>  rol_coll;  // same
	fco_coll.CoCreateInstance( L"Mga.MgaFCOs");        // create an
empty 'array' of MgaFCO objects
	rol_coll.CoCreateInstance( L"Mga.MgaMetaRoles");   // same

	// fco collection with 1 element
	fco_coll->Append( src_obj);

	CComPtr<IMgaMetaRole> role;
	src_obj->get_MetaRole(&role);
	
	// role collection with 1 element
	rol_coll->Append( role); // based on the assumption that the
parent of src_obj is of same or similar kind to par_obj

	CComPtr<IMgaFCOs> dst_coll;
	par_obj->CopyFCOs( fco_coll, rol_coll, &dst_coll);

	// analyze dst_coll
	long l = 0;
	if( dst_coll) dst_coll->get_Count( &l);

	CBuilderObject *return_value = 0;
	for( int i = 1; i <= l; ++i)
	{
		CComPtr<IMgaFCO> dst;
		dst_coll->get_Item( i, &dst);

		objtype_enum ot;
		if( dst) dst->get_ObjType( &ot);
		if( ot == OBJTYPE_ATOM)
		{
			CBuilderAtom* o =
CBuilderFactory::Create(CComQIPtr<IMgaAtom>(dst), this);

			children.AddTail(o);

			CBuilderAtomList *objectlist;
			VERIFY( atomLists.Lookup( o->GetPartName(),
objectlist) );
			objectlist->AddTail(o);

			return_value = o;
		}
		else if( ot == OBJTYPE_MODEL)
		{
			CBuilderModel* o = CBuilderFactory::Create(
CComQIPtr<IMgaModel>(dst), this);
			o->Resolve();

			children.AddTail(o);
			models.AddTail(o);

			CBuilderModelList *objectlist;
			VERIFY( modelLists.Lookup( o->GetPartName(),
objectlist) );
			objectlist->AddTail(o);

			return_value = o;
		}
		else if( ot == OBJTYPE_SET)
		{
			CBuilderSet* o = CBuilderFactory::Create(
CComQIPtr<IMgaSet>(dst), this);

			FindSets( o->GetPartName())->AddTail( o);
			sets.AddTail(o);
			children.AddTail(o);

			return_value = o;
		}
		else if( ot == OBJTYPE_REFERENCE)
		{
			CBuilderReference* oo =
CBuilderFactory::Create(CComQIPtr<IMgaReference>(dst), this);

			CBuilderReferenceList *objectlist;
			VERIFY( referenceLists.Lookup(
oo->GetPartName(), objectlist) );
			objectlist->AddTail(oo);

			children.AddTail(oo);

	
if(oo->IsKindOf(RUNTIME_CLASS(CBuilderModelReference)) ) {
					CBuilderModelReferenceList
*mobjectlist;
					VERIFY(
modelReferenceLists.Lookup(oo->GetPartName(), mobjectlist) );
	
mobjectlist->AddTail((CBuilderModelReference *)oo);
			}
			else
if(oo->IsKindOf(RUNTIME_CLASS(CBuilderAtomReference)) ) {
					CBuilderAtomReferenceList
*aobjectlist;
					VERIFY(
atomReferenceLists.Lookup(oo->GetPartName(), aobjectlist) );
	
aobjectlist->AddTail((CBuilderAtomReference *)oo);
			}

			return_value = oo;
		}
	}

	return return_value;
}

The Builder.h file needs to be modified to contain this member method
declaration 
in CBuilderModel class:

	CBuilderObject *CloneHere( CBuilderObject* orig);

All this will be available in the next public release.

Zoli

> -----Original Message-----
> From: gme-users-bounces at list.isis.vanderbilt.edu 
> [mailto:gme-users-bounces at list.isis.vanderbilt.edu] On Behalf 
> Of Sumant Tambe
> Sent: Friday, March 21, 2008 1:20 PM
> To: gme-users
> Subject: Re: [gme-users] cloning of models using BON
> 
> 
> Hi Zoli,
> 
> Thanks for the code. I'm integrating it into my program now. I'm not 
> sure how to get a handle to the copied object from your copy 
> function. Can you please tell what needs to change so that it 
> can return a handle?
> 
> Thanks,
> 
> Sumant.
> 
> Zoltan Molnar wrote:
> > Oh, sorry. BON1 might not have such functionality 
> implemented, but the 
> > underlying COM functionality allows easy implementation of it:
> > 
> > The COM methods of IMgaModel look like this:
> > 		HRESULT MoveFCOs([in] IMgaFCOs * to_copy, [in] 
> IMgaMetaRoles 
> > *destroles, [out] IMgaFCOs **objs);
> > 		HRESULT CopyFCOs([in] IMgaFCOs * to_move, [in] 
> IMgaMetaRoles 
> > *destroles, [out] IMgaFCOs **objs);
> > 
> > 
> > So a helper method to benefit from these could look like this: void 
> > copy( CBuilderModel* where_to_copy, CBuilderObject *to_copy) {
> > 	CComPtr<IMgaFCO>   src_obj = to_copy->getIObject();
> > 	CComPtr<IMgaModel> par_obj = where_to_copy->GetIModel();
> > 
> > 	CComPtr<IMgaFCOs>       fco_coll;  // ptr to a collection of
> > IMgaFCO objects
> > 	CComPtr<IMgaMetaRoles>  rol_coll;  // same
> > 	fco_coll.CoCreateInstance( L"Mga.MgaFCOs");        // create an
> > empty 'array' of MgaFCO objects
> > 	rol_coll.CoCreateInstance( L"Mga.MgaMetaRoles"));  // same
> > 
> > 	// fco collection with 1 element
> > 	fco_coll->Append( src_obj);
> > 
> > 	CComPtr<IMgaMetaRole> role;
> > 	src_obj->get_MetaRole(&role);
> > 	
> > 	// role collection with 1 element
> > 	rol_coll->Append( role); // based on the assumption 
> that the parent 
> > of src_obj is of same or similar kind to par_obj
> > 
> > 	CComPtr<IMgaFCOs> dst_coll;
> > 	par_obj->CopyFCOs( fco_coll, rol_coll, &dst_coll);
> > 
> > 	// analyze dst_coll
> > 	long l = 0;
> > 	if( dst_coll) dst_coll->get_Count( &l);
> > 	for( int i = 1; i <= l; ++i)
> > 	{
> > 		CComPtr<IMgaFCO> dst;
> > 		dst_coll->get_Item( i, &dst);
> > 	}
> > }
> > 
> > Let me know if you need something else,
> > Zoli
> > 
> >> -----Original Message-----
> >> From: gme-users-bounces at list.isis.vanderbilt.edu
> >> [mailto:gme-users-bounces at list.isis.vanderbilt.edu] On Behalf 
> >> Of Sumant Tambe
> >> Sent: Friday, March 21, 2008 11:22 AM
> >> To: gme-users
> >> Subject: Re: [gme-users] cloning of models using BON
> >>
> >>
> >> Hi Zoli,
> >>
> >> It is a part of BON2 I believe. I'm wondering if similar 
> thing can be
> >> done using BON. I need that because I'm maintaining legacy 
> >> code written 
> >> using BON.
> >>
> >> Thanks,
> >>
> >> Sumant.
> >>
> >> Zoltan Molnar wrote:
> >>> Sumant,
> >>>
> >>> There is a method called copy, and another called move. copy's
> >>> signature is as follows:
> >>>
> >>> FCOImpl::copy( Folder& parent)
> >>> FCOImpl::copy( Model& parent, std::string& role)
> >>>
> >>>
> >>> Zoli
> >>>
> >>>
> >>>> -----Original Message-----
> >>>> From: gme-users-bounces at list.isis.vanderbilt.edu
> >>>> [mailto:gme-users-bounces at list.isis.vanderbilt.edu] On Behalf
> >>>> Of Sumant Tambe
> >>>> Sent: Thursday, March 20, 2008 8:34 PM
> >>>> To: gme-users
> >>>> Subject: [gme-users] cloning of models using BON
> >>>>
> >>>>
> >>>> Hi folks,
> >>>>
> >>>> Is there a way to programatically duplicate or clone a 
> model using 
> >>>> BON? Effect should be same as that of a manual copy-paste 
> >>>> operation, which does a deep-copy of the source model.
> >>>>
> >>>> Thanks,
> >>>>
> >>>> Sumant.
> >>>> _______________________________________________
> >>>> gme-users mailing list
> >>>> gme-users at list.isis.vanderbilt.edu
> >>>> http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users
> >>>>
> >>> _______________________________________________
> >>> gme-users mailing list
> >>> gme-users at list.isis.vanderbilt.edu
> >>> http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users
> >> _______________________________________________
> >> gme-users mailing list
> >> gme-users at list.isis.vanderbilt.edu
> >> http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users
> >>
> > _______________________________________________
> > gme-users mailing list
> > gme-users at list.isis.vanderbilt.edu
> > http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users
> _______________________________________________
> gme-users mailing list
> gme-users at list.isis.vanderbilt.edu
> http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users
> 


More information about the gme-users mailing list