Skip to content

Commit a92e541

Browse files
committed
Add PowderPattern::RemovePowderPatternComponent and wxPowderPattern::OnMenuRemoveComp
1 parent c1fb1d6 commit a92e541

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

ObjCryst/ObjCryst/PowderPattern.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,43 @@ void PowderPattern::AddPowderPatternComponent(PowderPatternComponent &comp)
26042604
VFN_DEBUG_EXIT("PowderPattern::AddPowderPatternComponent():"<<comp.GetName(),5)
26052605
}
26062606

2607+
void PowderPattern::RemovePowderPatternComponent(PowderPatternComponent &comp)
2608+
{
2609+
VFN_DEBUG_ENTRY("PowderPattern::RemovePowderPatternComponent():"<<comp.GetName(),5)
2610+
if(comp.IsScalable())
2611+
{
2612+
// Remove one scale factor parameter
2613+
cout<<"PowderPattern::RemovePowderPatternComponent: removing 1 scale paramater"<<endl;
2614+
this->Print();
2615+
this->RemovePar(&this->GetPar(mScaleFactor.data()+mPowderPatternComponentRegistry.GetNb()-1));
2616+
this->Print();
2617+
}
2618+
2619+
this->RemoveSubRefObj(comp);
2620+
comp.DeRegisterClient(*this);
2621+
mClockPowderPatternCalc.Reset();
2622+
mClockIntegratedFactorsPrep.Reset();
2623+
mPowderPatternComponentRegistry.DeRegister(comp);
2624+
2625+
// Shift scale factors
2626+
unsigned int i=0;
2627+
for(unsigned int i=0;i<this->GetNbPowderPatternComponent();i++)
2628+
if(&comp == &this->GetPowderPatternComponent(i)) break;
2629+
for(unsigned int j=i;j<this->GetNbPowderPatternComponent()-1;j++) mScaleFactor(j) = mScaleFactor(j+1);
2630+
2631+
mClockScaleFactor.Click();
2632+
this->UpdateDisplay();
2633+
VFN_DEBUG_EXIT("PowderPattern::RemovePowderPatternComponent():"<<comp.GetName(),5)
2634+
}
2635+
2636+
void PowderPattern::RemovePowderPatternComponent(const int i)
2637+
{
2638+
VFN_DEBUG_ENTRY("PowderPattern::RemovePowderPatternComponent():"<<i,5)
2639+
this->RemovePowderPatternComponent(mPowderPatternComponentRegistry.GetObj(i));
2640+
VFN_DEBUG_EXIT("PowderPattern::RemovePowderPatternComponent():"<<i,5)
2641+
}
2642+
2643+
26072644
unsigned int PowderPattern::GetNbPowderPatternComponent()const
26082645
{
26092646
return mPowderPatternComponentRegistry.GetNb();

ObjCryst/ObjCryst/PowderPattern.h

+4
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,10 @@ class PowderPattern : public RefinableObj
591591
* are automatically changed to that of the PowderPattern object.
592592
*/
593593
void AddPowderPatternComponent(PowderPatternComponent &);
594+
/// Remove a powder pattern component
595+
void RemovePowderPatternComponent(PowderPatternComponent &);
596+
/// Remove a powder pattern component
597+
void RemovePowderPatternComponent(const int i);
594598
/// Number of components
595599
unsigned int GetNbPowderPatternComponent()const;
596600
/// Access to a component of the powder pattern

ObjCryst/wxCryst/wxPowderPattern.cpp

+43-3
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ class WXProfileFitting:public wxWindow
172172
// WXPowderPattern
173173
//
174174
////////////////////////////////////////////////////////////////////////
175-
static const long ID_POWDER_MENU_COMP_ADDBACKGD_BAYESIAN=WXCRYST_ID();
176-
static const long ID_POWDER_MENU_COMP_ADDBACKGD= WXCRYST_ID();
177-
static const long ID_POWDER_MENU_COMP_ADDCRYST= WXCRYST_ID();
175+
static const long ID_POWDER_MENU_COMP_ADDBACKGD_BAYESIAN= WXCRYST_ID();
176+
static const long ID_POWDER_MENU_COMP_ADDBACKGD= WXCRYST_ID();
177+
static const long ID_POWDER_MENU_COMP_ADDCRYST= WXCRYST_ID();
178+
static const long ID_POWDER_MENU_COMP_REMOVE= WXCRYST_ID();
178179
static const long ID_POWDER_MENU_GRAPH= WXCRYST_ID();
179180
static const long ID_POWDER_MENU_SAVETEXT= WXCRYST_ID();
180181
static const long ID_POWDER_MENU_SIMULATE= WXCRYST_ID();
@@ -236,6 +237,7 @@ BEGIN_EVENT_TABLE(WXPowderPattern, wxWindow)
236237
EVT_MENU(ID_POWDER_MENU_COMP_ADDBACKGD, WXPowderPattern::OnMenuAddCompBackgd)
237238
EVT_MENU(ID_POWDER_MENU_COMP_ADDBACKGD_BAYESIAN, WXPowderPattern::OnMenuAddCompBackgdBayesian)
238239
EVT_MENU(ID_POWDER_MENU_COMP_ADDCRYST, WXPowderPattern::OnMenuAddCompCryst)
240+
EVT_MENU(ID_POWDER_MENU_COMP_REMOVE, WXPowderPattern::OnMenuRemoveComp)
239241
EVT_MENU(ID_POWDER_MENU_SAVETEXT, WXPowderPattern::OnMenuSaveText)
240242
EVT_MENU(ID_POWDER_MENU_SIMULATE, WXPowderPattern::OnMenuSimulate)
241243
EVT_MENU(ID_POWDER_MENU_IMPORT_FULLPROF, WXPowderPattern::OnMenuImportPattern)
@@ -333,6 +335,8 @@ mChi2(0.0),mGoF(0.0),mRwp(0.0),mRp(0.0)
333335
"Add user-supplied Background ");
334336
mpMenuBar->AddMenuItem(ID_POWDERPATTERN_MENU_COMPONENTS,ID_POWDER_MENU_COMP_ADDCRYST,
335337
"Add Crystalline Phase");
338+
mpMenuBar->AddMenuItem(ID_POWDERPATTERN_MENU_COMPONENTS,ID_POWDER_MENU_COMP_REMOVE,
339+
"Remove background or crystalline phase");
336340
mpMenuBar->AddMenu("Radiation",ID_POWDER_MENU_WAVELENGTH);
337341
mpMenuBar->AddMenuItem(ID_POWDER_MENU_WAVELENGTH,
338342
ID_POWDER_MENU_WAVELENGTH_NEUTRON,
@@ -729,6 +733,42 @@ void WXPowderPattern::OnMenuAddCompCryst(wxCommandEvent & WXUNUSED(event))
729733
VFN_DEBUG_EXIT("WXPowderPattern::OnMenuAddCompCryst()",10)
730734
}
731735

