📄 ductmh.java
字号:
/********************************************************************
*
* $RCSfile: DuctMH.java,v $ $Revision: 1.1 $ $Date: 2003/09/22 08:06:24 $
*
* $Log: DuctMH.java,v $
* Revision 1.1 2003/09/22 08:06:24 icestone
* init
*
*
*
**********************************************************************/
package pcdmupgradedata;
/**
* <p>Title: 管孔的人井展开图坐标转换</p>
* <p>Description: </p>
*/
import java.sql.*;
import java.util.Vector;
import java.lang.Math.*;
import javax.swing.*;
public class DuctMH {
private Connection conn = null;
private String strSourceDBName = null;
private String strTargetDBName = null;
private String strSql;
public DuctMH() {
}
/**获取Conn连接*/
public DuctMH(Connection conn,String strInSourceDBName,String strInTargetDBName,JLabel jLabel1) {
this.conn = conn;
this.strSourceDBName = strInSourceDBName;
this.strTargetDBName = strInTargetDBName;
int i=0; //循环计数器
String strDuctGPCode; //管道段编码
System.out.println("=======开始转换管孔人井展开图坐标======");
Statement stmt = null;
ResultSet rset = null;
try{
stmt = conn.createStatement();
//查询 管道段编码
strSql = " Select distinct 所属管道段编码" +
" From " + strTargetDBName + ".I_管道 Where 所属管道 is null";
rset = stmt.executeQuery(strSql);
while (rset.next()){
strDuctGPCode = rset.getString(1);
//转换管孔坐标
changeCoordinate(strDuctGPCode,jLabel1);
//测试标志
System.out.println(i);
i = i+1;
}
}catch(SQLException e){
System.out.println(e.toString());
}
finally {
if (rset != null)
try {rset.close();} catch(SQLException ignore) {}
if (stmt != null)
try {stmt.close();} catch(SQLException ignore) {}
}
}
/**转换管孔坐标*/
private void changeCoordinate(String strDuctGPCode,JLabel jLabel1){
long b_mslink;
int b_entity;
String strBelongMHSide; //人井面号
Statement stmt = null;
Statement stmtQuery = null;
ResultSet rset = null;
ResultSet rsetQuery = null;
try{
stmt = conn.createStatement();
stmtQuery = conn.createStatement();
//查询 管孔所属人井信息
strSql = "Select distinct b_mslink,b_entity,所属井面号 " +
" From " + strSourceDBName + ".GK_T Where 所属管道段编码='" + strDuctGPCode + "'";
rset = stmt.executeQuery(strSql);
while (rset.next()){
b_mslink = rset.getLong(1);
b_entity = rset.getInt(2);
strBelongMHSide = rset.getString(3);
strBelongMHSide = strBelongMHSide.trim();
//查询管孔编码是否 存在I_管道表中,有则转换
strSql = "Select a.管孔编码" +
" From " + strSourceDBName + ".GK_T a," + strTargetDBName + ".I_管道 b" +
" Where a.管孔编码=b.管道编码" +
" And a.所属管道段编码='" + strDuctGPCode + "'" +
" And a.b_mslink=" + b_mslink + " And a.b_entity=" + b_entity;
rsetQuery = stmtQuery.executeQuery(strSql);
if(rsetQuery.next()){
//转换坐标,并保存新坐标
saveDuctCoord(b_mslink,b_entity,strDuctGPCode,strBelongMHSide,jLabel1);
}
}
}catch(SQLException e){
System.out.println(e.toString());
}
finally {
if (rset != null)
try {rset.close();} catch(SQLException ignore) {}
if (stmt != null)
try {stmt.close();} catch(SQLException ignore) {}
if (stmtQuery != null)
try {stmtQuery.close();} catch(SQLException ignore) {}
}
}
/**根据 SA.deviceframe表 得到人井面数*/
private int getMHSideNum(Statement stmt,long b_mslink,int b_entity){
int intMHSideCount = 0;
ResultSet rset = null;
try{
//选择面数
strSql = new String("select count(*) from " +
strSourceDBName + ".deviceframe" +
" where DEVICEMSLINK = " + b_mslink+
" and DEVICEENTITY = " + b_entity);
rset = stmt.executeQuery (strSql);
while(rset.next ()){
intMHSideCount = rset.getInt(1);
}
}catch (SQLException e){
System.out.println(e.toString());
}
finally {
if (rset != null)
try {rset.close();} catch(SQLException ignore) {}
}
return intMHSideCount;
}
/**生成标准的人井展开图框架,并按面号返回 面旋转的角度*/
private double getMHSideAngle(int intMHSideCount,String strBelongMHSide){
//A面朝上
Vector vMHFrame = null;
double angle; //面旋转的角度
int intMHSide; //面号
int i;
//计算面号
char charMHSide = strBelongMHSide.charAt(0);
intMHSide = charMHSide - 'A';
//顺时针 要 乘以 -1
angle = 1*(2*Math.PI/intMHSideCount)*intMHSide;
return angle;
}
/**获取 平移向量*/
private Point getMovePoint(int intMHSideCount,String strBelongMHSide){
//面长和面宽默认为1000毫米
//A面朝上
Vector vMHFrame = null;
double dblSideAngle[]; //每个面旋转的角度
int intMHSide; //面号
double angle; //旋转的角度
int i;
Point oReturnPoint = null; //保存返回的向量
double dblSideLen = 1000; //边长 默认为1000毫米
double dblX,dblY;
Point startPoint = null; //旋转原点
Point endPoint = null; //旋转点
//计算面号
char charMHSide = strBelongMHSide.charAt(0);
intMHSide = charMHSide - 'A' ; //A面 为平行,所以面号为 0
dblSideAngle = new double[intMHSideCount];
//确定第一点坐标
angle = (2*Math.PI/intMHSideCount)/2;
dblX = (-1*dblSideLen)/2;
dblY = (dblSideLen/2)/java.lang.Math.tan(angle);
startPoint = new Point(0,0);
endPoint = new Point(dblX,dblY);
//该面的旋转角度
angle = 1*(2*Math.PI/intMHSideCount)*intMHSide;
//该面左下角的坐标
oReturnPoint = getRotatedPoint(startPoint,endPoint,angle);
return oReturnPoint;
}
/**获取 管道段一边的管孔*/
private Vector getDuctsByBMslink(double b_mslink,int b_entity,String strDuctGPCode){
Vector vDucts = new Vector(); //管孔数组
String strDuctCode; //管孔编码
double dblX,dblY; //管孔坐标
Statement stmt = null;
ResultSet rset = null;
try{
stmt = conn.createStatement();
//查询 管孔所属人井信息
strSql = "Select 管孔编码,X,Y " +
" From " + strSourceDBName + ".GK_T Where 所属管道段编码='" + strDuctGPCode + "'" +
" And b_mslink=" + b_mslink + " And b_entity=" + b_entity;
rset = stmt.executeQuery(strSql);
while (rset.next()){
strDuctCode = rset.getString(1);
dblX = rset.getDouble(2);
dblY = rset.getDouble(3);
DuctEntity oDuctEntity = new DuctEntity(strDuctCode,dblX,dblY);
vDucts.addElement(oDuctEntity);
}
}catch(SQLException e){
System.out.println(e.toString());
}
finally {
if (rset != null)
try {rset.close();} catch(SQLException ignore) {}
if (stmt != null)
try {stmt.close();} catch(SQLException ignore) {}
}
return vDucts;
}
/**保存管孔坐标 由底边的坐标,对管孔组进行平移和旋转*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -