⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridsub3.c

📁 有限元学习研究用源代码(老外的),供科研人员参考
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
IGRID - Interactive Gridding Program.
Copyright (c) 1995 Thng Cheok Hoey

This program  is free software; you can redistribute it and /or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 or License, or (at your option) any
later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY of FIT-
NESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 675 Mass
Ave, Cambridge, MA 02139, USA.

Author's email address: thng@mimicad.colorado.edu
*/

#include <windows.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "emgrid.h"
#include "geometry.h"
#include "mousemod.h"

extern HWND hwndMouseX, hwndMouseY, hwndMessage, hwndMessage2, hwndMessage3;
int  evalsin(dVECTOR , dVECTOR, double *);
int  evalcos(dVECTOR , dVECTOR, double *);
void adjustallowablesnap(void);
void messagemouseloc(dPOINT);
COUNT  numberexteriorelmts(void);
class block * nextblock(ID id);
extern void setdrawingcoord(HDC);
extern void lptodrawing(POINT point, dPOINT *);
extern void drawdottedrect(HDC, RECT);
extern void DrawBitmap(HDC, HBITMAP, short, short);

extern block *blockselected;
extern tol option;
extern HWND hwndMain, hwndPaper;
extern HPEN   hPenDotBlack, hPenSolidBlack;
extern blocklist unselected, selected, addon, copied, swaped;
extern int    cxChar, cyChar;
extern dPOINT  snapedcoord;

extern HBITMAP  hBmpzminoff, hBmpzminon, hBmpzmoutoff, hBmpzmouton;
extern HBITMAP  hBmpptroff, hBmpptron, hBmpreszoff, hBmpreszon;
extern HBITMAP  hBmpmsmovoff, hBmpmsmovon, hBmprotoff, hBmproton;
extern HBITMAP  hBmpmodoff, hBmpmodon, hBmpenqoff, hBmpenqon;
extern HBITMAP  hBmpabsoff, hBmpabson, hBmpmagoff, hBmpmagon;
extern HBITMAP  hBmpelecoff, hBmpelecon, hBmpextoff, hBmpexton;
extern HBITMAP  hBmprectoff, hBmprecton, hBmpquadoff, hBmpquadon;
extern HBITMAP  hBmptrioff, hBmptrion;

extern HCURSOR hwait, harrow;


static char movinstructn1[] = "Click to move a block by mouse.";
static char movinstructn2[] = "Double-click to move blocks by exact coordinates.";
static char movinstructn3[] = "Drag the selected block(s) to new position.";
static char movinstructn4[] = "Right button to cancel.";
static char movinstructn5[] = "Drag the block to new position.";
static char movinstructn6[] = "Right button to cancel.";
static char movinstructn7[] = "Left button to accept this position.";
static char movinstructn8[] = "Right button to cancel.";

static char rotinstructn1[] = "Click to rotate a block by mouse.";
static char rotinstructn2[] = "Double-click to rotate blocks by exact angle.";
static char rotinstructn3[] = "Drag the selected block(s) to new orientation.";
static char rotinstructn4[] = "Right button to cancel.";
static char rotinstructn5[] = "Drag the block to new orientation.";
static char rotinstructn6[] = "Right button to cancel.";
static char rotinstructn7[] = "Left button to accept this orientation.";
static char rotinstructn8[] = "Right button to cancel.";

static char resizeinstructn1[] = "Click on a corner to resize a block.";
static char resizeinstructn2[] = "Double-click on a corner or node to resize by an exact value.";
static char resizeinstructn3[] = "Pull the corner to resize the block.";
static char resizeinstructn4[] = "Right button to cancel resizing.";
static char resizeinstructn5[] = "Pull the corner to rescale blocks.";
static char resizeinstructn6[] = "Right button to cancel rescaling.";
static char resizeinstructn7[] = "Left button to accept the new size.";
static char resizeinstructn8[] = "Right button to cancel.";

static char connectmessage[80];

void pointermode::lbuttondown(HWND hwnd, LONG lParam){

    POINT point;
    HDC   hdc;

    if(flag.anchor == NO){
      point = MAKEPOINT(lParam);
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      DPtoLP(hdc, &point, 1);
      ReleaseDC(hwnd, hdc) ;
      enclosure.left = point.x;
      enclosure.top = point.y;
      flag.previousoutline = NO;
      flag.anchor = YES;
    }
}

