[gme-users] Feedback: Removing/deleting model elements in BON1

Jane Lin liny at cis.uab.edu
Tue Mar 14 09:09:02 CST 2006


Hi Zoli,

A couple of weeks ago, I implemented the deleting operations (e.g., to
delete an atom from a model and delete a submodel from  a model) based on
the sample codes you provided, the only difference is my DeleteSelected
methods are used to delete a single atom or a single submodel, but yours are
used to delete a list. However, if I tried to find the the deleted atom
right after it was deleted, I still could find it!!!  Is this a transaction
boundary issue?

The following is the code I used to test this:

void CComponent::InvokeEx(CBuilder &builder,CBuilderObject *focus, 
CBuilderObjectList &selected, long param)
{
  //work with focused model
 const CBuilderObjectList *children = ((CBuilderModel
*)focus)->GetChildren();
 POSITION pos = children->GetHeadPosition();
 while(pos){
  CBuilderObject *child = children->GetNext(pos);
  CString childName;
  childName = child->GetName();
  if(childName == "S1") {
   AfxMessageBox("S1 found!");
   ((CMySmartModel *)focus)->DeleteSelected((CMySmartAtom *)child);
  }
 }
 //find S1 again, it should not be found!
 const CBuilderObjectList *children2 = ((CBuilderModel
*)focus)->GetChildren();
 POSITION pos2 = children2->GetHeadPosition();
 while(pos2){
  CBuilderObject *child = children2->GetNext(pos2);
  CString childName;
  childName = child->GetName();
  if(childName == "S1") {
   AfxMessageBox("S1 found again!");
  }
 }
 return;
}
-----------------------------------------------------------------------
The sample codes I put in Component.h:
---------------------------------------------------------------------
class CMySmartModel : public CBuilderModel
{
DECLARE_CUSTOMMODEL(CMySmartModel, CBuilderModel)
public:
void deleteMySelf();
void DeleteSelected(CMySmartAtom *childAtom);
void DeleteSelected( CMySmartModel *childModel);
virtual ~CMySmartModel() { }
};
class CMySmartAtom : public CBuilderAtom
{
DECLARE_CUSTOMATOM(CMySmartAtom, CBuilderAtomerence)
public:
virtual ~CMySmartAtom() { }
void deleteMySelf();
};
----------------------------------------------------------------------------
The codes I put in Component.cpp
----------------------------------------------------------------------------
void CMySmartModel::DeleteSelected( CMySmartAtom *childAtom) {
 ASSERT( childAtom );
 this->RemoveAtom( childAtom);//delete builder object which type is Atom
 childAtom->deleteMySelf();//delete MGA object
}

void CMySmartModel::DeleteSelected( CMySmartModel *childModel) {
 ASSERT( childModel );
 this->RemoveModel( childModel );//delete builder object which type is Model
 childModel->deleteMySelf();//delete MGA object
}

void CMySmartModel::deleteMySelf()
{
 CComPtr<IMgaFCO> my_mga_ptr = this->ciObject;
 my_mga_ptr->DestroyObject();
}

void CMySmartAtom::deleteMySelf()
{
 CComPtr<IMgaFCO> my_mga_ptr = this->ciObject;
 my_mga_ptr->DestroyObject();
}


Jane
---------------------------------------------------------------------------------
Yuehua (Jane) Lin
Department of Computer and Information Sciences
University of Alabama at Birmingham
liny at cis.uab.edu
http://www.cis.uab.edu/liny


----- Original Message ----- 
From: "Zoltan Molnar" <zolmol at isis.vanderbilt.edu>
To: "gme-users" <gme-users at list.isis.vanderbilt.edu>
Sent: Thursday, February 02, 2006 4:28 PM
Subject: RE: [gme-users] Removing/deleting model elements in BON1