736+
void WXPowderPattern::OnMenuRemoveComp(wxCommandEvent & WXUNUSED(event))
737+
{
738+
VFN_DEBUG_ENTRY("WXPowderPattern::OnMenuRemoveComp()",10)
739+
WXCrystValidateAllUserInput();
740+
// Update names
741+
for(unsigned int i=0;i<this->GetPowderPattern().GetNbPowderPatternComponent();i++)
742+
{
743+
PowderPatternComponent &comp=this->GetPowderPattern().GetPowderPatternComponent(i);
744+
if(comp.GetClassName()=="PowderPatternBackground")
745+
comp.SetName("Background");
746+
else
747+
{
748+
PowderPatternDiffraction* pdiff=dynamic_cast<PowderPatternDiffraction*> (&comp);
749+
if(pdiff) comp.SetName("Crystal:" + pdiff->GetCrystal().GetName());
750+
else cout<<"WXPowderPattern::OnMenuRemoveComp(): could not recognize:"<<comp.GetClassName()<<":"<<comp.GetName()<<endl;
751+
}
752+
}
753+
int choice;
754+
PowderPatternComponent *comp= WXDialogChooseFromRegistry(this->GetPowderPattern().mPowderPatternComponentRegistry,(wxWindow*)this,
755+
"Choose a component to remove:",choice);
756+
if(0==comp)
757+
{
758+
VFN_DEBUG_EXIT("WXPowderPattern::OnMenuRemoveComp(): Canceled",10)
759+
return;
760+
}
761+
VFN_DEBUG_MESSAGE("WXPowderPattern::OnMenuRemoveComp()",10)
762+
this->GetPowderPattern().RemovePowderPatternComponent(*comp);
763+
VFN_DEBUG_MESSAGE("WXPowderPattern::OnMenuRemoveComp()",10)
764+
if(mpGraph!=0) mpPowderPattern->Prepare();//else this will be done when opening the graph
765+
wxTheApp->GetTopWindow()->Layout();
766+
wxTheApp->GetTopWindow()->SendSizeEvent();
767+
this->CrystUpdate();
768+
VFN_DEBUG_EXIT("WXPowderPattern::OnMenuRemoveComp()",10)
769+
}
770+
771+
732772
class WXPowderPatternGraphFrame :public wxFrame
733773
{
734774
public:

ObjCryst/wxCryst/wxPowderPattern.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class WXPowderPattern: public WXRefinableObj
3939
void OnMenuAddCompBackgd(wxCommandEvent & WXUNUSED(event));
4040
void OnMenuAddCompBackgdBayesian(wxCommandEvent & WXUNUSED(event));
4141
void OnMenuAddCompCryst(wxCommandEvent & WXUNUSED(event));
42+
void OnMenuRemoveComp(wxCommandEvent & WXUNUSED(event));
4243
void OnMenuShowGraph(wxCommandEvent & WXUNUSED(event));
4344
void OnMenuSaveText(wxCommandEvent & WXUNUSED(event));
4445
void OnMenuSimulate(wxCommandEvent & WXUNUSED(event));

0 commit comments

Comments
 (0)