void pointermode::move(HWND hwnd, LONG lParam){

    POINT point;
    dPOINT p;
    HDC   hdc;

    point = MAKEPOINT(lParam);
    hdc = GetDC(hwnd);
    setdrawingcoord(hdc);
    DPtoLP(hdc, &point, 1);
    lptodrawing(point, &p);
    messagemouseloc(p);
    ReleaseDC(hwnd, hdc) ;
}


void pointermode::ldownmove(HWND hwnd, LONG lParam){

    POINT point;
    dPOINT p;
    HDC   hdc;

    if(flag.anchor == YES){
      point = MAKEPOINT(lParam);
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      DPtoLP(hdc, &point, 1);
      lptodrawing(point, &p);
      messagemouseloc(p);
      if(flag.previousoutline){
	drawdottedrect(hdc, enclosure);
	flag.previousoutline = NO;
      }
      enclosure.right = point.x;
      enclosure.bottom = point.y;
      drawdottedrect(hdc, enclosure);
      flag.previousoutline = YES;
      ReleaseDC(hwnd, hdc) ;
    }
}

void pointermode::lbuttonup(HWND hwnd){

    POINT point;
    HDC   hdc;
    HMENU hMenu;
    dRECT drect;
    int   n1 = 0, n2 = 0;

    if(flag.anchor == YES){
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      if(flag.previousoutline){
	drawdottedrect(hdc, enclosure);
	point = *(PPOINT) &enclosure.left;
	lptodrawing(point, (dPOINT *)&(drect.left));
	point = *(PPOINT) &enclosure.right;
	lptodrawing(point, (dPOINT *)&(drect.right));
	n1 = selected.selectblks(drect, swaped);
	n2 = unselected.selectblks(drect, selected);
	swaped.transfer(unselected);
	hMenu = GetMenu(hwndMain);
	if(selected.empty() == NO){
	  EnableMenuItem (hMenu, IDM_CUT, MF_ENABLED) ;
	  EnableMenuItem (hMenu, IDM_COPY, MF_ENABLED) ;
	  EnableMenuItem (hMenu, IDM_DEL, MF_ENABLED) ;
	}
	else{
	  EnableMenuItem (hMenu, IDM_CUT, MF_GRAYED) ;
	  EnableMenuItem (hMenu, IDM_COPY, MF_GRAYED) ;
	  EnableMenuItem (hMenu, IDM_DEL, MF_GRAYED) ;
	}
      }
      ReleaseDC(hwnd, hdc) ;
      flag.anchor = NO;
      flag.previousoutline = NO;
    }
    if((n1 > 0) || (n2 > 0))
      InvalidateRect(hwndPaper, NULL, TRUE);
}

void pointermode::presstoolbar(void){

    HDC hdc;

    hdc = GetDC(hwndMain);
    DrawBitmap(hdc, hBmpptron, POINTER_X,  0);
    ReleaseDC(hwndMain, hdc);
}

void pointermode::releasetoolbar(void){

    HDC hdc;

    hdc = GetDC(hwndMain);
    DrawBitmap(hdc, hBmpptroff, POINTER_X,  0);
    ReleaseDC(hwndMain, hdc);
    hdc = GetDC(hwndPaper);
    setdrawingcoord(hdc);
    if(flag.anchor == YES){
      if(flag.previousoutline){
	drawdottedrect(hdc, enclosure);
      }
      flag.anchor = NO;
    }
    ReleaseDC(hwndPaper, hdc);
    flag.previousoutline = NO;
}


void pointermode::ldblclk(HWND hwnd, LONG lParam){

    POINT  point;
    dPOINT p;
    HDC    hdc;
    block  *bp;

    point = MAKEPOINT(lParam);
    hdc = GetDC(hwnd);
    setdrawingcoord(hdc);
    DPtoLP(hdc, &point, 1);
    ReleaseDC(hwnd, hdc) ;
    lptodrawing(point, &p);

    if((bp = selected.enclosepoint(p)) == NULL)
      bp = unselected.enclosepoint(p);

    if(bp != NULL){
      bp->dialog();
    }
}