> Hi,
>
> If case of BON1 interpreters: let me make clear what I meant by ''used
> in destructors'': BON1 uses that method internally in its destructors.
>
>> The protected RemoveAtom & co. methods release objects only from the
>> Builder structure, [they are used mostly in destructors], and they do
>> not provide the functionality you would like to have: to remove an
>> atom from the gme model.
>>
>
>
> As Akos suggested if you subclass the CBuilderObject then you may access
> some of its protected members.
> Here you can find a COM based Delete implemented, using subclassing,
> thus acquiring the ciObject [a COM pointer] member of CBuilderObject and
> invoking the DestroyObject COM method on it. This DestroyObject deletes
> the MGA object (the object sitting in GME's window).
> The C++ builder objects need to be deleted also, that is why
> RemoveReference( obj) is called in CMySmartModel::DeleteSelected.
>
> CMySmartObj is an object which I could delete, CMySmartModel is its
> parent model.
>
> Br, Zoli
>
> -----------------put these into Component.h---------------------
> class CMySmartObj;
> typedef CTypedPtrList<CPtrList, CMySmartObj*> CMySmartObjList;
>
> class CMySmartModel : public CBuilderModel
> {
> DECLARE_CUSTOMMODEL(CMySmartModel, CBuilderModel)
> public:
> virtual void Traverse(CMySmartObjList &list);
> void DeleteSelected( CMySmartObjList &list);
> virtual ~CMySmartModel() { }
> };
>
> class CMySmartObj : public CBuilderReference
> {
> DECLARE_CUSTOMREF(CMySmartObj, CBuilderReference)
> public:
> virtual ~CMySmartObj() { }
> void deleteMySelf();
> };
>
> ----------------------put these into component.cpp---------------
>
>
> IMPLEMENT_CUSTOMMODEL(CMySmartModel, CBuilderModel, "configuration")
> IMPLEMENT_CUSTOMREF( CMySmartObj, CBuilderReference, "interface_ref")
>
> void CMySmartModel::Traverse(CMySmartObjList &lst)
> {
> const CBuilderReferenceList *ref_list =
> GetReferences("interface_ref");
> POSITION pos = ref_list->GetHeadPosition();
> while(pos)
> {
> CMySmartObj *obj = (CMySmartObj
> *)ref_list->GetNext(pos);
> ASSERT( obj);
> lst.AddTail( obj);
> }
> }
>
>
> void CMySmartModel::DeleteSelected(CMySmartObjList &smart_lst)
> {
> POSITION pos = smart_lst.GetHeadPosition();
> while(pos)
> {
> CMySmartObj *obj = (CMySmartObj
> *)smart_lst.GetNext(pos);
> ASSERT( obj);
> this->RemoveReference( obj);
> obj->deleteMySelf();
> }
>
> // test:
> // trying to acquire one more time
> const CBuilderReferenceList *ref_list =
> GetReferences("interface_ref");
> pos = ref_list->GetHeadPosition();
> while(pos)
> {
> // it should not enter this loop
> CMySmartObj *obj = (CMySmartObj
> *)ref_list->GetNext(pos);
> ASSERT( obj);
> obj->deleteMySelf();
> }
> // end test
> }
>
> void CMySmartObj::deleteMySelf()
> {
> CComPtr<IMgaFCO> my_mga_ptr = this->ciObject;
> my_mga_ptr->DestroyObject();
> }
>
>
> // traverses models inside topfolders and deletes all occurences of a
> certain reference kind
> void test2(CBuilder &builder,CBuilderObject *focus, CBuilderObjectList
> &selected, long param)
> {
> CBuilderFolder *rf = builder.GetRootFolder();
>
> CBuilderFolder *lastFolder = 0;
> const CBuilderFolderList * flds = rf->GetSubFolders();
> POSITION pos = flds->GetHeadPosition();
> while( pos)
> {
> CBuilderFolder *fld = flds->GetNext( pos);
> lastFolder = fld;
>
> const CBuilderObjectList *lst =
> lastFolder->GetRootObjects();
> POSITION pos = lst->GetHeadPosition();
> while( pos)
> {
> CBuilderObject *obj = lst->GetNext( pos);
> if(obj->IsKindOf(RUNTIME_CLASS(CMySmartModel)))
> {
> CMySmartObjList list;
> // fill the list with MySmartObjs
> CMySmartModel *smodel = (CMySmartModel
> *) obj;
> smodel->Traverse(list);
>
> // now delete them
> smodel->DeleteSelected( list);
> }
> }
> }
> }
>
> void CComponent::InvokeEx(CBuilder &builder,CBuilderObject *focus,
> CBuilderObjectList &selected, long param)
> {
> test2( builder, focus, selected, param);
> }
> _______________________________________________
> 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