Files
Work/meshwrp/mesh.hpp
2024-08-07 09:16:27 -04:00

111 lines
3.2 KiB
C++

#ifndef _MESHWRP_MESH_HPP_
#define _MESHWRP_MESH_HPP_
#ifndef _COMMON_STDIO_HPP_
#include <common/stdio.hpp>
#endif
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_WINDOW_HPP_
#include <common/window.hpp>
#endif
#ifndef _COMMON_CALLBACK_HPP_
#include <common/callback.hpp>
#endif
#ifndef _COMMON_PEN_HPP_
#include <common/pen.hpp>
#endif
#ifndef _COMMON_ARRAY_HPP_
#include <common/array.hpp>
#endif
#ifndef _MESHWRP_SEGMENT_HPP_
#include <meshwrp/segment.hpp>
#endif
#ifndef _MESHWRP_POLYPOINT_HPP_
#include <meshwrp/polypnt.hpp>
#endif
class GridMesh : public Array<Segment>, public Window
{
public:
enum GridShow{Show,NoShow};
GridMesh(HWND hParent,int width,int height,GridShow visibility=Show);
virtual ~GridMesh(void);
void newMesh(WORD gridLines=GridLines);
WORD saveMesh(String &pathFileName);
WORD loadMesh(String &pathFileName);
WORD retrieveMesh(Array<GDIPoint> &sourcePoints,Array<GDIPoint> &destPoints);
WORD rowCols(void)const;
WORD gridLines(void)const;
WORD upgradeStatus(WORD retCode)const;
// WORD isVisible(void)const;
void showWindow(int visible=TRUE);
void suspendMesh(WORD suspend);
private:
typedef LONG Index;
enum Status{InActive,Active};
enum {IntersectionSegments=4};
enum {GridLines=8,MaxGridLines=16};
void registerClass(void);
long WndProc(UINT message,WPARAM wParam,LPARAM lParam);
void mouseUp(int x,int y);
void mouseDown(int x,int y);
void mouseMove(int x,int y);
DWORD minDistance(const Segment &someSegment,const GDIPoint &mousePoint);
WORD closestIntersection(Block<Segment> &filterSegment,GDIPoint &mousePoint);
WORD orderIntersection(Block<Segment> &intersection);
WORD isInBlock(Block<Segment> &source,Segment &someSegment);
void createMesh(WORD gridLines,Array<Segment> &someSegmentVector);
WORD retrieveMesh(Array<GDIPoint> &meshPoints,Array<Segment> &meshSegments)const;
void getBoundingRect(Block<Segment> &currentIntersection,Rect &boundingRect);
void drawBoundingRect(const Rect &boundingRect);
CallbackData::ReturnType createHandler(CallbackData &someCallbackData);
CallbackData::ReturnType paintHandler(CallbackData &someCallbackData);
CallbackData::ReturnType leftButtonUpHandler(CallbackData &someCallbackData);
CallbackData::ReturnType leftButtonDownHandler(CallbackData &someCallbackData);
CallbackData::ReturnType mouseMoveHandler(CallbackData &someCallbackData);
CallbackData::ReturnType destroyHandler(CallbackData &someCallbackData);
void insertHandlers(void);
void removeHandlers(void);
Callback<GridMesh> mCreateHandler;
Callback<GridMesh> mPaintHandler;
Callback<GridMesh> mLeftButtonUpHandler;
Callback<GridMesh> mLeftButtonDownHandler;
Callback<GridMesh> mMouseMoveHandler;
Callback<GridMesh> mDestroyHandler;
Pen mDrawingPen;
static char szClassName[];
static char szMenuName[];
Block<Segment> mCurrentIntersection;
int mGridLines;
Status mStatus;
String mVersionInfo;
WORD mIsSuspended;
HWND mhParent;
HINSTANCE mhInstance;
};
inline
WORD GridMesh::gridLines(void)const
{
return mGridLines;
}
inline
WORD GridMesh::rowCols(void)const
{
return mGridLines+2;
}
inline
void GridMesh::suspendMesh(WORD suspend)
{
if(suspend)mIsSuspended=TRUE;
else mIsSuspended=FALSE;
}
#endif