void moveobjectmode::lbuttondown(HWND hwnd, LONG lParam){

    POINT point;
    dPOINT p;
    HDC   hdc;
    HCURSOR hcursor;
    COUNT nscount, totalcount = {0, 0, 0};

    if(flag.movingobject == NO){
      point = MAKEPOINT(lParam);
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      DPtoLP(hdc, &point, 1);
      ReleaseDC(hwnd, hdc) ;
      lptodrawing(point, &gcenter);
      ploc = gcenter;
      if(selected.enclosepoint(gcenter) != NULL){
	flag.movingobject = SELECTED;
	singleblock = NULL;
	SetWindowText(hwndMessage, movinstructn3);
	SetWindowText(hwndMessage2, movinstructn4);
      }
      else if((singleblock = unselected.enclosepoint(gcenter)) != NULL){
	singleblock->getreference(&ploc);
	offcenter.x = ploc.x - gcenter.x;
	offcenter.y = ploc.y - gcenter.y;
	flag.movingobject = UNSELECTED;
	SetWindowText(hwndMessage, movinstructn5);
	SetWindowText(hwndMessage2, movinstructn6);
      }
      else{
	singleblock = NULL;
      }
      flag.previousoutline = NO;
      flag.reconnect = NO;
    }
    else if(flag.movingobject == SELECTED){
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      if(flag.previousoutline){
	selected.outline(hdc, R2_NOTXORPEN, hPenDotBlack, gcenter, ploc);
	flag.previousoutline = NO;
      }
      ReleaseDC(hwnd, hdc) ;
      if(flag.reconnect == YES){
	hcursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
	ShowCursor(TRUE);
	selected.disconnect(unselected);
	selected.move(gcenter.x, gcenter.y, ploc.x, ploc.y);
	selected.clearconnectmask();
	unselected.clearconnectmask();
	totalcount = selected.connect(unselected);
	ShowCursor(FALSE);
	SetCursor(hcursor);
      }
      InvalidateRect(hwndPaper, NULL, TRUE);
      flag.reconnect = NO;
      flag.movingobject = NO;

      sprintf(connectmessage, "Connection: node:%d side:%d .",
	    totalcount.node, totalcount.side);
      SetWindowText(hwndMessage3, connectmessage);
      SetWindowText(hwndMessage, movinstructn1);
      SetWindowText(hwndMessage2, movinstructn2);
      SendMessage(hwndMain, WM_COMMAND, NEEDSAVE, 0L);
    }

    else if(flag.movingobject == UNSELECTED){
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      if(flag.previousoutline){
	singleblock->outline(hdc, R2_NOTXORPEN, hPenDotBlack, ploc);
	flag.previousoutline = NO;
      }
      ReleaseDC(hwnd, hdc) ;
      if(flag.reconnect == YES){
	hcursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
	ShowCursor(TRUE);
	singleblock->disconnect();
	singleblock->move(ploc.x, ploc.y);
	selected.clearconnectmask();
	unselected.clearconnectmask();
	totalcount = singleblock->connect(selected);
	nscount    = singleblock->connect(unselected);
	totalcount.node += nscount.node;
	totalcount.side += nscount.side;
	ShowCursor(FALSE);
	SetCursor(hcursor);
      }
      flag.reconnect = NO;
      flag.movingobject = NO;
      InvalidateRect(hwndPaper, NULL, TRUE);

      sprintf(connectmessage, "Connection: node:%d side:%d .",
	    totalcount.node, totalcount.side);
      SetWindowText(hwndMessage3, connectmessage);
      SetWindowText(hwndMessage, movinstructn1);
      SetWindowText(hwndMessage2, movinstructn2);
      SendMessage(hwndMain, WM_COMMAND, NEEDSAVE, 0L);
    }

}

void moveobjectmode::move(HWND hwnd, LONG lParam){

    POINT  point;
    HDC    hdc;
    dPOINT loc;
    // moving a group of selected(highlighted) object.

    if(flag.movingobject == SELECTED){
      point = MAKEPOINT(lParam);
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      DPtoLP(hdc, &point, 1);
      if(flag.previousoutline)
	 selected.outline(hdc, R2_NOTXORPEN, hPenDotBlack, gcenter, ploc);
      lptodrawing(point, &loc);
      messagemouseloc(loc);
      selected.outline(hdc, R2_NOTXORPEN, hPenDotBlack, gcenter, loc);
      ploc = loc;
      flag.previousoutline = YES;
      flag.reconnect = YES;
      ReleaseDC(hwnd, hdc) ;
      SetWindowText(hwndMessage, movinstructn7);
      SetWindowText(hwndMessage2, movinstructn8);
    }

    // moving ONE unselected object.
    else if(flag.movingobject == UNSELECTED){
      point = MAKEPOINT(lParam);
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      DPtoLP(hdc, &point, 1);
      if(flag.previousoutline)
	singleblock->outline(hdc, R2_NOTXORPEN, hPenDotBlack, ploc);
      lptodrawing(point, &loc);
      messagemouseloc(loc);
      loc.x += offcenter.x;
      loc.y += offcenter.y;
      singleblock->outline(hdc, R2_NOTXORPEN, hPenDotBlack, loc);
      ploc = loc;
      flag.previousoutline = YES;
      flag.reconnect = YES;
      ReleaseDC(hwnd, hdc) ;
      SetWindowText(hwndMessage, movinstructn7);
      SetWindowText(hwndMessage2, movinstructn8);
    }
    else{
      point = MAKEPOINT(lParam);
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      DPtoLP(hdc, &point, 1);
      lptodrawing(point, &loc);
      messagemouseloc(loc);
      ReleaseDC(hwnd, hdc) ;
    }
}

