FOX/ObjCryst++  2022
Scatterer.cpp
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2002 Vincent Favre-Nicolin vincefn@users.sourceforge.net
3  2000-2001 University of Geneva (Switzerland)
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 //
20 // source file for the base Scatterer classe
21 
22 #include <cmath>
23 #include <typeinfo>
24 #include <cstring>
25 #include <stdio.h> //for sprintf()
26 
27 #include "ObjCryst/ObjCryst/Crystal.h"
28 #include "ObjCryst/ObjCryst/Scatterer.h"
29 
30 #include "ObjCryst/Quirks/VFNStreamFormat.h" //simple formatting of integers, REALs..
31 
32 #include "ObjCryst/Quirks/VFNDebug.h"
33 
34 #ifdef __WX__CRYST__
35  #include "ObjCryst/wxCryst/wxScatterer.h"
36 #endif
37 
38 #include "ObjCryst/ObjCryst/Colours.h"
39 
40 #include <iomanip>
41 #include <fstream>
42 
43 namespace ObjCryst
44 {
45 
46 const RefParType *gpRefParTypeScatt=0;
47 const RefParType *gpRefParTypeScattTransl=0;
48 const RefParType *gpRefParTypeScattTranslX=0;
49 const RefParType *gpRefParTypeScattTranslY=0;
50 const RefParType *gpRefParTypeScattTranslZ=0;
51 const RefParType *gpRefParTypeScattOrient=0;
52 const RefParType *gpRefParTypeScattConform=0;
53 const RefParType *gpRefParTypeScattConformBondLength=0;
54 const RefParType *gpRefParTypeScattConformBondAngle=0;
55 const RefParType *gpRefParTypeScattConformDihedAngle=0;
56 const RefParType *gpRefParTypeScattConformX=0;
57 const RefParType *gpRefParTypeScattConformY=0;
58 const RefParType *gpRefParTypeScattConformZ=0;
59 const RefParType *gpRefParTypeScattOccup=0;
60 long NiftyStaticGlobalObjectsInitializer_Scatterer::mCount=0;
62 //
63 // SCATTERER : generic type of scatterer
64 //
65 //
67 ObjRegistry<Scatterer> gScattererRegistry("Global Scatterer Registry");
68 
69 Scatterer::Scatterer():mXYZ(3),mOccupancy(1.0),mColourName("White"),mpCryst(0)
70 {
71  VFN_DEBUG_MESSAGE("Scatterer::Scatterer()",5)
72  mXYZ=0;
73  this->InitRGBColour();
74  gScattererRegistry.Register(*this);
76 }
77 
79 //RefinableObj(),
80 mXYZ(old.mXYZ),
81 mOccupancy(old.mOccupancy),
82 mColourName(old.mColourName),mpCryst(old.mpCryst)
83 {
84  VFN_DEBUG_MESSAGE("Scatterer::Scatterer(&old)",5)
85  mName=old.GetName();
86  this->InitRGBColour();
87  gScattererRegistry.Register(*this);
89 }
90 
92 {
93  VFN_DEBUG_MESSAGE("Scatterer::~Scatterer():("<<mName<<")",5)
94  gScattererRegistry.DeRegister(*this);
95 }
96 
97 const string& Scatterer::GetClassName() const
98 {
99  const static string className="Scatterer";
100  return className;
101 }
102 
103 REAL Scatterer::GetX() const {return mXYZ(0);}
104 REAL Scatterer::GetY() const {return mXYZ(1);}
105 REAL Scatterer::GetZ() const {return mXYZ(2);}
106 REAL Scatterer::GetOccupancy() const {return mOccupancy;}
107 
108 
109 void Scatterer::SetX(const REAL x) { this->GetPar(mXYZ.data()).MutateTo(x);}
110 void Scatterer::SetY(const REAL y) { this->GetPar(mXYZ.data()+1).MutateTo(y);}
111 void Scatterer::SetZ(const REAL z) { this->GetPar(mXYZ.data()+2).MutateTo(z);}
112 void Scatterer::SetOccupancy(const REAL occupancy)
113 {
115  mOccupancy=occupancy;
116 }
117 
118 Scatterer::operator string() const {return this->GetName();}
119 /*
120 void Scatterer::Print() const
121 {
122  cout << "Scatterer : " << FormatString(this->GetName()) << " at :" ;
123  cout << FormatFloat(this->X());
124  cout << FormatFloat(this->Y());
125  cout << FormatFloat(this->Z());
126  cout << endl;
127 }
128 */
129 
130 const string& Scatterer::GetColour()const{ return mColourName;}
131 const float* Scatterer::GetColourRGB()const{ return mColourRGB;}
132 
135 
136 void Scatterer::SetCrystal(Crystal &cryst){mpCryst=&cryst;}
137 const Crystal& Scatterer::GetCrystal()const{return *mpCryst;}
139 
141 {
142  //mClockScatterer.Click();
143  VFN_DEBUG_MESSAGE("Scatterer::InitRGBColour()",2)
144  for(long i=0;;)
145  {
146  if(gPOVRayColours[i].mName==mColourName)
147  {
148  mColourRGB[0]=gPOVRayColours[i].mRGB[0];
149  mColourRGB[1]=gPOVRayColours[i].mRGB[1];
150  mColourRGB[2]=gPOVRayColours[i].mRGB[2];
151  break;
152  }
153  i++;
154  if(strncmp(gPOVRayColours[i].mName,"",3 )==0)
155  {//could not find colour !
156  cout << "Could not find colour:"<<mColourName<<" for scaterrer "<<mName<<endl;
157  mColourRGB[0]=1;
158  mColourRGB[1]=1;
159  mColourRGB[2]=1;
160  break;
161  }
162  }
163  VFN_DEBUG_MESSAGE("->RGBColour:"<<mColourName<<mColourRGB[0]<<" "<<mColourRGB[1]<<" "<<mColourRGB[2],2)
164 }
165 #ifdef __WX__CRYST__
166 WXCrystObjBasic* Scatterer::WXCreate(wxWindow* parent)
167 {
168  //:TODO: Check mpWXCrystObj==0
169  mpWXCrystObj=new WXScatterer(parent,this);
170  return mpWXCrystObj;
171 }
172 #endif
173 
174 }//namespace
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: doc-main.h:25
ObjRegistry< Scatterer > gScattererRegistry("Global Scatterer Registry")
Global registry for all Scatterer objects.
Definition: Scatterer.h:315
Crystal class: Unit cell, spacegroup, scatterers.
Definition: Crystal.h:98
Generic type of scatterer: can be an atom, or a more complex assembly of atoms.
Definition: Scatterer.h:131
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
Definition: Scatterer.cpp:97
string mColourName
Colour for this scatterer (from POVRay)
Definition: Scatterer.h:291
Crystal * mpCryst
The crystal in which the Scatterer is This is needed so that we can know which scattering powers are ...
Definition: Scatterer.h:304
virtual void InitRGBColour()
Get RGB Colour coordinates from Colour Name.
Definition: Scatterer.cpp:140
virtual ~Scatterer()
Destructor.
Definition: Scatterer.cpp:91
virtual void SetZ(const REAL z)
Z coordinate (fractionnal) of the scatterer (for complex scatterers, this corresponds to the position...
Definition: Scatterer.cpp:111
virtual void SetY(const REAL y)
Y coordinate (fractionnal) of the scatterer (for complex scatterers, this corresponds to the position...
Definition: Scatterer.cpp:110
virtual const float * GetColourRGB() const
Colour associated to this scatterer, 3 RGB Coordinates.
Definition: Scatterer.cpp:131
Scatterer()
Constructor.
Definition: Scatterer.cpp:69
REAL GetOccupancy() const
Get the occupancy of the scatterer (0.
Definition: Scatterer.cpp:106
const Crystal & GetCrystal() const
In which crystal is this Scatterer included ?
Definition: Scatterer.cpp:137
CrystVector_REAL mXYZ
coordinates of the scatterer (or of its center..)
Definition: Scatterer.h:283
REAL GetX() const
X coordinate (fractionnal) of the scatterer (for complex scatterers, this corresponds to the position...
Definition: Scatterer.cpp:103
const RefinableObjClock & GetClockScatterer() const
Last time anything in the scatterer was changed (atoms, positions, scattering power)
Definition: Scatterer.cpp:133
float mColourRGB[3]
Colour for this scatterer using RGB.
Definition: Scatterer.h:293
virtual const string & GetColour() const
Colour associated to this scatterer (using POVRay names)
Definition: Scatterer.cpp:130
REAL GetZ() const
Z coordinate (fractionnal) of the scatterer (for complex scatterers, this corresponds to the position...
Definition: Scatterer.cpp:105
RefinableObjClock mClockScatterer
Last time anything (number of atoms, positions, scattering power) was changed.
Definition: Scatterer.h:295
void SetCrystal(Crystal &)
Set the crystal in which is included this Scatterer.
Definition: Scatterer.cpp:136
REAL mOccupancy
Occupancy : 0 <= occ <= 1 For a multi-atom scatterer (polyhedron,..), this is the overall occupancy o...
Definition: Scatterer.h:289
REAL GetY() const
Y coordinate (fractionnal) of the scatterer (for complex scatterers, this corresponds to the position...
Definition: Scatterer.cpp:104
virtual void SetOccupancy(const REAL occupancy)
Change the occupancy of the scatterer (0.
Definition: Scatterer.cpp:112
virtual void SetX(const REAL x)
X coordinate (fractionnal) of the scatterer (for complex scatterers, this corresponds to the position...
Definition: Scatterer.cpp:109
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
Definition: RefinableObj.h:140
void AddChild(const RefinableObjClock &)
Add a 'child' clock.
void Click()
Record an event for this clock (generally, the 'time' an object has been modified,...
void MutateTo(const REAL newValue)
Change the current value to the given one.
RefinablePar & GetPar(const long i)
Access all parameters in the order they were inputted.
virtual const string & GetName() const
Name of the object.
RefinableObjClock mClockMaster
Master clock, which is changed whenever the object has been altered.
string mName
Name for this RefinableObject. Should be unique, at least in the same scope.+.
Abstract base class for all objects in wxCryst.
Definition: wxCryst.h:128
base wxCryst class for Scatterers
Definition: wxScatterer.h:36