Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
ScanBinder.h
Go to the documentation of this file.
1#pragma once
2#include "Namespace.h"
3#include <gii/gen/Variable.h>
7#include <math/Types.h>
10#include <string_view>
11
12namespace sf
13{
14// Forward declarations.
15class ProjectData;
16class ScanEntry;
17class ScanMethod;
18class ProjectDataPropertyPage;
19class CheckPositionsPropertyPage;
20class ScanMethodPositionPropertyPage;
21
22constexpr std::string_view DEFAULT_SCANBINDERNAME("<default>");
23constexpr std::string_view SEC_BINDER_GENERAL("Scan Binder");
24constexpr std::string_view KEY_IGNOREOFFSET("Ignore Project Offset");
25
30{
31 public:
36 {
40 InfoBase() = default;
41
45 virtual ~InfoBase() = default;
46
54 virtual void ReadWrite(IniProfile* ini, bool rd);
55
56 bool IgnoreFixtureOffset{false};
57 };
58
66
67 // Constructor for passing general structure for derived classes.
68 explicit ScanBinder(const Parameters& parameters);
69 // Destructor.
70 ~ScanBinder() override;
71 //
72 // Functions for the project to control the additional data.
73 //
74 // Reads and writes system configuration data.
75 void ReadWriteConfig(bool rd);
76 // For reading and write the current state of this instance and derived classes.
77 ConfigStore& GetSaveState();
78 // Adds the scan binder property pages of the base class.
79 // May be overloaded by derived class.
81 // Called by the project to make the binder create the additional information.
83 // Called by the project to make the binder delete the additional information.
84 void DeleteScanEntry(const ScanEntry* se);
85 // Adds property pages for derived classes by calling virtual method AddPropertyPages.
86 // When scan is true it gets the property pages which are scan related when false it gets the project selected property pages.
87 void DoAddPropertyPages(PropertySheetDialog* sheet, bool scan);
88 // Creates a scan binder frame if possible.
89 QWidget* DoGetFrame();
90 // Reads the settings from the passed inifile.
91 void DoReadProfile(IniProfile& inifile);
92 // Writes the settings to the passed inifile.
93 void DoWriteProfile(IniProfile& inifile);
94 // Do some initialization which must be done before scan initializations.
96 // Initializes the scan method. Is each time a project changes.
98 // Called from the project and rooted to the virtual Sustain function.
99 void DoSustain(timespec clk);
100 // Clears any settings of the scan binder to their initial state.
101 void DoClear();
102 // Suspends action at a convenient position or immediate.
103 bool DoSuspend(bool immediate);
104 // Resumes a suspended action.
105 bool DoResume();
106 // Stops activity immediately.
107 bool DoStop();
108 // Abort immediately stop all movement.
109 bool DoAbort();
110 // Moves the manipulator to a specific position.
111 bool DoMoveTo(int scan, int index = -1, double frac = 0.0, bool rect = false);
112 // Queries for a surface position of the user.
113 bool DoMoveToQuery(int scan);
114 // Moves to one of the system positions.
116 // Starts position checking mode and a scan method in checking mode.
117 // This means the angle on the surface is always zero degree to get
118 // a better signal from the surface.
119 bool DoCheck(int scan);
120 // Starts scan movements and a scan method for data recording.
121 bool DoScan(int scan);
122 // Start in evaluation mode and a scan method in evaluation mode.
123 // This means the angle on the surface is the same as when evaluating but
124 // movements are initiated by the DoMoveTo function.
125 bool DoEvaluate(int scan);
126 // Activates possible added links and parameters in a derived instance.
127 bool DoActivate(int scan);
128 // Starts rotating the scan axis if one is available for rotation using
129 // the scan rotation speed at the passed index or when index is -1 it uses
130 // the last index position. When scan is -1 the rotation stops.
131 bool DoRotate(int scan, int index = -1);
132 // Returns true if the passed scan is able to rotate regardless the current state.
133 bool CanRotate(int scan) const;
134 // Returns true if the rotating is active.
135 bool IsRotating() const;
136 // Returns the current scanning index. Is for progress purposes.
137 int DoGetIndex() const;
138 // Returns the sum of offsets generated by the derived scan binder.
139 // When not this function returns the same value as the fixture offset.
140 Vector3D DoGetOffset() const;
141
142 // States
144 {
146 sbsCFGERR = -2,
148 sbsERROR = -1,
150 sbsNOINIT = 0,
153 /*
154 * Controller is freed for usage by other modules.
155 */
169 sbsEVALUATING
170 };
171
172 // Gets the state name string.
173 static const char* GetStateName(EState state);
174 // Gets the current state name.
175 const char* GetStateName() const;
176 // Gets the state of the instance
177 EState GetState() const;
178 // Gets the velocity used to manipulate.
180 // Gets the acceleration used to manipulate.
181 const gmi::AxesCoord& GetAcceleration() const;
182 // Gets the project park position.
183 const gmi::AxesCoord& GetParkPosition() const;
184 // Gets the project park position.
185 const gmi::AxesCoord& GetToolPosition() const;
186 // Gets the fixture offset for the project applied on each scan.
187 const Vector3D& GetFixtureOffset() const;
188 // Gets the medium sound velocity variable.
189 const Variable& GetMediumVelocity() const;
190 // Gets the active scan index when the state is active or higher an -1 when not active.
192 // Gets the scan progress when scanning otherwise it returns -1.
193 double GetScanProgress() const;
194 // Gets true if the controller can be allocated.
195 bool CanAllocateController() const;
196 // Gets true is the controller is allocated.
197 bool IsControllerAllocated() const;
198 // Allocates or frees the controller for this project.
199 bool AllocateController(bool alloc);
200 // Gets the allocated controller for this project if not allocated it throws an exception and should be regarded as a design error.
202 const gmi::Controller* GetController() const;
203 // Sets the pop to manual state on the acquisition device.
205 // Gets true if the pop manual process is completed.
207 // Enables or disables programming velocity.
208 void SetProgVelocityEnable(bool enabled);
209 bool GetProgVelocityEnable() const;
210 // Gets the local variables of the scan binder.
211 const Variable::PtrVector& GetVars() const;
212
213 protected:
214 // Gets the scan position at the passed scan index.
216 gmi::AxesCoord& pos,// Returned axes coordinated.
217 int scan,// Scan list index.
218 int index,// Measurement index.
219 double frac,// Scan line fraction.
220 bool rect// When true the rectangular position if possible is returned.
221 ) const;
222 // Gets the current project active scan index and -1 one if not active.
224 // Gets the scan method of the project.
225 ScanMethod* GetScan(int scan) const;
226 // Gets true if the state was successfully set.
227 bool SetState(EState state);
228 // Gets the scan information of the passed project scan list index.
230 const InfoBase* GetScanInfo(int scan) const;
231 // Gets the scan information of the passed scan method pointer.
233 const InfoBase* GetScanInfo(const ScanMethod* sm) const;
234 // Must be overridden in a derived class.
235 // Returns a InfoBase derived structure.
236 virtual InfoBase* NewScanInfo() = 0;
237 // Is called when the current state changes.
238 virtual void StateChange(EState prev, EState cur) = 0;
239 // Must be overloaded in a derived class.
240 // Adds property pages to the passed sheet. See DoAddPropertyPages.
241 virtual void AddPropertyPages(PropertySheetDialog* sheet, bool scan) = 0;
242 // Reads the settings from the passed inifile.
243 virtual void ReadProfile(IniProfile& inifile) = 0;
244 // Writes the settings to the passed inifile.
245 virtual void WriteProfile(IniProfile& inifile) = 0;
246 // Returns the current scanned index.
247 virtual int GetIndex() = 0;
248 // Clears the settings of the derived instance initial state.
249 virtual void Clear() = 0;
250 // Can be overloaded to do background processing.
251 virtual void Sustain(timespec) = 0;
252 // Initializes the instance for action.
253 virtual bool Initialize() = 0;
254 // Suspends action at a convenient position.
255 virtual bool Suspend(bool immediate) = 0;
256 // Resumes a suspended action.
257 virtual bool Resume() = 0;
258 // Stops activity immediately.
259 virtual bool Stop() = 0;
260 // Abort immediately stop all movement.
261 virtual bool Abort() = 0;
262 // Must be overloaded in a derived class.
263 // When scan negative the index is considered to be a system position index.
264 // When scan has a valid value and index is negative the part is approached.
265 // When frac is negative am input query is started for a surface position.
266 virtual bool MoveTo(int scan, int index, double frac, bool rect) = 0;
267 // Starts checking .
268 virtual bool Check(int scan) = 0;
269 // Starts scan movements and a scan method for acquisition.
270 virtual bool Scan(int scan) = 0;
271 // Starts evaluation on the passed scan.
272 virtual bool Evaluate(int scan) = 0;
273 // Starts activates the parameters or links for the passed scan on the derived class.
274 virtual bool Activate(int scan) = 0;
275 // Starts rotation on the passed scan and index position for velocity calculations.
276 // When the passed index is -1 the current or last index position or center index is to be used.
277 virtual bool Rotate(int scan, int index) = 0;
278 // Creates the scan binder control frame.
279 virtual QWidget* GetFrame() = 0;
280 // Returns the sum of offsets generated by a derived class if overloaded.
281 virtual Vector3D GetOffset() const;
282 // Must be overloaded to do retrieve the list of linked variables or results.
283 // The name contains the description and the object the GII object pointer.
284 virtual bool GetGenericInfoList(StringList&) = 0;
285 // Property handler.
286 ProjectData* GetProjectData();
287 // Overloaded from base class.
288 const IdInfo* getInfo(const std::string& name) const override;
289 // Overloaded from base class.
290 bool getSetValue(const ScriptObject::IdInfo* info, Value* value, Value::vector_type* params, bool flag_set) override;
291
292 // Can be overloaded to read and write additional configuration settings.
293 virtual void DoReadWriteConfig(IniEnvelope& ini, bool rd) {}
294
295 private:
296 // Holds the controller allocation status.
297 bool FControllerAllocated;
298 // Holds the rotating flag.
299 bool FRotating;
300 // Holds the flag which decides which velocity is used.
301 bool FProgrammingVelocity;
302 // Sets the state for this base class without any checks.
303 void SetStatePrivate(EState state);
304 // Pointer to the project this instance is part of.
305 ProjectData* FProjectData;
306 // Holds the name prefix for binder parameters.
307 std::string FNamePrefix;
308 // Holds the current state.
309 const EState FState;
310 // For returning in references when a request fails.
311 gmi::AxesCoord FFailCoord;
312 // Holds the velocity values for manipulation.
313 gmi::AxesCoord FVelocity;
314 // Holds the velocity values for manipulation at scan project design time.
315 gmi::AxesCoord FProgVelocity;
316 // Holds the acceleration values for manipulation.
317 gmi::AxesCoord FAcceleration;
318 // Holds the project dependent park position.
319 gmi::AxesCoord FParkPosition;
320 // Holds the project dependent tool position.
321 gmi::AxesCoord FToolPosition;
322 // Holds the fixture offset.
323 Vector3D FFixtureOffset;
324 // Holds the active scan index when the instance was activated
325 // using a command where the index was passed.
326 int FActiveScanIndex;
327 // Handles parameters.
328 void VarEvent(Variable::EEvent event, const Variable&, Variable& link, bool same_inst);
329 // Holds the local variable pointers that hold the parameters.
330 Variable::PtrVector FLocalVars;
331 // For reporting the scanning progress.
332 LocalVariable VProgress;
333 // Holds the medium velocity of the name specified in the project.
334 LocalVariable VMediumVelocity;
335 // Handles applies from system property pages.
336 void HandleParamMappingApply(QWidget*);
337 // For storing current information.
338 ConfigStore FSaveState;
339
340 TVariableHandler<ScanBinder> _variableHandler;
341
342 friend ScanMethod;
343 friend ScanMethodPositionPropertyPage;
344 friend ProjectDataPropertyPage;
345 friend CheckPositionsPropertyPage;
346
347 // Declarations of static functions and data members to be able to create registered implementations.
349};
350
352{
353 return FSaveState;
354}
355
357{
358 return FState;
359}
360
362{
363 // When already allocated byu this instance it is not problem.
364 if (FControllerAllocated)
365 return true;
366 // Return true when the controller is not allocated.
368}
369
371{
372 return FControllerAllocated;
373}
374
375inline bool ScanBinder::IsRotating() const
376{
377 return FRotating;
378}
379
380inline const char* ScanBinder::GetStateName() const
381{
382 return GetStateName(GetState());
383}
384
386{
387 return FAcceleration;
388}
389
391{
392 return FParkPosition;
393}
394
396{
397 return FToolPosition;
398}
399
401{
402 return VMediumVelocity;
403}
404
406{
407 return FProjectData;
408}
409
411{
412 return const_cast<ScanBinder*>(this)->GetController();
413}
414
415inline void ScanBinder::SetProgVelocityEnable(bool enabled)
416{
417 FProgrammingVelocity = enabled;
418}
419
421{
422 return FProgrammingVelocity;
423}
424
426{
427 return FLocalVars;
428}
429
431{
432 return const_cast<ScanBinder*>(this)->GetScanInfo(scan);
433}
434
436{
437 return const_cast<ScanBinder*>(this)->GetScanInfo(sm);
438}
439
440}// namespace sf
#define SF_DECL_IFACE(InterfaceType, ParamType, FuncName)
Declares a public static function in the class where it is used. Where: InterfaceType: Global typenam...
Definition TClassRegistration.h:71
Class to store application configuration. Uses the global application settings or a given ini-file.
Definition ConfigStore.h:16
Class for reading and writing ini-profiles.
Definition IniProfile.h:17
Create a local variable by calling the protected constructor.
Definition Variable.h:947
Definition ProjectData.h:23
bool IsControllerAllocated()
Definition ProjectModule.h:407
Object for scripts to interact with the inspection project.
Definition ProjectScriptObject.h:14
Dialog containing multiple property pages.
Definition qt/PropertySheetDialog.h:14
Abstract base class for implementing scan binders.
Definition ScanBinder.h:30
virtual bool GetGenericInfoList(StringList &)=0
EState
Definition ScanBinder.h:144
@ sbsCHECKING
Binder is active and the controller is allocated.
Definition ScanBinder.h:165
@ sbsREADY
Waiting for activation by a command and the controller is freed.
Definition ScanBinder.h:157
@ sbsWAITING
Waiting to execute.
Definition ScanBinder.h:159
@ sbsACTIVE
Binder is active and the controller is allocated.
Definition ScanBinder.h:163
@ sbsSUSPENDED
Execution of the current task is suspended.
Definition ScanBinder.h:161
@ sbsABORTED
Binder movement was aborted abruptly.
Definition ScanBinder.h:152
@ sbsSCANNING
Binder is active and scanning.
Definition ScanBinder.h:167
virtual bool Suspend(bool immediate)=0
const gmi::AxesCoord & GetParkPosition() const
Definition ScanBinder.h:390
~ScanBinder() override
InfoBase * GetScanInfo(const ScanMethod *sm)
const Vector3D & GetFixtureOffset() const
bool DoEvaluate(int scan)
const gmi::AxesCoord & GetAcceleration() const
Definition ScanBinder.h:385
bool DoCheck(int scan)
virtual void AddPropertyPages(PropertySheetDialog *sheet, bool scan)=0
ScanBinder(const Parameters &parameters)
virtual void Clear()=0
bool DoPreInitialize()
virtual bool Resume()=0
virtual QWidget * GetFrame()=0
bool DoSuspend(bool immediate)
bool GetScanPos(gmi::AxesCoord &pos, int scan, int index, double frac, bool rect) const
bool DoMoveToSysPos(ESystemPosition sp)
double GetScanProgress() const
gmi::Controller * GetController()
bool getSetValue(const ScriptObject::IdInfo *info, Value *value, Value::vector_type *params, bool flag_set) override
Overridden from base class.
ConfigStore & GetSaveState()
Definition ScanBinder.h:351
ScanMethod * GetScan(int scan) const
const Variable::PtrVector & GetVars() const
Definition ScanBinder.h:425
int GetActiveScanIndex() const
virtual Vector3D GetOffset() const
bool DoActivate(int scan)
bool DoMoveToQuery(int scan)
static const char * GetStateName(EState state)
virtual bool Rotate(int scan, int index)=0
bool IsRotating() const
Definition ScanBinder.h:375
bool DoScan(int scan)
void SetAcqPopManual(RsaTypes::EPopManual pop_manual)
bool IsAcqPopManualReady() const
virtual int GetIndex()=0
virtual bool Stop()=0
void DoReadProfile(IniProfile &inifile)
virtual bool Check(int scan)=0
bool GetProgVelocityEnable() const
Definition ScanBinder.h:420
virtual bool Evaluate(int scan)=0
const gmi::AxesCoord & GetVelocity() const
void DoSustain(timespec clk)
ProjectData * GetProjectData()
Definition ScanBinder.h:405
virtual void Sustain(timespec)=0
void ReadWriteConfig(bool rd)
Vector3D DoGetOffset() const
bool AllocateController(bool alloc)
const IdInfo * getInfo(const std::string &name) const override
Overridden from base class.
int DoGetIndex() const
const Variable & GetMediumVelocity() const
Definition ScanBinder.h:400
virtual bool Scan(int scan)=0
virtual bool Initialize()=0
virtual InfoBase * NewScanInfo()=0
virtual void WriteProfile(IniProfile &inifile)=0
const char * GetStateName() const
Definition ScanBinder.h:380
QWidget * DoGetFrame()
void DoAddPropertyPages(PropertySheetDialog *sheet, bool scan)
bool DoInitialize()
bool DoRotate(int scan, int index=-1)
EState GetState() const
Definition ScanBinder.h:356
bool SetState(EState state)
const gmi::AxesCoord & GetToolPosition() const
Definition ScanBinder.h:395
bool CanRotate(int scan) const
bool CanAllocateController() const
Definition ScanBinder.h:361
virtual void AddPropertyPages(PropertySheetDialog *sheet)
bool DoMoveTo(int scan, int index=-1, double frac=0.0, bool rect=false)
void DoWriteProfile(IniProfile &inifile)
InfoBase * GetScanInfo(int scan)
void SetProgVelocityEnable(bool enabled)
Definition ScanBinder.h:415
virtual void ReadProfile(IniProfile &inifile)=0
void DeleteScanEntry(const ScanEntry *se)
virtual bool Abort()=0
void NewScanEntry(ScanEntry *se)
virtual bool MoveTo(int scan, int index, double frac, bool rect)=0
bool IsControllerAllocated() const
Definition ScanBinder.h:370
virtual void StateChange(EState prev, EState cur)=0
virtual bool Activate(int scan)=0
virtual void DoReadWriteConfig(IniEnvelope &ini, bool rd)
Definition ScanBinder.h:293
Definition ScanEntry.h:13
Definition ScanMethod.h:28
String list with optional object association and sorting.
Definition TStringList.h:12
Template for linking pointers of member function to Variable instances.
Definition VariableHandler.h:38
Value container class able to performing arithmetic functions.
Definition Value.h:19
EEvent
Events send to the handler set with sf::Variable::setHandler.
Definition VariableTypes.h:130
Class for creating and referencing global or local created parameters or settings called variables....
Definition Variable.h:16
All axis values in one structure accompanied by some handy manipulation methods.
Definition AxesCoord.h:13
Pure virtual class for implementation of motion controllers.
Definition Controller.h:13
#define _IPJ_CLASS
Definition ipj/iface/global.h:35
Definition Application.h:10
constexpr std::string_view DEFAULT_SCANBINDERNAME("<default>")
ESystemPosition
Fixed system dependent axis positions.
Definition ipj/iface/Namespace.h:297
constexpr std::string_view SEC_BINDER_GENERAL("Scan Binder")
_IPJ_FUNC ProjectModule * getProjectModule()
Creates the project module when called for.
constexpr std::string_view KEY_IGNOREOFFSET("Ignore Project Offset")
EPopManual
Enumerate for the pop manual function.
Definition RsaTypes.h:507
Structure used a base class for derived binder classes to store scan dependant information.
Definition ScanBinder.h:36
virtual void ReadWrite(IniProfile *ini, bool rd)
Read or writes the scan scan-binder information to profile. Derived classes need to inherit this memb...
InfoBase()=default
Default constructor.
virtual ~InfoBase()=default
Virtual constructor so the memory management can be done in the scan binders base class.
Mandatory structure for initialization of derive class.
Definition ScanBinder.h:63
ProjectData * _project_data
Definition ScanBinder.h:64
Used to create static lookup lists.
Definition ScriptObject.h:62