void moveobjectmode::ldownmove(HWND hwnd, LONG lParam){

     move(hwnd, lParam);
}

void moveobjectmode::rbuttondown(void){

    HDC hdc;

    hdc = GetDC(hwndPaper);
    setdrawingcoord(hdc);
    if(flag.movingobject == SELECTED){
      if(flag.previousoutline)
	selected.outline(hdc, R2_NOTXORPEN, hPenDotBlack, gcenter, ploc);
      flag.movingobject = NO;
    }

    if(flag.movingobject == UNSELECTED){
      if(flag.previousoutline)
	singleblock->outline(hdc, R2_NOTXORPEN, hPenDotBlack, ploc);
      flag.movingobject = NO;
      singleblock = NULL;
    }
    ReleaseDC(hwndPaper, hdc);
    flag.previousoutline = NO;
    flag.reconnect = NO;
    SetWindowText(hwndMessage, movinstructn1);
    SetWindowText(hwndMessage2, movinstructn2);

//    SendMessage(hwndMain, WM_COMMAND, IDM_MOVE_OBJ, 0L);
}

void moveobjectmode::ldblclk(HWND hwnd, LONG lParam){

    POINT  point;
    dPOINT p;
    HDC    hdc;
    block  *bp;

    rbuttondown();
    point = MAKEPOINT(lParam);
    hdc = GetDC(hwnd);
    setdrawingcoord(hdc);
    DPtoLP(hdc, &point, 1);
    ReleaseDC(hwnd, hdc) ;
    lptodrawing(point, &p);

    if((bp = selected.enclosepoint(p)) != NULL){
      blockselected = bp;
      snapedcoord = bp->snaptonode(p);
      SendMessage(hwndMain, WM_COMMAND, IDM_MOVEBYLOC, 0L);
    }
    else if((bp = unselected.enclosepoint(p)) != NULL){
      blockselected = bp;
      snapedcoord = bp->snaptonode(p);
      SendMessage(hwndMain, WM_COMMAND, IDM_MOVEBYLOC, 0L);
    }
}


void moveobjectmode::presstoolbar(void){

    HDC hdc;

    hdc = GetDC(hwndMain);
    DrawBitmap(hdc, hBmpmsmovon, MOVEOBJECT_X,  0);
    ReleaseDC(hwndMain, hdc);
}

void moveobjectmode::releasetoolbar(void){

    HDC hdc;

    hdc = GetDC(hwndMain);
    DrawBitmap(hdc, hBmpmsmovoff, MOVEOBJECT_X,  0);
    ReleaseDC(hwndMain, hdc);
    rbuttondown();  // equavalent to CANCEL
}


void rotateobjectmode::lbuttondown(HWND hwnd, LONG lParam){

    POINT   point;
    HDC     hdc;
    HCURSOR hcursor;
    COUNT   nscount, totalcount = {0, 0, 0};

    if(flag.rotatingobject == NO){
      point = MAKEPOINT(lParam);
      hdc = GetDC(hwnd);
      setdrawingcoord(hdc);
      DPtoLP(hdc, &point, 1);
      ReleaseDC(hwnd, hdc) ;
      lptodrawing(point, &lever);
      if(selected.enclosepoint(lever) != NULL){
	selected.center(&pivot);
	v1.x = lever.x - pivot.x;
	v1.y = lever.y - pivot.y;
	if(sqrt(v1.x * v1.x + v1.y * v1.y) != 0.0){
	  flag.rotatingobject = SELECTED;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -