code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; using System.Data; using System.Windows.Forms; using System.Data.Common; namespace QUANLYNHASACH.App_code.BLL { class Group_BLL { public List<QUANLYNHASACH.Group_td> LayDanhSachGroup() { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "getGroup"; cmd.CommandType = CommandType.StoredProcedure; SqlDataReader reader = cmd.ExecuteReader(); List<QUANLYNHASACH.Group_td> GroupLst = new List<QUANLYNHASACH.Group_td>(); while (reader.Read()) { QUANLYNHASACH.Group_td Grp = new QUANLYNHASACH.Group_td(); Grp.idGroup = reader[0].ToString(); Grp.CapBac = reader[1].ToString(); GroupLst.Add(Grp); } conn.Close(); return GroupLst; }; } catch (Exception ex) { MessageBox.Show("Lỗi xảy ra: " + ex.Message, "Thông báo lỗi"); } return null; } public void CapNhatGroup(string idGroup, string CapBac) { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "editGroup"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idGroup"; param.Value = idGroup; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@CapBac"; param.Value = CapBac; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); } } //////// public void ThemGroup(string idGroup, string CapBac) { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "addGroup"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idGroup"; param.Value = idGroup; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@CapBac"; param.Value = CapBac; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); } } public void XoaGroup(string idGroup) { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "delGroup"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idGroup"; param.Value = idGroup; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); } } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/BLL/Group_BLL.cs
C#
art
5,225
//Author: Tran Quang Dang Khoa // Group : 06TH1d.12 // Created : 12/5/2010 using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Data.Common; using System.Windows.Forms; namespace QUANLYNHASACH.App_code.BLL { public class THELOAI_BLL { #region LAY DANH SACH THE LOAI SACH public List<DAL.THELOAI_td> LayDanhSachTheLoai() { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.connect.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "getTheLoaiSach"; cmd.CommandType = CommandType.StoredProcedure; SqlDataReader reader = cmd.ExecuteReader(); List<DAL.THELOAI_td> theloaiLST = new List<DAL.THELOAI_td>(); while (reader.Read()) { DAL.THELOAI_td theloai = new DAL.THELOAI_td(); theloai.idTheLoai = reader[0].ToString(); theloai.TenTheLoai = reader[1].ToString(); theloaiLST.Add(theloai); } conn.Close(); return theloaiLST; }; } catch (Exception ex) { MessageBox.Show("Lỗi xảy ra: " + ex.Message, "Thông báo lỗi"); } return null; } #endregion #region THEM THE LOAI public void ThemTheLoai(string idTheLoai, string TenTheLoai) { // bool result = false; try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.connect.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "addTheLoaiSach"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idTheLoai"; param.Value = idTheLoai; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TenTheLoai"; param.Value = TenTheLoai; param.DbType = DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); result = true; conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); // result = false; } // return result; } #endregion #region SUA THE LOAI public void suaTheLoai(string idTheLoai, string TenTheLoai_new) { // bool kq = false; try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.connect.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "editTheLoaiSach"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idTheLoai"; param.Value = idTheLoai; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TenTheLoai_new"; param.Value = TenTheLoai_new; param.DbType = DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); // kq = true; conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); // kq = false; } // return kq; } #endregion #region XOA THE LOAI public void xoaTheLoai(string idTheLoai) { //bool ketqua = false; try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.connect.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "delTheLoaiSach"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idTheLoai"; param.Value = idTheLoai; param.DbType = DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); // ketqua = true; conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); // ketqua = false; } // return ketqua; } #endregion } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/BLL/THELOAI_BLL.cs
C#
art
5,892
//Author: Pham Thi Kim Diep // Group : 06TH1d.12 // Created : 12/5/2010 using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Data.Common; using System.Windows.Forms; namespace QUANLYNHASACH.App_code.BLL { public class SACH_BLL { #region LẤY CHI TIẾT SÁCH public List<DAL.SACH_td> LayChiTietSach() { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "getSach"; cmd.CommandType = CommandType.StoredProcedure; SqlDataReader reader = cmd.ExecuteReader(); List<DAL.SACH_td> sachLST = new List<DAL.SACH_td>(); while (reader.Read()) { DAL.SACH_td sach = new DAL.SACH_td(); sach.idSach = reader[0].ToString(); sach.idTheLoai = reader[1].ToString(); sach.idNhaXuatBan = reader[2].ToString(); sach.TenSach = reader[3].ToString(); sach.TacGia = reader[4].ToString(); sach.DichGia = reader[5].ToString(); sach.SoTrang = int.Parse(reader[6].ToString()); sach.KichThuoc = float.Parse(reader[7].ToString()); sach.HinhThuc = reader[8].ToString(); sach.TrongLuong = float.Parse(reader[9].ToString()); sach.GiaBan = float.Parse(reader[10].ToString()); sach.SLTrongKho = int.Parse(reader[11].ToString()); sachLST.Add(sach); } conn.Close(); return sachLST; }; } catch (Exception ex) { MessageBox.Show("Lỗi xảy ra: " + ex.Message, "Thông báo lỗi"); } return null; } #endregion #region THÊM SÁCH public void ThemSach(string idSach, string idTheLoai, string idNhaXuatBan, string TenSach, string TacGia, string DichGia, int SoTrang, float KichThuoc, string HinhThuc, float TrongLuong, float GiaBan, int SLTrongKho) { //bool result = false; try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.connect.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "addSach"; cmd.CommandType = CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idSach"; param.Value = idSach; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@idTheLoai"; param.Value = idTheLoai; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@idNhaXuatBan"; param.Value = idNhaXuatBan; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TenSach"; param.Value = TenSach; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TacGia"; param.Value = TacGia; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@DichGia"; param.Value = DichGia; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@SoTrang"; param.Value = SoTrang; param.DbType = DbType.Int32; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@KichThuoc"; param.Value = KichThuoc; param.DbType = DbType.Double; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@HinhThuc"; param.Value = HinhThuc; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TrongLuong"; param.Value = TrongLuong; param.DbType = DbType.Double; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@GiaBia"; param.Value = GiaBan; param.DbType = DbType.Double; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@SLTrongKho"; param.Value = SLTrongKho; param.DbType = DbType.Int32; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); // result = true; conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); //result = false; } //return result; } #endregion #region XÓA SÁCH public void xoasach(string idsach) { //bool result = false; try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "delSach"; cmd.CommandType = CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idSach"; param.Value = idsach; param.DbType = DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); // result = true; conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); //result = false; } //return result; } #endregion #region SỬA SÁCH public void suasach(string idsach, string idTheLoai_new, string idNhaXuatBan_new, string TenSach_new, string TacGia_new, string DichGia_new, int SoTrang_new, float KichThuoc_new, string HinhThuc_new, float TrongLuong_new, float GiaBia_new, int SLTrongKho_new) { //bool result = false; try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "editSach"; cmd.CommandType = CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idSach"; param.Value = idsach; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@idTheLoai_new"; param.Value = idTheLoai_new; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@idNhaXuatBan_new"; param.Value = idNhaXuatBan_new; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TenSach_new"; param.Value = TenSach_new; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TacGia_new"; param.Value = TacGia_new; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@DichGia_new"; param.Value = DichGia_new; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@SoTrang_new"; param.Value = SoTrang_new; param.DbType = DbType.Int32; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@KichThuoc_new"; param.Value = KichThuoc_new; param.DbType = DbType.Double; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@HinhThuc_new"; param.Value = HinhThuc_new; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TrongLuong_new"; param.Value = TrongLuong_new; param.DbType = DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@GiaBia_new"; param.Value = GiaBia_new; param.DbType = DbType.Double; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@SLTrongKho_new"; param.Value = SLTrongKho_new; param.DbType = DbType.Int32; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); // result = true; conn.Close(); } } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); // result = false; } // return result; } #endregion } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/BLL/SACH_BLL.cs
C#
art
11,999
//Author: Ha Bao Minh Ky // Group : 06TH1d.12 // Created : 12/5/2010 using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Windows.Forms; using System.Data.Common; namespace QUANLYNHASACH.App_code.BLL { public class NXB_BLL { public List<QUANLYNHASACH.NXB_td> LayDanhSachNXB() { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "getNhaXuatBan"; cmd.CommandType = CommandType.StoredProcedure; SqlDataReader reader = cmd.ExecuteReader(); List<QUANLYNHASACH.NXB_td> nxbLst = new List<QUANLYNHASACH.NXB_td>(); while (reader.Read()) { QUANLYNHASACH.NXB_td nxb = new QUANLYNHASACH.NXB_td(); nxb._idNhaXuatBan = reader[0].ToString(); nxb._TenNXB = reader[1].ToString(); nxbLst.Add(nxb); } conn.Close(); return nxbLst; }; } catch (Exception ex) { MessageBox.Show("Lỗi xảy ra: " + ex.Message, "Thông báo lỗi"); } return null; } //////////////// public void CapNhatNXB(string idNhaXuatBan, string TenNXB, string DiaChi, string NguoiDaiDien, string SoDienThoai, string Email) { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "editNhaXuatBan"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idNhaXuatBan"; param.Value = idNhaXuatBan ; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TenNXB_new"; param.Value = TenNXB ; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@DiaChi_new"; param.Value = DiaChi; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@NguoiDaiDien_new"; param.Value = NguoiDaiDien; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@SoDienThoai_new"; param.Value = SoDienThoai; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@Email_new"; param.Value = Email; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); } } /////////////// public void ThemNXB(string idNhaXuatBan, string TenNXB, string DiaChi, string NguoiDaiDien, string SoDienThoai, string Email) { // bool ketqua = false; try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.connect.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "addNhaXuatBan"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idNhaXuatBan"; param.Value = idNhaXuatBan; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@TenNXB"; param.Value = TenNXB; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@DiaChi"; param.Value = DiaChi; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@NguoiDaiDien"; param.Value = NguoiDaiDien; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@SoDienThoai"; param.Value = SoDienThoai; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@Email"; param.Value = Email; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); ketqua = true; conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); // ketqua = false; } // return ketqua; } ////////////////////////////// public void XoaNXB(string idNhaXuatBan) { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "delNhaXuatBan"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idNhaXuatBan"; param.Value = idNhaXuatBan; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); } } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/BLL/NXB_BLL.cs
C#
art
7,906
// Author : Le Khac Huy // Group : 06TH1d.12 // Created : 12/5/2010 using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; using System.Data.Common; using System.Data; using System.Windows.Forms; namespace QUANLYNHASACH.App_code.BLL { public class DANGNHAP_BLL { public static bool layusername(string username) { bool ok = false; try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.connect.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "getUsername"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@username"; param.Value = username; param.DbType = DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); ok = true; conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); ok = false; } return ok; } public static bool laypassword(string password) { bool ok = false; try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.connect.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "getPassword"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@password"; param.Value = password; param.DbType = DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); ok = true; conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); ok = false; } return ok; } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/BLL/DANGNHAP_BLL.cs
C#
art
2,631
//Author: Nguyen The Thien Hung // Group : 06TH1d.12 // Created : 12/5/2010 using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.IO; using System.Windows.Forms; using System.Data.Common; namespace QUANLYNHASACH { class User_BLL { public List<QUANLYNHASACH.User_td> LayDanhSachUser() { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "getUser"; cmd.CommandType = CommandType.StoredProcedure; SqlDataReader reader = cmd.ExecuteReader(); List<QUANLYNHASACH.User_td> UsrLst = new List<QUANLYNHASACH.User_td>(); while (reader.Read()) { QUANLYNHASACH.User_td usr = new QUANLYNHASACH.User_td(); usr.idUser = reader[0].ToString(); usr.idGroup = reader[1].ToString(); usr.Username = reader[2].ToString(); usr.Password = reader[3].ToString(); usr.HoTen = reader[4].ToString(); UsrLst.Add(usr); } conn.Close(); return UsrLst; }; } catch (Exception ex) { MessageBox.Show("Lỗi xảy ra: " + ex.Message, "Thông báo lỗi"); } return null; } /////////////////////// public void CapNhatUser(string idUser, string idGroup, string Username, string Password, string Hoten) { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "editUser"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idUser"; param.Value = idUser; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@idGroup_new"; param.Value = idGroup; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@UserName_new"; param.Value = Username; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@Password_new"; param.Value = Password; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@HoTen_new"; param.Value = Hoten; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); } } public void ThemUser(string idUser, string idGroup, string UserName, string Password, string HoTen) { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "addUser"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idUser"; param.Value = idUser; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@idGroup"; param.Value = idGroup; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@UserName"; param.Value = UserName; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@Password"; param.Value = Password; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); param = cmd.CreateParameter(); param.ParameterName = "@HoTen"; param.Value = HoTen; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); } } public void XoaUser(string idUser) { try { using (SqlConnection conn = new SqlConnection(QUANLYNHASACH.quanlycosodulieu.GetChuoiKetNoi())) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "delUser"; cmd.CommandType = System.Data.CommandType.StoredProcedure; DbParameter param = cmd.CreateParameter(); param.ParameterName = "@idUser"; param.Value = idUser; param.DbType = System.Data.DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); conn.Close(); }; } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Thông báo lỗi"); } } public string CreateID() { SqlConnection conn = new SqlConnection(QUANLYNHASACH.connect.GetChuoiKetNoi()); conn.Open(); SqlCommand cmd = new SqlCommand("select isnull(max(cast(substring(idUser,1,4) as int)),0) from USERS", conn); int count = (int)cmd.ExecuteScalar() + 1; string id= "000" + count.ToString(); conn.Close(); return id; } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/BLL/User_BLL.cs
C#
art
7,741
using System; using System.Collections.Generic; using System.Text; namespace QUANLYNHASACH { public class User_td { private string _idUser = ""; public string idUser { get { return _idUser; } set { _idUser = value; } } private string _idGroup = ""; public string idGroup { get { return _idGroup; } set { _idGroup = value; } } private string _Username = ""; public string Username { get { return _Username; } set { _Username = value; } } private string _Password = ""; public string Password { get { return _Password; } set { _Password = value; } } private string _HoTen = ""; public string HoTen { get { return _HoTen; } set { _HoTen = value; } } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/DAL/User_td.cs
C#
art
999
using System; using System.Collections.Generic; using System.Text; namespace QUANLYNHASACH { class Group_td { private string _idGroup = ""; public string idGroup { get { return _idGroup; } set { _idGroup = value; } } private string _CapBac = ""; public string CapBac { get { return _CapBac; } set { _CapBac = value; } } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/DAL/Group_td.cs
C#
art
474
using System; using System.Collections.Generic; using System.Text; namespace QUANLYNHASACH { public class NXB_td { public NXB_td() { } string idNhaXuatBan = ""; string TenNXB = ""; string DiaChi = ""; string NguoiDaiDien = ""; string SoDienThoai = ""; string Email = ""; public string _idNhaXuatBan { get { return idNhaXuatBan; } set { if (idNhaXuatBan != (string)value) idNhaXuatBan = (string)value; } } public string _TenNXB { get { return TenNXB ; } set { if (TenNXB != (string)value) TenNXB = (string)value; } } public string _DiaChi { get { return DiaChi; } set { if (DiaChi != (string)value) DiaChi = (string)value; } } public string _NguoiDaiDien { get { return NguoiDaiDien; } set { if (NguoiDaiDien != (string)value) NguoiDaiDien = (string)value; } } public string _SoDienThoai { get { return SoDienThoai; } set { if (SoDienThoai != (string)value) SoDienThoai = (string)value; } } public string _Email { get { return Email; } set { if (Email != (string)value) Email = (string)value; } } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/DAL/NXB_td.cs
C#
art
2,098
using System; using System.Collections.Generic; using System.Text; namespace QUANLYNHASACH.App_code.DAL { class SACH_td { private string _idSach = ""; public string idSach { get { return _idSach; } set { _idSach = value; } } private string _idTheLoai = ""; public string idTheLoai { get { return _idTheLoai;} set { _idTheLoai = value; } } private string _idNhaXuatBan = ""; public string idNhaXuatBan { get { return _idNhaXuatBan; } set { _idNhaXuatBan = value; } } private string _TenSach = ""; public string TenSach { get { return _TenSach;} set { _TenSach = value; } } private string _TacGia = ""; public string TacGia { get { return _TacGia; } set { _TacGia = value; } } private string _DichGia = ""; public string DichGia { get { return _DichGia; } set { _DichGia = value; } } private int _SoTrang = 0; public int SoTrang { get { return _SoTrang; } set { _SoTrang = value; } } private float _KichThuoc = 0; public float KichThuoc { get { return _KichThuoc; } set { _KichThuoc = value; } } private string _HinhThuc; public string HinhThuc { get { return _HinhThuc; } set { _HinhThuc = value; } } private float _TrongLuong = 0; public float TrongLuong { get { return _TrongLuong; } set { _TrongLuong = value; } } private float _GiaBan = 0; public float GiaBan { get { return _GiaBan; } set { _GiaBan = value; } } private int _SLTrongKho = 0; public int SLTrongKho { get { return _SLTrongKho; } set { _SLTrongKho = value; } } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/DAL/SACH_td.cs
C#
art
2,314
using System; using System.Collections.Generic; using System.Text; namespace QUANLYNHASACH.App_code.DAL { class THELOAI_td { private string _idTheLoai = ""; public string idTheLoai { get { return _idTheLoai; } set { _idTheLoai = value; } } private string _TenTheLoai = ""; public string TenTheLoai { get { return _TenTheLoai; } set { _TenTheLoai = value; } } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/App_code/DAL/THELOAI_td.cs
C#
art
517
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace QUANLYNHASACH { public partial class frmQuanLyNXB : Form { QUANLYNHASACH.App_code.BLL.NXB_BLL bllNXB = new QUANLYNHASACH.App_code.BLL.NXB_BLL(); public frmQuanLyNXB() { InitializeComponent(); } private void frmQuanLyNXB_Load(object sender, EventArgs e) { Gridnxb.DataSource = bllNXB.LayDanhSachNXB(); } private void bttSua_Click(object sender, EventArgs e) { bool isCheck = false; for (int i = 0; i < this.Gridnxb.Rows.Count; i++) { if (this.Gridnxb.Rows[i].Cells[0].Value != null) { isCheck = (bool)this.Gridnxb.Rows[i].Cells[0].Value; string idNXB = this.Gridnxb.Rows[i].Cells[1].Value.ToString(); string tenNXB = this.Gridnxb.Rows[i].Cells[2].Value.ToString(); string Diachi = this.Gridnxb.Rows[i].Cells[3].Value.ToString(); string nguoiDD = this.Gridnxb.Rows[i].Cells[4].Value.ToString(); string soDT = this.Gridnxb.Rows[i].Cells[5].Value.ToString(); string Email = this.Gridnxb.Rows[i].Cells[6].Value.ToString(); if (isCheck == true) { bllNXB.CapNhatNXB(idNXB, tenNXB, Diachi, nguoiDD, soDT, Email); } } } MessageBox.Show("Đã cập nhật danh sách NXB thành công", "Thông báo"); } private void bttThem_Click(object sender, EventArgs e) { string idNXB=txtID.Text;; string tenNXB=txtTenNXB.Text; string Diachi=txtDiaChi.Text; string nguoiDD=txtNguoiDD.Text; string soDT= txtSoDT.Text; string Email=txtEmail.Text; bllNXB.ThemNXB(idNXB, tenNXB, Diachi, nguoiDD, soDT, Email); MessageBox.Show("Đã thêm NXB thành công", "Thông báo"); Gridnxb.DataSource = bllNXB.LayDanhSachNXB(); } private void bttXoa_Click(object sender, EventArgs e) { bool isCheck = false; for (int i = 0; i < this.Gridnxb.Rows.Count; i++) { if (this.Gridnxb.Rows[i].Cells[0].Value != null) { isCheck = (bool)this.Gridnxb.Rows[i].Cells[0].Value; string idNXB = this.Gridnxb.Rows[i].Cells[1].Value.ToString(); if (isCheck == true) { bllNXB.XoaNXB(idNXB); } Gridnxb.DataSource = bllNXB.LayDanhSachNXB(); } } } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/QUANLYNHASACH/frmQuanLyNXB.cs
C#
art
3,063
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("QUANLYNHASACH")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("tsd")] [assembly: AssemblyProduct("QUANLYNHASACH")] [assembly: AssemblyCopyright("Copyright © tsd 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("db1c49da-c525-4d94-9cf2-2a6e3fa50d5c")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/Backup/QUANLYNHASACH/Properties/AssemblyInfo.cs
C#
art
1,280
using System; using System.Collections.Generic; using System.Windows.Forms; namespace QUANLYNHASACH { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmQuanLyBanHang()); } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/Backup/QUANLYNHASACH/Program.cs
C#
art
491
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.Common; using QUANLYNHASACH.App_code.DAL.ds_quanlybansachTableAdapters; namespace QUANLYNHASACH { public partial class frmQuanLyBanHang : Form { public frmQuanLyBanHang() { InitializeComponent(); } private void frmQuanLyBanHang_Load(object sender, EventArgs e) { DONHANGTableAdapter donhang = new DONHANGTableAdapter(); DataTable dt_donhang = donhang.LoadHD(); dtgSACH.DataSource = dt_donhang; } } }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/Backup/QUANLYNHASACH/frmQuanLyBanHang.cs
C#
art
760
BODY { BACKGROUND-COLOR: white; FONT-FAMILY: "Verdana", sans-serif; FONT-SIZE: 100%; MARGIN-LEFT: 0px; MARGIN-TOP: 0px } P { FONT-FAMILY: "Verdana", sans-serif; FONT-SIZE: 70%; LINE-HEIGHT: 12pt; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 10px; MARGIN-TOP: 10px } .note { BACKGROUND-COLOR: #ffffff; COLOR: #336699; FONT-FAMILY: "Verdana", sans-serif; FONT-SIZE: 100%; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 0px; MARGIN-TOP: 0px; PADDING-RIGHT: 10px } .infotable { BACKGROUND-COLOR: #f0f0e0; BORDER-BOTTOM: #ffffff 0px solid; BORDER-COLLAPSE: collapse; BORDER-LEFT: #ffffff 0px solid; BORDER-RIGHT: #ffffff 0px solid; BORDER-TOP: #ffffff 0px solid; FONT-SIZE: 70%; MARGIN-LEFT: 10px } .issuetable { BACKGROUND-COLOR: #ffffe8; BORDER-COLLAPSE: collapse; COLOR: #000000; FONT-SIZE: 100%; MARGIN-BOTTOM: 10px; MARGIN-LEFT: 13px; MARGIN-TOP: 0px } .issuetitle { BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #dcdcdc 1px solid; BORDER-TOP: #dcdcdc 1px; COLOR: #003366; FONT-WEIGHT: normal } .header { BACKGROUND-COLOR: #cecf9c; BORDER-BOTTOM: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; COLOR: #000000; FONT-WEIGHT: bold } .issuehdr { BACKGROUND-COLOR: #E0EBF5; BORDER-BOTTOM: #dcdcdc 1px solid; BORDER-TOP: #dcdcdc 1px solid; COLOR: #000000; FONT-WEIGHT: normal } .issuenone { BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-RIGHT: 0px; BORDER-TOP: 0px; COLOR: #000000; FONT-WEIGHT: normal } .content { BACKGROUND-COLOR: #e7e7ce; BORDER-BOTTOM: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; PADDING-LEFT: 3px } .issuecontent { BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #dcdcdc 1px solid; BORDER-TOP: #dcdcdc 1px solid; PADDING-LEFT: 3px } A:link { COLOR: #cc6633; TEXT-DECORATION: underline } A:visited { COLOR: #cc6633; } A:active { COLOR: #cc6633; } A:hover { COLOR: #cc3300; TEXT-DECORATION: underline } H1 { BACKGROUND-COLOR: #003366; BORDER-BOTTOM: #336699 6px solid; COLOR: #ffffff; FONT-SIZE: 130%; FONT-WEIGHT: normal; MARGIN: 0em 0em 0em -20px; PADDING-BOTTOM: 8px; PADDING-LEFT: 30px; PADDING-TOP: 16px } H2 { COLOR: #000000; FONT-SIZE: 80%; FONT-WEIGHT: bold; MARGIN-BOTTOM: 3px; MARGIN-LEFT: 10px; MARGIN-TOP: 20px; PADDING-LEFT: 0px } H3 { COLOR: #000000; FONT-SIZE: 80%; FONT-WEIGHT: bold; MARGIN-BOTTOM: -5px; MARGIN-LEFT: 10px; MARGIN-TOP: 20px } H4 { COLOR: #000000; FONT-SIZE: 70%; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; MARGIN-TOP: 15px; PADDING-BOTTOM: 0px } UL { COLOR: #000000; FONT-SIZE: 70%; LIST-STYLE: square; MARGIN-BOTTOM: 0pt; MARGIN-TOP: 0pt } OL { COLOR: #000000; FONT-SIZE: 70%; LIST-STYLE: square; MARGIN-BOTTOM: 0pt; MARGIN-TOP: 0pt } LI { LIST-STYLE: square; MARGIN-LEFT: 0px } .expandable { CURSOR: hand } .expanded { color: black } .collapsed { DISPLAY: none } .foot { BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #cecf9c 1px solid; BORDER-TOP: #cecf9c 2px solid } .settings { MARGIN-LEFT: 25PX; } .help { TEXT-ALIGN: right; margin-right: 10px; }
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/_UpgradeReport_Files/UpgradeReport.css
CSS
art
3,348
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl='urn:schemas-microsoft-com:xslt'> <xsl:key name="ProjectKey" match="Event" use="@Project" /> <xsl:template match="Events" mode="createProjects"> <projects> <xsl:for-each select="Event"> <!--xsl:sort select="@Project" order="descending"/--> <xsl:if test="(1=position()) or (preceding-sibling::*[1]/@Project != @Project)"> <xsl:variable name="ProjectName" select="@Project"/> <project> <xsl:attribute name="name"> <xsl:value-of select="@Project"/> </xsl:attribute> <xsl:if test="@Project=''"> <xsl:attribute name="solution"> <xsl:value-of select="@Solution"/> </xsl:attribute> </xsl:if> <xsl:for-each select="key('ProjectKey', $ProjectName)"> <!--xsl:sort select="@Source" /--> <xsl:if test="(1=position()) or (preceding-sibling::*[1]/@Source != @Source)"> <source> <xsl:attribute name="name"> <xsl:value-of select="@Source"/> </xsl:attribute> <xsl:variable name="Source"> <xsl:value-of select="@Source"/> </xsl:variable> <xsl:for-each select="key('ProjectKey', $ProjectName)[ @Source = $Source ]"> <event> <xsl:attribute name="error-level"> <xsl:value-of select="@ErrorLevel"/> </xsl:attribute> <xsl:attribute name="description"> <xsl:value-of select="@Description"/> </xsl:attribute> </event> </xsl:for-each> </source> </xsl:if> </xsl:for-each> </project> </xsl:if> </xsl:for-each> </projects> </xsl:template> <xsl:template match="projects"> <xsl:for-each select="project"> <xsl:sort select="@Name" order="ascending"/> <h2> <xsl:if test="@solution"><a _locID="Solution">Solution</a>: <xsl:value-of select="@solution"/></xsl:if> <xsl:if test="not(@solution)"><a _locID="Project">Project</a>: <xsl:value-of select="@name"/> <xsl:for-each select="source"> <xsl:variable name="Hyperlink" select="@name"/> <xsl:for-each select="event[@error-level='4']"> &#32;<A class="note"><xsl:attribute name="HREF"><xsl:value-of select="$Hyperlink"/></xsl:attribute><xsl:value-of select="@description"/></A> </xsl:for-each> </xsl:for-each> </xsl:if> </h2> <table cellpadding="2" cellspacing="0" width="98%" border="1" bordercolor="white" class="infotable"> <tr> <td nowrap="1" class="header" _locID="Filename">Filename</td> <td nowrap="1" class="header" _locID="Status">Status</td> <td nowrap="1" class="header" _locID="Errors">Errors</td> <td nowrap="1" class="header" _locID="Warnings">Warnings</td> </tr> <xsl:for-each select="source"> <xsl:sort select="@name" order="ascending"/> <xsl:variable name="source-id" select="generate-id(.)"/> <xsl:if test="count(event)!=count(event[@error-level='4'])"> <tr class="row"> <td class="content"> <A HREF="javascript:"><xsl:attribute name="onClick">javascript:document.images['<xsl:value-of select="$source-id"/>'].click()</xsl:attribute><IMG border="0" _locID="IMG.alt" _locAttrData="alt" alt="expand/collapse section" class="expandable" height="11" onclick="changepic()" src="_UpgradeReport_Files/UpgradeReport_Plus.gif" width="9" ><xsl:attribute name="name"><xsl:value-of select="$source-id"/></xsl:attribute><xsl:attribute name="child">src<xsl:value-of select="$source-id"/></xsl:attribute></IMG></A>&#32;<xsl:value-of select="@name"/> </td> <td class="content"> <xsl:if test="count(event[@error-level='3'])=1"> <xsl:for-each select="event[@error-level='3']"> <xsl:if test="@description='Converted'"><a _locID="Converted1">Converted</a></xsl:if> <xsl:if test="@description!='Converted'"><xsl:value-of select="@description"/></xsl:if> </xsl:for-each> </xsl:if> <xsl:if test="count(event[@error-level='3'])!=1 and count(event[@error-level='3' and @description='Converted'])!=0"><a _locID="Converted2">Converted</a> </xsl:if> </td> <td class="content"><xsl:value-of select="count(event[@error-level='2'])"/></td> <td class="content"><xsl:value-of select="count(event[@error-level='1'])"/></td> </tr> <tr class="collapsed" bgcolor="#ffffff"> <xsl:attribute name="id">src<xsl:value-of select="$source-id"/></xsl:attribute> <td colspan="7"> <table width="97%" border="1" bordercolor="#dcdcdc" rules="cols" class="issuetable"> <tr> <td colspan="7" class="issuetitle" _locID="ConversionIssues">Conversion Issues - <xsl:value-of select="@name"/>:</td> </tr> <xsl:for-each select="event[@error-level!='3']"> <xsl:if test="@error-level!='4'"> <tr> <td class="issuenone" style="border-bottom:solid 1 lightgray"> <xsl:value-of select="@description"/> </td> </tr> </xsl:if> </xsl:for-each> </table> </td> </tr> </xsl:if> </xsl:for-each> <tr valign="top"> <td class="foot"> <xsl:if test="count(source)!=1"> <xsl:value-of select="count(source)"/><a _locID="file1"> files</a> </xsl:if> <xsl:if test="count(source)=1"> <a _locID="file2">1 file</a> </xsl:if> </td> <td class="foot"> <a _locID="Converted3">Converted</a>:&#32;<xsl:value-of select="count(source/event[@error-level='3' and @description='Converted'])"/><BR /> <a _locID="NotConverted">Not converted</a>:&#32;<xsl:value-of select="count(source) - count(source/event[@error-level='3' and @description='Converted'])"/> </td> <td class="foot"><xsl:value-of select="count(source/event[@error-level='2'])"/></td> <td class="foot"><xsl:value-of select="count(source/event[@error-level='1'])"/></td> </tr> </table> </xsl:for-each> </xsl:template> <xsl:template match="Property"> <xsl:if test="@Name!='Date' and @Name!='Time' and @Name!='LogNumber' and @Name!='Solution'"> <tr><td nowrap="1"><b><xsl:value-of select="@Name"/>: </b><xsl:value-of select="@Value"/></td></tr> </xsl:if> </xsl:template> <xsl:template match="UpgradeLog"> <html> <head> <META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="_UpgradeReport_Files\UpgradeReport.css" /> <title _locID="ConversionReport0">Conversion Report&#32; <xsl:if test="Properties/Property[@Name='LogNumber']"> <xsl:value-of select="Properties/Property[@Name='LogNumber']/@Value"/> </xsl:if> </title> <script language="javascript"> function outliner () { oMe = window.event.srcElement //get child element var child = document.all[event.srcElement.getAttribute("child",false)]; //if child element exists, expand or collapse it. if (null != child) child.className = child.className == "collapsed" ? "expanded" : "collapsed"; } function changepic() { uMe = window.event.srcElement; var check = uMe.src.toLowerCase(); if (check.lastIndexOf("upgradereport_plus.gif") != -1) { uMe.src = "_UpgradeReport_Files/UpgradeReport_Minus.gif" } else { uMe.src = "_UpgradeReport_Files/UpgradeReport_Plus.gif" } } </script> </head> <body topmargin="0" leftmargin="0" rightmargin="0" onclick="outliner();"> <h1 _locID="ConversionReport">Conversion Report - <xsl:value-of select="Properties/Property[@Name='Solution']/@Value"/></h1> <p><span class="note"> <b _locID="TimeOfConversion">Time of Conversion:</b>&#32;&#32;<xsl:value-of select="Properties/Property[@Name='Date']/@Value"/>&#32;&#32;<xsl:value-of select="Properties/Property[@Name='Time']/@Value"/><br/> </span></p> <xsl:variable name="SortedEvents"> <Events> <xsl:for-each select="Event"> <xsl:sort select="@Project" order="ascending"/> <xsl:sort select="@Source" order="ascending"/> <xsl:sort select="@ErrorLevel" order="ascending"/> <Event> <xsl:attribute name="Project"><xsl:value-of select="@Project"/> </xsl:attribute> <xsl:attribute name="Solution"><xsl:value-of select="/UpgradeLog/Properties/Property[@Name='Solution']/@Value"/> </xsl:attribute> <xsl:attribute name="Source"><xsl:value-of select="@Source"/> </xsl:attribute> <xsl:attribute name="ErrorLevel"><xsl:value-of select="@ErrorLevel"/> </xsl:attribute> <xsl:attribute name="Description"><xsl:value-of select="@Description"/> </xsl:attribute> </Event> </xsl:for-each> </Events> </xsl:variable> <xsl:variable name="Projects"> <xsl:apply-templates select="msxsl:node-set($SortedEvents)/*" mode="createProjects"/> </xsl:variable> <xsl:apply-templates select="msxsl:node-set($Projects)/*"/> <p></p><p> <table class="note"> <tr> <td nowrap="1"> <b _locID="ConversionSettings">Conversion Settings</b> </td> </tr> <xsl:apply-templates select="Properties"/> </table></p> </body> </html> </xsl:template> </xsl:stylesheet>
06th1d-12-quanlynhasach
trunk/QUANLYNHASACH/_UpgradeReport_Files/UpgradeReport.xslt
XSLT
art
12,579
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("unittests_formtheloai")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("unittests_formtheloai")] [assembly: AssemblyCopyright("Copyright © 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("e21e7895-9e37-417b-ba26-df1caef96be0")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
06th1d-12-quanlynhasach
trunk/unittests_formtheloai/unittests_formtheloai/Properties/AssemblyInfo.cs
C#
art
1,454
using System; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; namespace QUANLYNHASACH { [TestFixture] public class testTheLoai { /// <summary> /// test them the loai voi thong tin day du va chinh xac /// </summary> [Test] public void ThemTheLoai_test() { bool result = QUANLYNHASACH.App_code.BLL.THELOAI_BLL.ThemTheLoai("3", "tham khao"); Assert.AreEqual(result, true); } [Test] public void SuaTheLoai_test() { bool result = QUANLYNHASACH.App_code.BLL.THELOAI_BLL.suaTheLoai("3", "tham khao new"); Assert.AreEqual(result, true); } [Test] public void XoaTheLoai_test() { bool result = QUANLYNHASACH.App_code.BLL.THELOAI_BLL.xoaTheLoai("3"); Assert.AreEqual(result, true); } } }
06th1d-12-quanlynhasach
trunk/unittests_formtheloai/unittests_formtheloai/testTheLoai.cs
C#
art
992
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("unittest_frmDangNhap")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("unittest_frmDangNhap")] [assembly: AssemblyCopyright("Copyright © 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("ecd385db-34ad-44ef-b5b8-16ad35cbf74b")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
06th1d-12-quanlynhasach
trunk/unittest_frmDangNhap/unittest_frmDangNhap/Properties/AssemblyInfo.cs
C#
art
1,452
using System; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; namespace QUANLYNHASACH { [TestFixture] public class testDangNhap { [Test] public void layusername_test() { bool user = QUANLYNHASACH.App_code.BLL.DANGNHAP_BLL.layusername("sa"); Assert.AreEqual(user, true); } [Test] public void laypassword_test() { bool pass = QUANLYNHASACH.App_code.BLL.DANGNHAP_BLL.laypassword("123"); Assert.AreEqual(pass, true); } } }
06th1d-12-quanlynhasach
trunk/unittest_frmDangNhap/unittest_frmDangNhap/testDangNhap.cs
C#
art
625
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("unittest_frmSACH")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("unittest_frmSACH")] [assembly: AssemblyCopyright("Copyright © 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("77d6f576-6418-4291-b2cc-07ad0022f356")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
06th1d-12-quanlynhasach
trunk/unittest_frmSACH/unittest_frmSACH/Properties/AssemblyInfo.cs
C#
art
1,444
using System; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; namespace QUANLYNHASACH { [TestFixture] public class testSACH { [Test] public void ThemSach_test() { bool result = QUANLYNHASACH.App_code.BLL.SACH_BLL.ThemSach("12", "0001", "0001", "Connan", "Connan", "Phan Thị", 43, 3, "sách", 12, 8000, 20); Assert.AreEqual(result, true); } [Test] public void SuaSach_test() { bool result = QUANLYNHASACH.App_code.BLL.SACH_BLL.suasach("12", "0001", "0001", "Connan_new", "Connan_new", "Phan Thị new", 42, 3, "sach", 12, 8000, 20); Assert.AreEqual(result, true); } [Test] public void XoaSach_test() { bool result = QUANLYNHASACH.App_code.BLL.SACH_BLL.xoasach("12"); Assert.AreEqual(result, true); } } }
06th1d-12-quanlynhasach
trunk/unittest_frmSACH/unittest_frmSACH/testSACH.cs
C#
art
983
package org.poly2tri.triangulation.point.ardor3d; import java.util.ArrayList; import java.util.List; import org.poly2tri.geometry.polygon.PolygonPoint; import org.poly2tri.triangulation.TriangulationPoint; import com.ardor3d.math.Vector3; public class ArdorVector3PolygonPoint extends PolygonPoint { private final Vector3 _p; public ArdorVector3PolygonPoint( Vector3 point ) { super( point.getX(), point.getY() ); _p = point; } public final double getX() { return _p.getX(); } public final double getY() { return _p.getY(); } public final double getZ() { return _p.getZ(); } public final float getXf() { return _p.getXf(); } public final float getYf() { return _p.getYf(); } public final float getZf() { return _p.getZf(); } public static List<PolygonPoint> toPoints( Vector3[] vpoints ) { ArrayList<PolygonPoint> points = new ArrayList<PolygonPoint>(vpoints.length); for( int i=0; i<vpoints.length; i++ ) { points.add( new ArdorVector3PolygonPoint(vpoints[i]) ); } return points; } public static List<PolygonPoint> toPoints( ArrayList<Vector3> vpoints ) { int i=0; ArrayList<PolygonPoint> points = new ArrayList<PolygonPoint>(vpoints.size()); for( Vector3 point : vpoints ) { points.add( new ArdorVector3PolygonPoint(point) ); } return points; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-ardor3d/src/main/java/org/poly2tri/triangulation/point/ardor3d/ArdorVector3PolygonPoint.java
Java
bsd
1,641
package org.poly2tri.triangulation.point.ardor3d; import java.util.ArrayList; import java.util.List; import org.poly2tri.triangulation.TriangulationPoint; import com.ardor3d.math.Vector3; public class ArdorVector3Point extends TriangulationPoint { private final Vector3 _p; public ArdorVector3Point( Vector3 point ) { _p = point; } public final double getX() { return _p.getX(); } public final double getY() { return _p.getY(); } public final double getZ() { return _p.getZ(); } public final float getXf() { return _p.getXf(); } public final float getYf() { return _p.getYf(); } public final float getZf() { return _p.getZf(); } @Override public void set( double x, double y, double z ) { _p.set( x, y, z ); } public static List<TriangulationPoint> toPoints( Vector3[] vpoints ) { ArrayList<TriangulationPoint> points = new ArrayList<TriangulationPoint>(vpoints.length); for( int i=0; i<vpoints.length; i++ ) { points.add( new ArdorVector3Point(vpoints[i]) ); } return points; } public static List<TriangulationPoint> toPoints( ArrayList<Vector3> vpoints ) { int i=0; ArrayList<TriangulationPoint> points = new ArrayList<TriangulationPoint>(vpoints.size()); for( Vector3 point : vpoints ) { points.add( new ArdorVector3Point(point) ); } return points; } public static List<TriangulationPoint> toPolygonPoints( Vector3[] vpoints ) { ArrayList<TriangulationPoint> points = new ArrayList<TriangulationPoint>(vpoints.length); for( int i=0; i<vpoints.length; i++ ) { points.add( new ArdorVector3PolygonPoint(vpoints[i]) ); } return points; } public static List<TriangulationPoint> toPolygonPoints( ArrayList<Vector3> vpoints ) { int i=0; ArrayList<TriangulationPoint> points = new ArrayList<TriangulationPoint>(vpoints.size()); for( Vector3 point : vpoints ) { points.add( new ArdorVector3PolygonPoint(point) ); } return points; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-ardor3d/src/main/java/org/poly2tri/triangulation/point/ardor3d/ArdorVector3Point.java
Java
bsd
2,416
package org.poly2tri.triangulation.tools.ardor3d; import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.HashMap; import java.util.List; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.geometry.primitives.Point; import org.poly2tri.transform.coordinate.CoordinateTransform; import org.poly2tri.transform.coordinate.NoTransform; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; import org.poly2tri.triangulation.point.TPoint; import org.poly2tri.triangulation.sets.PointSet; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.IndexMode; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.util.geom.BufferUtils; public class ArdorMeshMapper { private static final CoordinateTransform _ct = new NoTransform(); public static void updateTriangleMesh( Mesh mesh, List<DelaunayTriangle> triangles ) { updateTriangleMesh( mesh, triangles, _ct ); } public static void updateTriangleMesh( Mesh mesh, List<DelaunayTriangle> triangles, CoordinateTransform pc ) { FloatBuffer vertBuf; TPoint point; mesh.getMeshData().setIndexMode( IndexMode.Triangles ); if( triangles == null || triangles.size() == 0 ) { return; } point = new TPoint(0,0,0); int size = 3*3*triangles.size(); prepareVertexBuffer( mesh, size ); vertBuf = mesh.getMeshData().getVertexBuffer(); vertBuf.rewind(); for( DelaunayTriangle t : triangles ) { for( int i=0; i<3; i++ ) { pc.transform( t.points[i], point ); vertBuf.put(point.getXf()); vertBuf.put(point.getYf()); vertBuf.put(point.getZf()); } } } public static void updateFaceNormals( Mesh mesh, List<DelaunayTriangle> triangles ) { updateFaceNormals( mesh, triangles, _ct ); } public static void updateFaceNormals( Mesh mesh, List<DelaunayTriangle> triangles, CoordinateTransform pc ) { FloatBuffer nBuf; Vector3 fNormal; HashMap<DelaunayTriangle,Vector3> fnMap; int size = 3*3*triangles.size(); fnMap = calculateFaceNormals( triangles, pc ); prepareNormalBuffer( mesh, size ); nBuf = mesh.getMeshData().getNormalBuffer(); nBuf.rewind(); for( DelaunayTriangle t : triangles ) { fNormal = fnMap.get( t ); for( int i=0; i<3; i++ ) { nBuf.put(fNormal.getXf()); nBuf.put(fNormal.getYf()); nBuf.put(fNormal.getZf()); } } } public static void updateVertexNormals( Mesh mesh, List<DelaunayTriangle> triangles ) { updateVertexNormals( mesh, triangles, _ct ); } public static void updateVertexNormals( Mesh mesh, List<DelaunayTriangle> triangles, CoordinateTransform pc ) { FloatBuffer nBuf; TriangulationPoint vertex; Vector3 vNormal, fNormal; HashMap<DelaunayTriangle,Vector3> fnMap; HashMap<TriangulationPoint,Vector3> vnMap = new HashMap<TriangulationPoint,Vector3>(3*triangles.size()); int size = 3*3*triangles.size(); fnMap = calculateFaceNormals( triangles, pc ); // Calculate a vertex normal for each vertex for( DelaunayTriangle t : triangles ) { fNormal = fnMap.get( t ); for( int i=0; i<3; i++ ) { vertex = t.points[i]; vNormal = vnMap.get( vertex ); if( vNormal == null ) { vNormal = new Vector3( fNormal.getX(), fNormal.getY(), fNormal.getZ() ); vnMap.put( vertex, vNormal ); } else { vNormal.addLocal( fNormal ); } } } // Normalize all normals for( Vector3 normal : vnMap.values() ) { normal.normalizeLocal(); } prepareNormalBuffer( mesh, size ); nBuf = mesh.getMeshData().getNormalBuffer(); nBuf.rewind(); for( DelaunayTriangle t : triangles ) { for( int i=0; i<3; i++ ) { vertex = t.points[i]; vNormal = vnMap.get( vertex ); nBuf.put(vNormal.getXf()); nBuf.put(vNormal.getYf()); nBuf.put(vNormal.getZf()); } } } private static HashMap<DelaunayTriangle,Vector3> calculateFaceNormals( List<DelaunayTriangle> triangles, CoordinateTransform pc ) { HashMap<DelaunayTriangle,Vector3> normals = new HashMap<DelaunayTriangle,Vector3>(triangles.size()); TPoint point = new TPoint(0,0,0); // calculate the Face Normals for all triangles float x1,x2,x3,y1,y2,y3,z1,z2,z3,nx,ny,nz,ux,uy,uz,vx,vy,vz; double norm; for( DelaunayTriangle t : triangles ) { pc.transform( t.points[0], point ); x1 = point.getXf(); y1 = point.getYf(); z1 = point.getZf(); pc.transform( t.points[1], point ); x2 = point.getXf(); y2 = point.getYf(); z2 = point.getZf(); pc.transform( t.points[2], point ); x3 = point.getXf(); y3 = point.getYf(); z3 = point.getZf(); ux = x2 - x1; uy = y2 - y1; uz = z2 - z1; vx = x3 - x1; vy = y3 - y1; vz = z3 - z1; nx = uy*vz - uz*vy; ny = uz*vx - ux*vz; nz = ux*vy - uy*vx; norm = 1/Math.sqrt( nx*nx + ny*ny + nz*nz ); nx *= norm; ny *= norm; nz *= norm; normals.put( t, new Vector3(nx,ny,nz) ); } return normals; } /** * For now very primitive! * * Assumes a single texture and that the triangles form a xy-monotone surface * <p> * A continuous surface S in R3 is called xy-monotone, if every line parallel * to the z-axis intersects it at a single point at most. * * @param mesh * @param scale */ public static void updateTextureCoordinates( Mesh mesh, List<DelaunayTriangle> triangles, double scale, double angle ) { TriangulationPoint vertex; FloatBuffer tcBuf; float width,maxX,minX,maxY,minY,x,y,xn,yn; maxX = Float.NEGATIVE_INFINITY; minX = Float.POSITIVE_INFINITY; maxY = Float.NEGATIVE_INFINITY; minY = Float.POSITIVE_INFINITY; for( DelaunayTriangle t : triangles ) { for( int i=0; i<3; i++ ) { vertex = t.points[i]; x = vertex.getXf(); y = vertex.getYf(); maxX = x > maxX ? x : maxX; minX = x < minX ? x : minX; maxY = y > maxY ? y : maxY; minY = y < minY ? x : minY; } } width = maxX-minX > maxY-minY ? maxX-minX : maxY-minY; width *= scale; tcBuf = prepareTextureCoordinateBuffer(mesh,0,2*3*triangles.size()); tcBuf.rewind(); for( DelaunayTriangle t : triangles ) { for( int i=0; i<3; i++ ) { vertex = t.points[i]; x = vertex.getXf()-(maxX-minX)/2; y = vertex.getYf()-(maxY-minY)/2; xn = (float)(x*Math.cos(angle)-y*Math.sin(angle)); yn = (float)(y*Math.cos(angle)+x*Math.sin(angle)); tcBuf.put( xn/width ); tcBuf.put( yn/width ); } } } /** * Assuming: * 1. That given U anv V aren't collinear. * 2. That O,U and V can be projected in the XY plane * * @param mesh * @param triangles * @param o * @param u * @param v */ public static void updateTextureCoordinates( Mesh mesh, List<DelaunayTriangle> triangles, double scale, Point o, Point u, Point v ) { FloatBuffer tcBuf; float x,y,a,b; final float ox = (float)scale*o.getXf(); final float oy = (float)scale*o.getYf(); final float ux = (float)scale*u.getXf(); final float uy = (float)scale*u.getYf(); final float vx = (float)scale*v.getXf(); final float vy = (float)scale*v.getYf(); final float vCu = (vx*uy-vy*ux); final boolean doX = Math.abs( ux ) > Math.abs( uy ); tcBuf = prepareTextureCoordinateBuffer(mesh,0,2*3*triangles.size()); tcBuf.rewind(); for( DelaunayTriangle t : triangles ) { for( int i=0; i<3; i++ ) { x = t.points[i].getXf()-ox; y = t.points[i].getYf()-oy; // Calculate the texture coordinate in the UV plane a = (uy*x - ux*y)/vCu; if( doX ) { b = (x - a*vx)/ux; } else { b = (y - a*vy)/uy; } tcBuf.put( a ); tcBuf.put( b ); } } } // FloatBuffer vBuf,tcBuf; // float width,maxX,minX,maxY,minY,x,y,xn,yn; // // maxX = Float.NEGATIVE_INFINITY; // minX = Float.POSITIVE_INFINITY; // maxY = Float.NEGATIVE_INFINITY; // minY = Float.POSITIVE_INFINITY; // // vBuf = mesh.getMeshData().getVertexBuffer(); // for( int i=0; i < vBuf.limit()-1; i+=3 ) // { // x = vBuf.get(i); // y = vBuf.get(i+1); // // maxX = x > maxX ? x : maxX; // minX = x < minX ? x : minX; // maxY = y > maxY ? y : maxY; // minY = y < minY ? x : minY; // } // // width = maxX-minX > maxY-minY ? maxX-minX : maxY-minY; // width *= scale; // // vBuf = mesh.getMeshData().getVertexBuffer(); // tcBuf = prepareTextureCoordinateBuffer(mesh,0,2*vBuf.limit()/3); // tcBuf.rewind(); // // for( int i=0; i < vBuf.limit()-1; i+=3 ) // { // x = vBuf.get(i)-(maxX-minX)/2; // y = vBuf.get(i+1)-(maxY-minY)/2; // xn = (float)(x*Math.cos(angle)-y*Math.sin(angle)); // yn = (float)(y*Math.cos(angle)+x*Math.sin(angle)); // tcBuf.put( xn/width ); // tcBuf.put( yn/width ); // } public static void updateTriangleMesh( Mesh mesh, PointSet ps, CoordinateTransform pc ) { updateTriangleMesh( mesh, ps.getTriangles(), pc ); } /** * Will populate a given Mesh's vertex,index buffer and set IndexMode.Triangles<br> * Will also increase buffer sizes if needed by creating new buffers. * * @param mesh * @param ps */ public static void updateTriangleMesh( Mesh mesh, PointSet ps ) { updateTriangleMesh( mesh, ps.getTriangles() ); } public static void updateTriangleMesh( Mesh mesh, Polygon p ) { updateTriangleMesh( mesh, p.getTriangles() ); } public static void updateTriangleMesh( Mesh mesh, Polygon p, CoordinateTransform pc ) { updateTriangleMesh( mesh, p.getTriangles(), pc ); } public static void updateVertexBuffer( Mesh mesh, List<? extends Point> list ) { FloatBuffer vertBuf; int size = 3*list.size(); prepareVertexBuffer( mesh, size ); if( size == 0 ) { return; } vertBuf = mesh.getMeshData().getVertexBuffer(); vertBuf.rewind(); for( Point p : list ) { vertBuf.put(p.getXf()).put(p.getYf()).put(p.getZf()); } } public static void updateIndexBuffer( Mesh mesh, int[] index ) { IntBuffer indexBuf; if( index == null || index.length == 0 ) { return; } int size = index.length; prepareIndexBuffer( mesh, size ); indexBuf = mesh.getMeshData().getIndexBuffer(); indexBuf.rewind(); for( int i=0; i<size; i+=2 ) { indexBuf.put(index[i]).put( index[i+1] ); } } private static void prepareVertexBuffer( Mesh mesh, int size ) { FloatBuffer vertBuf; vertBuf = mesh.getMeshData().getVertexBuffer(); if( vertBuf == null || vertBuf.capacity() < size ) { vertBuf = BufferUtils.createFloatBuffer( size ); mesh.getMeshData().setVertexBuffer( vertBuf ); } else { vertBuf.limit( size ); mesh.getMeshData().updateVertexCount(); } } private static void prepareNormalBuffer( Mesh mesh, int size ) { FloatBuffer nBuf; nBuf = mesh.getMeshData().getNormalBuffer(); if( nBuf == null || nBuf.capacity() < size ) { nBuf = BufferUtils.createFloatBuffer( size ); mesh.getMeshData().setNormalBuffer( nBuf ); } else { nBuf.limit( size ); } } private static void prepareIndexBuffer( Mesh mesh, int size) { IntBuffer indexBuf = mesh.getMeshData().getIndexBuffer(); if( indexBuf == null || indexBuf.capacity() < size ) { indexBuf = BufferUtils.createIntBuffer( size ); mesh.getMeshData().setIndexBuffer( indexBuf ); } else { indexBuf.limit( size ); } } private static FloatBuffer prepareTextureCoordinateBuffer( Mesh mesh, int index, int size ) { FloatBuffer tcBuf; tcBuf = mesh.getMeshData().getTextureBuffer( index ); if( tcBuf == null || tcBuf.capacity() < size ) { tcBuf = BufferUtils.createFloatBuffer( size ); mesh.getMeshData().setTextureBuffer( tcBuf, index ); } else { tcBuf.limit( size ); } return tcBuf; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-ardor3d/src/main/java/org/poly2tri/triangulation/tools/ardor3d/ArdorMeshMapper.java
Java
bsd
15,811
package org.poly2tri.polygon.ardor3d; import java.util.ArrayList; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point; import org.poly2tri.triangulation.point.ardor3d.ArdorVector3PolygonPoint; import com.ardor3d.math.Vector3; public class ArdorPolygon extends Polygon { public ArdorPolygon( Vector3[] points ) { super( ArdorVector3PolygonPoint.toPoints( points ) ); } public ArdorPolygon( ArrayList<Vector3> points ) { super( ArdorVector3PolygonPoint.toPoints( points ) ); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-ardor3d/src/main/java/org/poly2tri/polygon/ardor3d/ArdorPolygon.java
Java
bsd
604
package org.poly2tri.examples.ardor3d; import java.util.ArrayList; import org.poly2tri.Poly2Tri; import org.poly2tri.examples.ardor3d.base.P2TSimpleExampleBase; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.geometry.polygon.PolygonPoint; import org.poly2tri.triangulation.tools.ardor3d.ArdorMeshMapper; import com.ardor3d.framework.FrameHandler; import com.ardor3d.input.logical.LogicalLayer; import com.ardor3d.math.ColorRGBA; import com.ardor3d.renderer.state.WireframeState; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.Node; import com.google.inject.Inject; public class CDTHoleExample extends P2TSimpleExampleBase { public static void main(final String[] args) { start(CDTHoleExample.class); } @Inject public CDTHoleExample( LogicalLayer logicalLayer, FrameHandler frameHandler ) { super( logicalLayer, frameHandler ); } @Override protected void initExample() { super.initExample(); Node node = new Node(); node.setRenderState( new WireframeState() ); _node.attachChild( node ); Polygon circle; Polygon hole; circle = createCirclePolygon( 64, 25, 1 ); hole = createCirclePolygon( 32, 25, 0.25, -0.5, -0.5 ); circle.addHole( hole ); hole = createCirclePolygon( 64, 25, 0.5, 0.25, 0.25 ); circle.addHole( hole ); Mesh mesh = new Mesh(); mesh.setDefaultColor( ColorRGBA.RED ); mesh.setTranslation( 0, 0, 0.01 ); node.attachChild( mesh ); Mesh mesh2 = new Mesh(); mesh2.setDefaultColor( ColorRGBA.BLUE ); _node.attachChild( mesh2 ); Poly2Tri.triangulate( circle ); ArdorMeshMapper.updateTriangleMesh( mesh, circle ); ArdorMeshMapper.updateTriangleMesh( mesh2, circle ); } private Polygon createCirclePolygon( int n, double scale, double radius ) { return createCirclePolygon( n, scale, radius, 0, 0 ); } private Polygon createCirclePolygon( int n, double scale, double radius, double x, double y ) { if( n < 3 ) n=3; PolygonPoint[] points = new PolygonPoint[n]; for( int i=0; i<n; i++ ) { points[i] = new PolygonPoint( scale*(x + radius*Math.cos( (2.0*Math.PI*i)/n )), scale*(y + radius*Math.sin( (2.0*Math.PI*i)/n ) )); } return new Polygon( points ); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/CDTHoleExample.java
Java
bsd
2,773
package org.poly2tri.examples.ardor3d.base; import java.net.URISyntaxException; import org.lwjgl.opengl.Display; import com.ardor3d.example.ExampleBase; import com.ardor3d.framework.FrameHandler; import com.ardor3d.image.Texture; import com.ardor3d.image.Image.Format; import com.ardor3d.input.logical.LogicalLayer; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.BlendState; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.WireframeState; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.util.TextureManager; import com.ardor3d.util.resource.ResourceLocatorTool; import com.ardor3d.util.resource.SimpleResourceLocator; import com.google.inject.Inject; public abstract class P2TSimpleExampleBase extends ExampleBase { protected Node _node; protected Quad _logotype; protected int _width,_height; @Inject public P2TSimpleExampleBase( LogicalLayer logicalLayer, FrameHandler frameHandler ) { super( logicalLayer, frameHandler ); } @Override protected void initExample() { _canvas.setVSyncEnabled( true ); _canvas.getCanvasRenderer().getCamera().setLocation(0, 0, 65); _width = Display.getDisplayMode().getWidth(); _height = Display.getDisplayMode().getHeight(); _root.getSceneHints().setLightCombineMode( LightCombineMode.Off ); _node = new Node(); _node.getSceneHints().setLightCombineMode( LightCombineMode.Off ); // _node.setRenderState( new WireframeState() ); _root.attachChild( _node ); try { SimpleResourceLocator srl = new SimpleResourceLocator(ExampleBase.class.getClassLoader().getResource("org/poly2tri/examples/data/")); ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_MODEL, srl); SimpleResourceLocator sr2 = new SimpleResourceLocator(ExampleBase.class.getClassLoader().getResource("org/poly2tri/examples/textures/")); ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, sr2); } catch (final URISyntaxException ex) { ex.printStackTrace(); } _logotype = new Quad("box", 128, 128 ); _logotype.setTranslation( 74, _height - 74, 0 ); _logotype.getSceneHints().setRenderBucketType( RenderBucketType.Ortho ); BlendState bs = new BlendState(); bs.setBlendEnabled( true ); bs.setEnabled( true ); bs.setSourceFunction(BlendState.SourceFunction.SourceAlpha); bs.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha); _logotype.setRenderState( bs ); TextureState ts = new TextureState(); ts.setEnabled(true); ts.setTexture(TextureManager.load("poly2tri_logotype_256x256.png", Texture.MinificationFilter.Trilinear, Format.GuessNoCompression, true)); _logotype.setRenderState(ts); _root.attachChild( _logotype ); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/base/P2TSimpleExampleBase.java
Java
bsd
3,237
package org.poly2tri.examples.ardor3d.base; import java.nio.FloatBuffer; import java.util.List; import org.poly2tri.geometry.polygon.PolygonSet; import org.poly2tri.triangulation.TriangulationAlgorithm; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.TriangulationProcess; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; import org.poly2tri.triangulation.delaunay.sweep.DTSweepContext; import org.poly2tri.triangulation.tools.ardor3d.ArdorMeshMapper; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.FrameHandler; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.LogicalLayer; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.IndexMode; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.WireframeState; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.MeshData; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.Point; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.ui.text.BasicText; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.geom.BufferUtils; public abstract class P2TExampleBase extends P2TSimpleExampleBase { protected TriangulationProcess _process; protected CDTSweepMesh _cdtSweepMesh; protected CDTSweepPoints _cdtSweepPoints; protected PolygonSet _polygonSet; private long _processTimestamp; /** Text fields used to present info about the example. */ protected final BasicText _exampleInfo[] = new BasicText[7]; public P2TExampleBase( LogicalLayer logicalLayer, FrameHandler frameHandler ) { super( logicalLayer, frameHandler ); } @Override protected void initExample() { super.initExample(); // Warmup the triangulation code for better performance // when we need triangulation during runtime // Poly2Tri.warmup(); _process = new TriangulationProcess(TriangulationAlgorithm.DTSweep); _cdtSweepPoints = new CDTSweepPoints(); _cdtSweepMesh = new CDTSweepMesh(); _node.attachChild( _cdtSweepPoints.getSceneNode() ); _node.attachChild( _cdtSweepMesh.getSceneNode() ); final Node textNodes = new Node("Text"); textNodes.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); textNodes.getSceneHints().setLightCombineMode(LightCombineMode.Off); _root.attachChild( textNodes ); for (int i = 0; i < _exampleInfo.length; i++) { _exampleInfo[i] = BasicText.createDefaultTextLabel("Text", "", 16); _exampleInfo[i].setTranslation(new Vector3(10, (_exampleInfo.length-i-1) * 20 + 10, 0)); textNodes.attachChild(_exampleInfo[i]); } updateText(); } protected DTSweepContext getContext() { return (DTSweepContext)_process.getContext(); } /** * Update text information. */ protected void updateText() { _exampleInfo[0].setText(""); _exampleInfo[1].setText("[Home] Toggle wireframe"); _exampleInfo[2].setText("[End] Toggle vertex points"); } @Override protected void updateExample(final ReadOnlyTimer timer) { if( _process.isDone() && _processTimestamp != _process.getTimestamp() ) { _processTimestamp = _process.getTimestamp(); updateMesh(); _exampleInfo[0].setText("[" + _process.getTriangulationTime() + "ms] " + _process.getPointCount() + " points" ); } } public void exit() { super.exit(); _process.shutdown(); } protected void triangulate() { _process.triangulate( _polygonSet ); } protected void updateMesh() { if( _process.getContext().getTriangulatable() != null ) { if( _process.getContext().isDebugEnabled() ) { if( _process.isDone() ) { _cdtSweepMesh.update( _process.getContext().getTriangulatable().getTriangles() ); _cdtSweepPoints.update( _process.getContext().getTriangulatable().getPoints() ); } else { _cdtSweepMesh.update( _process.getContext().getTriangles() ); _cdtSweepPoints.update( _process.getContext().getPoints() ); } } else { _cdtSweepMesh.update( _polygonSet.getPolygons().get(0).getTriangles() ); _cdtSweepPoints.update( _polygonSet.getPolygons().get(0).getPoints() ); } } } @Override public void registerInputTriggers() { super.registerInputTriggers(); _controlHandle.setMoveSpeed( 10 ); // HOME - toogleWireframe _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.HOME ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { _cdtSweepMesh.toogleWireframe(); } } ) ); // END - tooglePoints _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.END ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { _cdtSweepPoints.toogleVisibile(); } } ) ); } protected abstract class SceneElement<A> { protected Node _node; public SceneElement(String name) { _node = new Node(name); _node.getSceneHints().setAllPickingHints( false ); } public abstract void update( A element ); public Node getSceneNode() { return _node; } } protected class CDTSweepPoints extends SceneElement<List<TriangulationPoint>> { private Point m_point = new Point(); private boolean _pointsVisible = true; public CDTSweepPoints() { super("Mesh"); m_point.setDefaultColor( ColorRGBA.RED ); m_point.setPointSize( 1 ); m_point.setTranslation( 0, 0, 0.01 ); _node.attachChild( m_point ); MeshData md = m_point.getMeshData(); int size = 1000; FloatBuffer vertBuf = BufferUtils.createFloatBuffer( (int)size*3 ); md.setVertexBuffer( vertBuf ); } public void toogleVisibile() { if( _pointsVisible ) { m_point.removeFromParent(); _pointsVisible = false; } else { _node.attachChild( m_point ); _pointsVisible = true; } } @Override public void update( List<TriangulationPoint> list ) { ArdorMeshMapper.updateVertexBuffer( m_point, list ); } } protected class CDTSweepMesh extends SceneElement<List<DelaunayTriangle>> { private Mesh m_mesh = new Mesh(); private WireframeState _ws = new WireframeState(); public CDTSweepMesh() { super("Mesh"); MeshData md; m_mesh.setDefaultColor( ColorRGBA.BLUE ); m_mesh.setRenderState( _ws ); _node.attachChild( m_mesh ); md = m_mesh.getMeshData(); int size = 1000; FloatBuffer vertBuf = BufferUtils.createFloatBuffer( (int)size*3*3 ); md.setVertexBuffer( vertBuf ); md.setIndexMode( IndexMode.Triangles ); } public void toogleWireframe() { if( _ws.isEnabled() ) { _ws.setEnabled( false ); } else { _ws.setEnabled( true ); } } @Override public void update( List<DelaunayTriangle> triangles ) { ArdorMeshMapper.updateTriangleMesh( m_mesh, triangles ); } } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/base/P2TExampleBase.java
Java
bsd
9,020
package org.poly2tri.examples.ardor3d.misc; public enum ExampleModels { Test ("test.dat",1,0,0,true), Two ("2.dat",1,0,0,true), Debug ("debug.dat",1,0,0,false), Debug2 ("debug2.dat",1,0,0,false), Bird ("bird.dat",1,0,0,false), Custom ("funny.dat",1,0,0,false), Diamond ("diamond.dat",1,0,0,false), Dude ("dude.dat",1,-0.1,0,true), Nazca_heron ("nazca_heron.dat",1.3,0,0.35,false), Nazca_monkey ("nazca_monkey.dat",1,0,0,false), Star ("star.dat",1,0,0,false), Strange ("strange.dat",1,0,0,true), Tank ("tank.dat",1.3,0,0,true); private final static String m_basePath = "org/poly2tri/examples/data/"; private String m_filename; private double m_scale; private double m_x; private double m_y; private boolean _invertedYAxis; ExampleModels( String filename, double scale, double x, double y, boolean invertedY ) { m_filename = filename; m_scale = scale; m_x = x; m_y = y; _invertedYAxis = invertedY; } public String getFilename() { return m_basePath + m_filename; } public double getScale() { return m_scale; } public double getX() { return m_x; } public double getY() { return m_y; } public boolean invertedYAxis() { return _invertedYAxis; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/misc/ExampleModels.java
Java
bsd
1,573
/** * Copyright (c) 2008-2009 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ package org.poly2tri.examples.ardor3d.misc; import java.nio.FloatBuffer; import com.ardor3d.math.Vector3; import com.ardor3d.math.type.ReadOnlyVector3; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.util.geom.BufferUtils; public class Triangle extends Mesh { private static final long serialVersionUID = 1L; public Triangle() { this( "Triangle" ); } public Triangle(final String name ) { this( name, new Vector3( Math.cos( Math.toRadians( 90 ) ), Math.sin( Math.toRadians( 90 ) ), 0 ), new Vector3( Math.cos( Math.toRadians( 210 ) ), Math.sin( Math.toRadians( 210 ) ), 0 ), new Vector3( Math.cos( Math.toRadians( 330 ) ), Math.sin( Math.toRadians( 330 ) ), 0 )); } public Triangle(final String name, ReadOnlyVector3 a, ReadOnlyVector3 b, ReadOnlyVector3 c ) { super(name); initialize(a,b,c); } /** * <code>resize</code> changes the width and height of the given quad by altering its vertices. * * @param width * the new width of the <code>Quad</code>. * @param height * the new height of the <code>Quad</code>. */ // public void resize( double radius ) // { // _meshData.getVertexBuffer().clear(); // _meshData.getVertexBuffer().put((float) (-width / 2)).put((float) (height / 2)).put(0); // _meshData.getVertexBuffer().put((float) (-width / 2)).put((float) (-height / 2)).put(0); // _meshData.getVertexBuffer().put((float) (width / 2)).put((float) (-height / 2)).put(0); // _meshData.getVertexBuffer().put((float) (width / 2)).put((float) (height / 2)).put(0); // } /** * <code>initialize</code> builds the data for the <code>Quad</code> object. * * @param width * the width of the <code>Quad</code>. * @param height * the height of the <code>Quad</code>. */ private void initialize(ReadOnlyVector3 a, ReadOnlyVector3 b, ReadOnlyVector3 c ) { final int verts = 3; _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(3)); _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(3)); final FloatBuffer tbuf = BufferUtils.createVector2Buffer(3); _meshData.setTextureBuffer(tbuf, 0); _meshData.setIndexBuffer(BufferUtils.createIntBuffer(3)); Vector3 ba = Vector3.fetchTempInstance(); Vector3 ca = Vector3.fetchTempInstance(); ba.set( b ).subtractLocal( a ); ca.set( c ).subtractLocal( a ); ba.crossLocal( ca ).normalizeLocal(); _meshData.getNormalBuffer().put(ba.getXf()).put(ba.getYf()).put(ba.getZf()); _meshData.getNormalBuffer().put(ba.getXf()).put(ba.getYf()).put(ba.getZf()); _meshData.getNormalBuffer().put(ba.getXf()).put(ba.getYf()).put(ba.getZf()); Vector3.releaseTempInstance( ba ); Vector3.releaseTempInstance( ca ); tbuf.put(0).put(1); tbuf.put(0).put(0); tbuf.put(1).put(0); _meshData.getIndexBuffer().put(0); _meshData.getIndexBuffer().put(1); _meshData.getIndexBuffer().put(2); _meshData.getVertexBuffer().put(a.getXf()).put(a.getYf()).put(a.getZf()); _meshData.getVertexBuffer().put(b.getXf()).put(b.getYf()).put(b.getZf()); _meshData.getVertexBuffer().put(c.getXf()).put(c.getYf()).put(c.getZf()); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/misc/Triangle.java
Java
bsd
3,822
package org.poly2tri.examples.ardor3d.misc; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.polygon.ardor3d.ArdorPolygon; import org.poly2tri.triangulation.TriangulationPoint; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ardor3d.math.Vector3; public class PolygonLoader { private final static Logger logger = LoggerFactory.getLogger( PolygonLoader.class ); public static Polygon loadModel( ExampleModels model, double scale ) throws FileNotFoundException, IOException { String line; ArrayList<Vector3> points = new ArrayList<Vector3>(); InputStream istream = PolygonLoader.class.getClassLoader().getResourceAsStream( model.getFilename() ); if( istream == null ) { throw new FileNotFoundException( "Couldn't find " + model ); } InputStreamReader ir = new InputStreamReader( istream ); BufferedReader reader = new BufferedReader( ir ); while( ( line = reader.readLine() ) != null ) { StringTokenizer tokens = new StringTokenizer( line, " ," ); points.add( new Vector3( Float.valueOf( tokens.nextToken() ).floatValue(), Float.valueOf( tokens.nextToken() ).floatValue(), 0f )); } if( points.isEmpty() ) { throw new IOException( "no data in file " + model ); } // Rescale models so they are centered at 0,0 and don't fall outside the // unit square double maxX, maxY, minX, minY; maxX = minX = points.get( 0 ).getX(); if( model.invertedYAxis() ) { maxY = minY = -points.get( 0 ).getY(); } else { maxY = minY = points.get( 0 ).getY(); } for( Vector3 p : points ) { if( model.invertedYAxis() ) { p.setY( -p.getY() ); } maxX = p.getX() > maxX ? p.getX() : maxX; maxY = p.getY() > maxY ? p.getY() : maxY; minX = p.getX() < minX ? p.getX() : minX; minY = p.getY() < minY ? p.getY() : minY; } double width, height, xScale, yScale; width = maxX - minX; height = maxY - minY; xScale = scale * 1f / width; yScale = scale * 1f / height; // System.out.println("scale/height=" + SCALE + "/" + height ); // System.out.println("scale=" + yScale); for( Vector3 p : points ) { if( model.invertedYAxis() ) { p.subtractLocal( maxX - width / 2, maxY - height / 2, 0 ); } else { p.subtractLocal( maxX - width / 2, maxY - height / 2, 0 ); } p.multiplyLocal( xScale < yScale ? xScale : yScale ); } return new ArdorPolygon( points); } public static void saveModel( String path, TriangulationPoint[] points ) { FileWriter writer = null; BufferedWriter w = null; String file = path+System.currentTimeMillis()+".dat"; try { writer = new FileWriter(file); w = new BufferedWriter(writer); for( TriangulationPoint p : points ) { w.write( Float.toString( p.getXf() ) +" "+ Float.toString( p.getYf() )); w.newLine(); } logger.info( "Saved polygon\n" + file ); } catch( IOException e ) { logger.error( "Failed to save model" ); } finally { if( w != null ) { try { w.close(); } catch( IOException e2 ) { } } } } /** * This is a very unoptimal dump of the triangles as absolute lines. * For manual importation to an SVG<br> * * @param path * @param ps */ // public static void saveTriLine( String path, PolygonSet ps ) // { // FileWriter writer = null; // BufferedWriter w = null; // String file = path+System.currentTimeMillis()+".tri"; // // if( ps.getTriangles() == null || ps.getTriangles().isEmpty() ) // { // return; // } // // try // { // // writer = new FileWriter(file); // w = new BufferedWriter(writer); // for( DelaunayTriangle t : ps.getTriangles() ) // { // for( int i=0; i<3; i++ ) // { // w.write( Float.toString( t.points[i].getXf() ) +","+ Float.toString( t.points[i].getYf() )+" "); // } //// w.newLine(); // } // logger.info( "Saved triangle lines\n" + file ); // } // catch( IOException e ) // { // logger.error( "Failed to save triangle lines" + e.getMessage() ); // } // finally // { // if( w != null ) // { // try // { // w.close(); // } // catch( IOException e2 ) // { // } // } // } // } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/misc/PolygonLoader.java
Java
bsd
5,967
package org.poly2tri.examples.ardor3d.misc; public enum ExampleSets { Example1 ("example1.dat",1,0,0,true), Example2 ("example2.dat",1,0,0,true), Example3 ("example3.dat",1,0,0,false), Example4 ("example4.dat",1,0,0,false); private final static String m_basePath = "org/poly2tri/examples/data/pointsets/"; private String m_filename; private double m_scale; private double m_x; private double m_y; private boolean _invertedYAxis; ExampleSets( String filename, double scale, double x, double y, boolean invertedY ) { m_filename = filename; m_scale = scale; m_x = x; m_y = y; _invertedYAxis = invertedY; } public String getFilename() { return m_basePath + m_filename; } public double getScale() { return m_scale; } public double getX() { return m_x; } public double getY() { return m_y; } public boolean invertedYAxis() { return _invertedYAxis; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/misc/ExampleSets.java
Java
bsd
1,143
package org.poly2tri.examples.ardor3d.misc; import org.poly2tri.triangulation.point.TPoint; public class MyPoint extends TPoint { int index; public MyPoint( double x, double y ) { super( x, y ); } public void setIndex(int i) { index = i; } public int getIndex() { return index; } public boolean equals(Object other) { if (!(other instanceof MyPoint)) return false; MyPoint p = (MyPoint)other; return getX() == p.getX() && getY() == p.getY(); } public int hashCode() { return (int)getX() + (int)getY(); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/misc/MyPoint.java
Java
bsd
667
package org.poly2tri.examples.ardor3d.misc; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.geometry.polygon.PolygonSet; import org.poly2tri.polygon.ardor3d.ArdorPolygon; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; import org.poly2tri.triangulation.point.TPoint; import org.poly2tri.triangulation.sets.PointSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ardor3d.math.Vector3; public class DataLoader { private final static Logger logger = LoggerFactory.getLogger( DataLoader.class ); public static Polygon loadModel( ExampleModels model, double scale ) throws FileNotFoundException, IOException { String line; ArrayList<Vector3> points = new ArrayList<Vector3>(); InputStream istream = DataLoader.class.getClassLoader().getResourceAsStream( model.getFilename() ); if( istream == null ) { throw new FileNotFoundException( "Couldn't find " + model ); } InputStreamReader ir = new InputStreamReader( istream ); BufferedReader reader = new BufferedReader( ir ); while( ( line = reader.readLine() ) != null ) { StringTokenizer tokens = new StringTokenizer( line, " ," ); points.add( new Vector3( Double.valueOf( tokens.nextToken() ).doubleValue(), Double.valueOf( tokens.nextToken() ).doubleValue(), 0f )); } if( points.isEmpty() ) { throw new IOException( "no data in file " + model ); } // Rescale models so they are centered at 0,0 and don't fall outside the // unit square double maxX, maxY, minX, minY; maxX = minX = points.get( 0 ).getX(); if( model.invertedYAxis() ) { maxY = minY = -points.get( 0 ).getY(); } else { maxY = minY = points.get( 0 ).getY(); } for( Vector3 p : points ) { if( model.invertedYAxis() ) { p.setY( -p.getY() ); } maxX = p.getX() > maxX ? p.getX() : maxX; maxY = p.getY() > maxY ? p.getY() : maxY; minX = p.getX() < minX ? p.getX() : minX; minY = p.getY() < minY ? p.getY() : minY; } double width, height, xScale, yScale; width = maxX - minX; height = maxY - minY; xScale = scale * 1f / width; yScale = scale * 1f / height; // System.out.println("scale/height=" + SCALE + "/" + height ); // System.out.println("scale=" + yScale); for( Vector3 p : points ) { if( model.invertedYAxis() ) { p.subtractLocal( maxX - width / 2, maxY - height / 2, 0 ); } else { p.subtractLocal( maxX - width / 2, maxY - height / 2, 0 ); } p.multiplyLocal( xScale < yScale ? xScale : yScale ); } return new ArdorPolygon( points); } public static PointSet loadPointSet( ExampleSets set, double scale ) throws FileNotFoundException, IOException { String line; ArrayList<TriangulationPoint> points = new ArrayList<TriangulationPoint>(); InputStream istream = DataLoader.class.getClassLoader().getResourceAsStream( set.getFilename() ); if( istream == null ) { throw new FileNotFoundException( "Couldn't find " + set ); } InputStreamReader ir = new InputStreamReader( istream ); BufferedReader reader = new BufferedReader( ir ); while( ( line = reader.readLine() ) != null ) { StringTokenizer tokens = new StringTokenizer( line, " ," ); points.add( new TPoint( scale*Float.valueOf( tokens.nextToken() ).floatValue(), scale*Float.valueOf( tokens.nextToken() ).floatValue() )); } if( points.isEmpty() ) { throw new IOException( "no data in file " + set ); } // Rescale models so they are centered at 0,0 and don't fall outside the // unit square // double maxX, maxY, minX, minY; // maxX = minX = points.get( 0 ).getX(); // if( set.invertedYAxis() ) // { // maxY = minY = -points.get( 0 ).getY(); // } // else // { // maxY = minY = points.get( 0 ).getY(); // } // for( TPoint p : points ) // { // if( set.invertedYAxis() ) // { // p.setY( -p.getY() ); // } // maxX = p.getX() > maxX ? p.getX() : maxX; // maxY = p.getY() > maxY ? p.getY() : maxY; // minX = p.getX() < minX ? p.getX() : minX; // minY = p.getY() < minY ? p.getY() : minY; // } // // double width, height, xScale, yScale; // width = maxX - minX; // height = maxY - minY; // xScale = scale * 1f / width; // yScale = scale * 1f / height; // // // System.out.println("scale/height=" + SCALE + "/" + height ); // // System.out.println("scale=" + yScale); // // for( TPoint p : points ) // { // if( set.invertedYAxis() ) // { // p.subtractLocal( maxX - width / 2, maxY - height / 2, 0 ); // } // else // { // p.subtractLocal( maxX - width / 2, maxY - height / 2, 0 ); // } // p.multiplyLocal( xScale < yScale ? xScale : yScale ); // } return new PointSet( points ); } public static void saveModel( String path, TriangulationPoint[] points ) { FileWriter writer = null; BufferedWriter w = null; String file = path+System.currentTimeMillis()+".dat"; try { writer = new FileWriter(file); w = new BufferedWriter(writer); for( TriangulationPoint p : points ) { w.write( Float.toString( p.getXf() ) +" "+ Float.toString( p.getYf() )); w.newLine(); } logger.info( "Saved polygon\n" + file ); } catch( IOException e ) { logger.error( "Failed to save model" ); } finally { if( w != null ) { try { w.close(); } catch( IOException e2 ) { } } } } /** * This is a very unoptimal dump of the triangles as absolute lines. * For manual importation to an SVG<br> * * @param path * @param ps */ public static void saveTriLine( String path, PolygonSet ps ) { FileWriter writer = null; BufferedWriter w = null; String file = path+System.currentTimeMillis()+".tri"; if( ps.getPolygons() == null || ps.getPolygons().isEmpty() ) { return; } try { writer = new FileWriter(file); w = new BufferedWriter(writer); for( DelaunayTriangle t : ps.getPolygons().get(0).getTriangles() ) { for( int i=0; i<3; i++ ) { w.write( Float.toString( t.points[i].getXf() ) +","+ Float.toString( t.points[i].getYf() )+" "); } // w.newLine(); } logger.info( "Saved triangle lines\n" + file ); } catch( IOException e ) { logger.error( "Failed to save triangle lines" + e.getMessage() ); } finally { if( w != null ) { try { w.close(); } catch( IOException e2 ) { } } } } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/misc/DataLoader.java
Java
bsd
8,703
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.examples.ardor3d; import java.io.IOException; import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.List; import org.poly2tri.examples.ardor3d.base.P2TExampleBase; import org.poly2tri.examples.ardor3d.misc.DataLoader; import org.poly2tri.examples.ardor3d.misc.ExampleModels; import org.poly2tri.examples.ardor3d.misc.Triangle; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.geometry.polygon.PolygonSet; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; import org.poly2tri.triangulation.delaunay.sweep.AdvancingFront; import org.poly2tri.triangulation.delaunay.sweep.AdvancingFrontNode; import org.poly2tri.triangulation.delaunay.sweep.DTSweepConstraint; import org.poly2tri.triangulation.delaunay.sweep.DTSweepContext; import org.poly2tri.triangulation.point.TPoint; import org.poly2tri.triangulation.sets.ConstrainedPointSet; import org.poly2tri.triangulation.sets.PointSet; import org.poly2tri.triangulation.util.PolygonGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.FrameHandler; import com.ardor3d.input.Key; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.KeyPressedCondition; import com.ardor3d.input.logical.LogicalLayer; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.math.ColorRGBA; import com.ardor3d.renderer.IndexMode; import com.ardor3d.renderer.state.WireframeState; import com.ardor3d.scenegraph.Line; import com.ardor3d.scenegraph.Point; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.geom.BufferUtils; import com.google.inject.Inject; /** * Toggle Model with PageUp and PageDown<br> * Toggle Wireframe with Home<br> * Toggle Vertex points with End<br> * Use 1 and 2 to generate random polygons<br> * * @author Thomas * */ public class CDTModelExample extends P2TExampleBase { private final static Logger logger = LoggerFactory.getLogger( CDTModelExample.class ); private ExampleModels m_currentModel = ExampleModels.Two; private static double SCALE = 50; private Line m_line; // Build parameters private int m_vertexCount = 10000; // Scene components private CDTSweepAdvancingFront _cdtSweepAdvancingFront; private CDTSweepActiveNode _cdtSweepActiveNode; private CDTSweepActiveTriangles _cdtSweepActiveTriangle; private CDTSweepActiveEdge _cdtSweepActiveEdge; // private GUICircumCircle m_circumCircle; private int m_stepCount = 0; private boolean m_autoStep = true; private final String m_dataPath = "src/main/resources/org/poly2tri/examples/data/"; public static void main(final String[] args) { start(CDTModelExample.class); } @Inject public CDTModelExample( LogicalLayer logicalLayer, FrameHandler frameHandler ) { super( logicalLayer, frameHandler ); } protected void updateExample(final ReadOnlyTimer timer) { super.updateExample( timer ); if( getContext().isDebugEnabled() ) { int count = _process.getStepCount(); if( m_stepCount < count ) { _process.requestRead(); if( _process.isReadable() ) { updateMesh(); m_stepCount = count; if( m_autoStep ) { _process.resume(); } } } } } @Override protected void initExample() { super.initExample(); // getContext().isDebugEnabled( true ); if( getContext().isDebugEnabled() ) { _cdtSweepAdvancingFront = new CDTSweepAdvancingFront(); _node.attachChild( _cdtSweepAdvancingFront.getSceneNode() ); _cdtSweepActiveNode = new CDTSweepActiveNode(); _node.attachChild( _cdtSweepActiveNode.getSceneNode() ); _cdtSweepActiveTriangle = new CDTSweepActiveTriangles(); _node.attachChild( _cdtSweepActiveTriangle.getSceneNode() ); _cdtSweepActiveEdge = new CDTSweepActiveEdge(); _node.attachChild( _cdtSweepActiveEdge.getSceneNode() ); // m_circumCircle = new GUICircumCircle(); // m_node.attachChild( m_circumCircle.getSceneNode() ); } buildModel(m_currentModel); triangulate(); } /** * Update text information. */ protected void updateText() { super.updateText(); _exampleInfo[3].setText("[PageUp] Next model"); _exampleInfo[4].setText("[PageDown] Previous model"); _exampleInfo[5].setText("[1] Generate polygon type A "); _exampleInfo[6].setText("[2] Generate polygon type B "); } private void buildModel( ExampleModels model ) { Polygon poly; if( model != null ) { try { poly = DataLoader.loadModel( model, SCALE ); _polygonSet = new PolygonSet( poly ); } catch( IOException e ) { logger.info( "Failed to load model {}", e.getMessage() ); model = null; } } if( model == null ) { _polygonSet = new PolygonSet( PolygonGenerator.RandomCircleSweep( SCALE, m_vertexCount ) ); } } private ConstrainedPointSet buildCustom() { ArrayList<TriangulationPoint> list = new ArrayList<TriangulationPoint>(20); int[] index; list.add( new TPoint(2.2715518,-4.5233157) ); list.add( new TPoint(3.4446202,-3.5232647) ); list.add( new TPoint(4.7215156,-4.5233157) ); list.add( new TPoint(6.0311967,-3.5232647) ); list.add( new TPoint(3.4446202,-7.2578132) ); list.add( new TPoint(.81390847,-3.5232647) ); index = new int[]{3,5}; return new ConstrainedPointSet( list, index ); } protected void triangulate() { super.triangulate(); m_stepCount = 0; } protected void updateMesh() { super.updateMesh(); DTSweepContext tcx = getContext(); if( tcx.isDebugEnabled() ) { _cdtSweepActiveTriangle.update( tcx ); _cdtSweepActiveEdge.update( tcx ); _cdtSweepActiveNode.update( tcx ); _cdtSweepAdvancingFront.update( tcx ); // m_circumCircle.update( tcx.getCircumCircle() ); } } @Override public void registerInputTriggers() { super.registerInputTriggers(); // SPACE - toggle models _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.PAGEUP_PRIOR ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { int index; index = (m_currentModel.ordinal()+1)%ExampleModels.values().length; m_currentModel = ExampleModels.values()[index]; buildModel(m_currentModel); _node.setScale( m_currentModel.getScale() ); triangulate(); } } ) ); // SPACE - toggle models backwards _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.PAGEDOWN_NEXT ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { int index; index = ((m_currentModel.ordinal()-1)%ExampleModels.values().length + ExampleModels.values().length)%ExampleModels.values().length; m_currentModel = ExampleModels.values()[index]; buildModel(m_currentModel); _node.setScale( m_currentModel.getScale() ); triangulate(); } } ) ); _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.ONE ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { _polygonSet = new PolygonSet( PolygonGenerator.RandomCircleSweep( SCALE, m_vertexCount ) ); triangulate(); } } ) ); _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.TWO ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { _polygonSet = new PolygonSet( PolygonGenerator.RandomCircleSweep2( SCALE, 200 ) ); triangulate(); } } ) ); // X -start _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.X ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { // Lets create a TriangulationProcess that allows you to step thru the TriangulationAlgorithm // _process.getContext().isDebugEnabled( true ); // _process.triangulate(); // m_stepCount = 0; } } ) ); // C - step _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.C ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { // updateMesh(); _process.resume(); } } ) ); // Z - toggle autostep _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.Z ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { m_autoStep = m_autoStep ? false : true; } } ) ); // space - save triangle lines _logicalLayer.registerTrigger( new InputTrigger( new KeyPressedCondition( Key.SPACE ), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { // PolygonLoader.saveTriLine( m_dataPath, _polygonSet ); m_stepCount = 0; _process.triangulate( buildCustom() ); } } ) ); } class CDTSweepAdvancingFront extends SceneElement<DTSweepContext> { protected Line m_nodeLines; protected Point m_frontPoints; protected Line m_frontLine; public CDTSweepAdvancingFront() { super("AdvancingFront"); m_frontLine = new Line(); m_frontLine.getMeshData().setIndexMode( IndexMode.LineStrip ); m_frontLine.getMeshData().setVertexBuffer( BufferUtils.createVector3Buffer( 800 ) ); m_frontLine.setDefaultColor( ColorRGBA.ORANGE ); m_frontLine.setTranslation( 0, 0.05, 0 ); _node.attachChild( m_frontLine ); m_frontPoints = new Point(); m_frontPoints.getMeshData().setVertexBuffer( m_frontLine.getMeshData().getVertexBuffer() ); m_frontPoints.setPointSize( 6 ); m_frontPoints.setDefaultColor( ColorRGBA.ORANGE ); m_frontPoints.setTranslation( 0, 0.05, 0 ); _node.attachChild( m_frontPoints ); m_nodeLines = new Line(); m_nodeLines.getMeshData().setIndexMode( IndexMode.Lines ); m_nodeLines.getMeshData().setVertexBuffer( BufferUtils.createVector3Buffer( 2*800 ) ); m_nodeLines.setDefaultColor( ColorRGBA.YELLOW ); m_nodeLines.setTranslation( 0, 0.05, 0 ); _node.attachChild( m_nodeLines ); } @Override public void update( DTSweepContext tcx ) { AdvancingFront front = ((DTSweepContext)tcx).getAdvancingFront(); AdvancingFrontNode node; DelaunayTriangle tri; if( front == null ) return; FloatBuffer fb = m_frontLine.getMeshData().getVertexBuffer(); FloatBuffer nodeVert = m_nodeLines.getMeshData().getVertexBuffer(); fb.limit( fb.capacity() ); nodeVert.limit( fb.capacity() ); fb.rewind(); nodeVert.rewind(); int count=0; node = front.head; TriangulationPoint point; do { point = node.getPoint(); fb.put( point.getXf() ).put( point.getYf() ).put( point.getZf() ); tri = node.getTriangle(); if( tri != null ) { nodeVert.put( point.getXf() ).put( point.getYf() ).put( point.getZf() ); nodeVert.put( ( tri.points[0].getXf() + tri.points[1].getXf() + tri.points[2].getXf() )/3 ); nodeVert.put( ( tri.points[0].getYf() + tri.points[1].getYf() + tri.points[2].getYf() )/3 ); nodeVert.put( ( tri.points[0].getZf() + tri.points[1].getZf() + tri.points[2].getZf() )/3 ); } count++; } while( (node = node.getNext()) != null ); fb.limit( 3*count ); nodeVert.limit( 2*count*3 ); } } // class GUICircumCircle extends SceneElement<Tuple2<TriangulationPoint,Double>> // { // private int VCNT = 64; // private Line m_circle = new Line(); // // public GUICircumCircle() // { // super("CircumCircle"); // m_circle.getMeshData().setIndexMode( IndexMode.LineLoop ); // m_circle.getMeshData().setVertexBuffer( BufferUtils.createVector3Buffer( VCNT ) ); // m_circle.setDefaultColor( ColorRGBA.WHITE ); // m_circle.setLineWidth( 1 ); // m_node.attachChild( m_circle ); // } // // @Override // public void update( Tuple2<TriangulationPoint,Double> circle ) // { // float x,y; // if( circle.a != null ) // { // FloatBuffer fb = m_circle.getMeshData().getVertexBuffer(); // fb.rewind(); // for( int i=0; i < VCNT; i++ ) // { // x = (float)circle.a.getX() + (float)(circle.b*Math.cos( 2*Math.PI*((double)i%VCNT)/VCNT )); // y = (float)circle.a.getY() + (float)(circle.b*Math.sin( 2*Math.PI*((double)i%VCNT)/VCNT )); // fb.put( x ).put( y ).put( 0 ); // } // } // else // { // m_node.detachAllChildren(); // } // } // } class CDTSweepMeshExtended extends CDTSweepMesh { // private Line m_conLine = new Line(); public CDTSweepMeshExtended() { super(); // Line that show the connection between triangles // m_conLine.setDefaultColor( ColorRGBA.RED ); // m_conLine.getMeshData().setIndexMode( IndexMode.Lines ); // m_node.attachChild( m_conLine ); // // vertBuf = BufferUtils.createFloatBuffer( size*3*3*3 ); // m_conLine.getMeshData().setVertexBuffer( vertBuf ); } @Override public void update( List<DelaunayTriangle> triangles ) { super.update( triangles ); // MeshData md; // Vector3 v1 = Vector3.fetchTempInstance(); // Vector3 v2 = Vector3.fetchTempInstance(); // FloatBuffer v2Buf; // // // md = m_mesh.getMeshData(); // v2Buf = m_conLine.getMeshData().getVertexBuffer(); // //// logger.info( "Triangle count [{}]", tcx.getMap().size() ); // // int size = 2*3*3*ps.getTriangles().size(); // if( v2Buf.capacity() < size ) // { // v2Buf = BufferUtils.createFloatBuffer( size ); // m_conLine.getMeshData().setVertexBuffer( v2Buf ); // } // else // { // v2Buf.limit( 2*size ); // } // // v2Buf.rewind(); // int lineCount=0; // ArdorVector3Point p; // for( DelaunayTriangle t : ps.getTriangles() ) // { // v1.set( t.points[0] ).addLocal( t.points[1] ).addLocal( t.points[2] ).multiplyLocal( 1.0d/3 ); // if( t.neighbors[0] != null ) // { // v2.set( t.points[2] ).subtractLocal( t.points[1] ).multiplyLocal( 0.5 ).addLocal( t.points[1] ); // v2Buf.put( v1.getXf() ).put( v1.getYf() ).put( v1.getZf() ); // v2Buf.put( v2.getXf() ).put( v2.getYf() ).put( v2.getZf() ); // lineCount++; // } // if( t.neighbors[1] != null ) // { // v2.set( t.points[0] ).subtractLocal( t.points[2] ).multiplyLocal( 0.5 ).addLocal( t.points[2] ); // v2Buf.put( v1.getXf() ).put( v1.getYf() ).put( v1.getZf() ); // v2Buf.put( v2.getXf() ).put( v2.getYf() ).put( v2.getZf() ); // lineCount++; // } // if( t.neighbors[2] != null ) // { // v2.set( t.points[1] ).subtractLocal( t.points[0] ).multiplyLocal( 0.5 ).addLocal( t.points[0] ); // v2Buf.put( v1.getXf() ).put( v1.getYf() ).put( v1.getZf() ); // v2Buf.put( v2.getXf() ).put( v2.getYf() ).put( v2.getZf() ); // lineCount++; // } // } // v2Buf.limit( 2*3*lineCount ); // Vector3.releaseTempInstance( v1 ); // Vector3.releaseTempInstance( v2 ); } } class CDTSweepActiveEdge extends SceneElement<DTSweepContext> { private Line m_edgeLine = new Line(); public CDTSweepActiveEdge() { super("ActiveEdge"); m_edgeLine.getMeshData().setIndexMode( IndexMode.Lines ); m_edgeLine.getMeshData().setVertexBuffer( BufferUtils.createVector3Buffer( 2 ) ); m_edgeLine.setDefaultColor( ColorRGBA.YELLOW ); m_edgeLine.setLineWidth( 3 ); } @Override public void update( DTSweepContext tcx ) { DTSweepConstraint edge = tcx.getDebugContext().getActiveConstraint(); if( edge != null ) { FloatBuffer fb = m_edgeLine.getMeshData().getVertexBuffer(); fb.rewind(); fb.put( edge.getP().getXf() ).put( edge.getP().getYf() ).put( 0 ); fb.put( edge.getQ().getXf() ).put( edge.getQ().getYf() ).put( 0 ); _node.attachChild( m_edgeLine ); } else { _node.detachAllChildren(); } } } class CDTSweepActiveTriangles extends SceneElement<DTSweepContext> { private Triangle m_a = new Triangle(); private Triangle m_b = new Triangle(); public CDTSweepActiveTriangles() { super("ActiveTriangles"); _node.getSceneHints().setAllPickingHints( false ); m_a.setDefaultColor( new ColorRGBA( 0.8f,0.8f,0.8f,1.0f ) ); m_b.setDefaultColor( new ColorRGBA( 0.5f,0.5f,0.5f,1.0f ) ); } public void setScale( double scale ) { m_a.setScale( scale ); m_b.setScale( scale ); } @Override public void update( DTSweepContext tcx ) { DelaunayTriangle t,t2; t = tcx.getDebugContext().getPrimaryTriangle(); t2 = tcx.getDebugContext().getSecondaryTriangle(); _node.detachAllChildren(); if( t != null ) { FloatBuffer fb = m_a.getMeshData().getVertexBuffer(); fb.rewind(); fb.put( t.points[0].getXf() ).put( t.points[0].getYf() ).put( t.points[0].getZf() ); fb.put( t.points[1].getXf() ).put( t.points[1].getYf() ).put( t.points[1].getZf() ); fb.put( t.points[2].getXf() ).put( t.points[2].getYf() ).put( t.points[2].getZf() ); _node.attachChild( m_a ); } if( t2 != null ) { FloatBuffer fb = m_b.getMeshData().getVertexBuffer(); fb.rewind(); fb.put( t2.points[0].getXf() ).put( t2.points[0].getYf() ).put( t2.points[0].getZf() ); fb.put( t2.points[1].getXf() ).put( t2.points[1].getYf() ).put( t2.points[1].getZf() ); fb.put( t2.points[2].getXf() ).put( t2.points[2].getYf() ).put( t2.points[2].getZf() ); _node.attachChild( m_b ); } } } class CDTSweepActiveNode extends SceneElement<DTSweepContext> { private Triangle m_a = new Triangle(); private Triangle m_b = new Triangle(); private Triangle m_c = new Triangle(); public CDTSweepActiveNode() { super("WorkingNode"); _node.setRenderState( new WireframeState() ); m_a.setDefaultColor( ColorRGBA.DARK_GRAY ); m_b.setDefaultColor( ColorRGBA.LIGHT_GRAY ); m_c.setDefaultColor( ColorRGBA.DARK_GRAY ); setScale( 0.5 ); } public void setScale( double scale ) { m_a.setScale( scale ); m_b.setScale( scale ); m_c.setScale( scale ); } @Override public void update( DTSweepContext tcx ) { AdvancingFrontNode node = tcx.getDebugContext().getActiveNode(); TriangulationPoint p; if( node != null ) { if( node.getPrevious() != null ) { p = node.getPrevious().getPoint(); m_a.setTranslation( p.getXf(), p.getYf(), p.getZf() ); } p = node.getPoint(); m_b.setTranslation( p.getXf(), p.getYf(), p.getZf() ); if( node.getNext() != null ) { p = node.getNext().getPoint(); m_c.setTranslation( p.getXf(), p.getYf(), p.getZf() ); } _node.attachChild( m_a ); _node.attachChild( m_b ); _node.attachChild( m_c ); } else { _node.detachAllChildren(); } } } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/CDTModelExample.java
Java
bsd
25,670
package org.poly2tri.examples.ardor3d; import java.io.IOException; import java.util.ArrayList; import org.poly2tri.Poly2Tri; import org.poly2tri.examples.ardor3d.base.P2TSimpleExampleBase; import org.poly2tri.examples.ardor3d.misc.DataLoader; import org.poly2tri.examples.ardor3d.misc.ExampleSets; import org.poly2tri.triangulation.TriangulationAlgorithm; import org.poly2tri.triangulation.TriangulationContext; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.point.TPoint; import org.poly2tri.triangulation.sets.PointSet; import org.poly2tri.triangulation.tools.ardor3d.ArdorMeshMapper; import org.poly2tri.triangulation.util.PointGenerator; import com.ardor3d.framework.FrameHandler; import com.ardor3d.input.logical.LogicalLayer; import com.ardor3d.math.ColorRGBA; import com.ardor3d.renderer.state.WireframeState; import com.ardor3d.scenegraph.Mesh; import com.google.inject.Inject; public class DTUniformDistributionExample extends P2TSimpleExampleBase { public static void main(final String[] args) { start(DTUniformDistributionExample.class); } @Inject public DTUniformDistributionExample( LogicalLayer logicalLayer, FrameHandler frameHandler ) { super( logicalLayer, frameHandler ); } @Override protected void initExample() { super.initExample(); PointSet ps; Mesh mesh; mesh = new Mesh(); mesh.setDefaultColor( ColorRGBA.BLUE ); mesh.setRenderState( new WireframeState() ); _node.attachChild( mesh ); try { ps = DataLoader.loadPointSet( ExampleSets.Example2, 0.1 ); ps = new PointSet( PointGenerator.uniformDistribution( 10000, 60 ) ); Poly2Tri.triangulate( ps ); ArdorMeshMapper.updateTriangleMesh( mesh, ps ); } catch( IOException e ) {} } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/DTUniformDistributionExample.java
Java
bsd
1,990
package org.poly2tri.examples.ardor3d; import java.util.List; import org.poly2tri.Poly2Tri; import org.poly2tri.examples.ardor3d.base.P2TSimpleExampleBase; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.point.TPoint; import org.poly2tri.triangulation.sets.ConstrainedPointSet; import org.poly2tri.triangulation.tools.ardor3d.ArdorMeshMapper; import org.poly2tri.triangulation.util.PointGenerator; import com.ardor3d.framework.FrameHandler; import com.ardor3d.input.logical.LogicalLayer; import com.ardor3d.math.ColorRGBA; import com.ardor3d.scenegraph.Mesh; import com.google.inject.Inject; public class CDTUniformDistributionExample extends P2TSimpleExampleBase { public static void main(final String[] args) { start(CDTUniformDistributionExample.class); } @Inject public CDTUniformDistributionExample( LogicalLayer logicalLayer, FrameHandler frameHandler ) { super( logicalLayer, frameHandler ); } @Override protected void initExample() { super.initExample(); Mesh mesh = new Mesh(); mesh.setDefaultColor( ColorRGBA.BLUE ); _node.attachChild( mesh ); double scale = 100; int size = 1000; int index = (int)(Math.random()*size); List<TriangulationPoint> points = PointGenerator.uniformDistribution( size, scale ); // Lets add a constraint that cuts the uniformDistribution in half points.add( new TPoint(0,scale/2) ); points.add( new TPoint(0,-scale/2) ); index = size; ConstrainedPointSet cps = new ConstrainedPointSet( points, new int[]{ index, index+1 } ); Poly2Tri.triangulate( cps ); ArdorMeshMapper.updateTriangleMesh( mesh, cps ); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/CDTUniformDistributionExample.java
Java
bsd
1,849
package org.poly2tri.examples.ardor3d; import java.util.ArrayList; import org.poly2tri.Poly2Tri; import org.poly2tri.examples.ardor3d.base.P2TSimpleExampleBase; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.geometry.polygon.PolygonPoint; import org.poly2tri.triangulation.point.TPoint; import org.poly2tri.triangulation.tools.ardor3d.ArdorMeshMapper; import org.poly2tri.triangulation.util.PolygonGenerator; import com.ardor3d.framework.FrameHandler; import com.ardor3d.input.logical.LogicalLayer; import com.ardor3d.math.ColorRGBA; import com.ardor3d.renderer.state.WireframeState; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.Node; import com.google.inject.Inject; public class CDTSteinerPointExample extends P2TSimpleExampleBase { public static void main(final String[] args) { start(CDTSteinerPointExample.class); } @Inject public CDTSteinerPointExample( LogicalLayer logicalLayer, FrameHandler frameHandler ) { super( logicalLayer, frameHandler ); } @Override protected void initExample() { super.initExample(); Node node = new Node(); node.setRenderState( new WireframeState() ); _node.attachChild( node ); Polygon poly; poly = createCirclePolygon( 32, 1.5 ); // top left Mesh mesh = new Mesh(); mesh.setDefaultColor( ColorRGBA.BLUE ); mesh.setTranslation( -2, 2, 0 ); node.attachChild( mesh ); Poly2Tri.triangulate( poly ); ArdorMeshMapper.updateTriangleMesh( mesh, poly ); // bottom left mesh = new Mesh(); mesh.setDefaultColor( ColorRGBA.RED ); mesh.setTranslation( -2, -2, 0 ); node.attachChild( mesh ); poly.addSteinerPoint( new TPoint(0,0) ); Poly2Tri.triangulate( poly ); ArdorMeshMapper.updateTriangleMesh( mesh, poly ); poly = PolygonGenerator.RandomCircleSweep2( 4, 200 ); // top right mesh = new Mesh(); mesh.setDefaultColor( ColorRGBA.BLUE ); mesh.setTranslation( 2, 2, 0 ); node.attachChild( mesh ); Poly2Tri.triangulate( poly ); ArdorMeshMapper.updateTriangleMesh( mesh, poly ); // bottom right mesh = new Mesh(); mesh.setDefaultColor( ColorRGBA.RED ); mesh.setTranslation( 2, -2, 0 ); node.attachChild( mesh ); poly.addSteinerPoint( new TPoint(0,0) ); Poly2Tri.triangulate( poly ); ArdorMeshMapper.updateTriangleMesh( mesh, poly ); } private Polygon createCirclePolygon( int n, double radius ) { if( n < 3 ) n=3; PolygonPoint[] points = new PolygonPoint[n]; for( int i=0; i<n; i++ ) { points[i] = new PolygonPoint( radius*Math.cos( (2.0*Math.PI*i)/n ), radius*Math.sin( (2.0*Math.PI*i)/n ) ); } return new Polygon( points ); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ardor3d/CDTSteinerPointExample.java
Java
bsd
3,120
package org.poly2tri.examples; import org.poly2tri.Poly2Tri; import org.poly2tri.triangulation.sets.PointSet; import org.poly2tri.triangulation.util.PointGenerator; public class ProfilingExample { public static void main(final String[] args) throws Exception { PointSet ps = new PointSet( PointGenerator.uniformDistribution( 50, 500000 ) ); for( int i=0; i<1; i++ ) { Poly2Tri.triangulate( ps ); } Thread.sleep( 10000000 ); } public void startProfiling() throws Exception { } }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples/src/main/java/org/poly2tri/examples/ProfilingExample.java
Java
bsd
620
package org.poly2tri.examples.geotools; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import org.geotools.data.FeatureSource; import org.geotools.data.shapefile.ShapefileDataStore; import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureIterator; import org.opengis.feature.Feature; import org.opengis.feature.GeometryAttribute; import org.poly2tri.Poly2Tri; import org.poly2tri.examples.ardor3d.base.P2TSimpleExampleBase; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.geometry.polygon.PolygonPoint; import org.poly2tri.geometry.polygon.PolygonSet; import org.poly2tri.transform.coordinate.CoordinateTransform; import org.poly2tri.triangulation.tools.ardor3d.ArdorMeshMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ardor3d.example.ExampleBase; import com.ardor3d.framework.Canvas; import com.ardor3d.framework.FrameHandler; import com.ardor3d.image.Image; import com.ardor3d.image.Texture; import com.ardor3d.image.Texture.WrapMode; import com.ardor3d.input.MouseButton; import com.ardor3d.input.logical.InputTrigger; import com.ardor3d.input.logical.LogicalLayer; import com.ardor3d.input.logical.MouseButtonClickedCondition; import com.ardor3d.input.logical.TriggerAction; import com.ardor3d.input.logical.TwoInputStates; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.MathUtils; import com.ardor3d.math.Matrix3; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.BlendState; import com.ardor3d.renderer.state.MaterialState; import com.ardor3d.renderer.state.WireframeState; import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.renderer.state.BlendState.BlendEquation; import com.ardor3d.scenegraph.FloatBufferData; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.extension.Skybox; import com.ardor3d.scenegraph.extension.Skybox.Face; import com.ardor3d.scenegraph.hint.LightCombineMode; import com.ardor3d.scenegraph.shape.Sphere; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.TextureManager; import com.ardor3d.util.resource.ResourceLocatorTool; import com.ardor3d.util.resource.SimpleResourceLocator; import com.google.inject.Inject; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.LinearRing; import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.MultiPolygon; /** * Hello world! * */ public class WorldExample extends P2TSimpleExampleBase { private final static Logger logger = LoggerFactory.getLogger( WorldExample.class ); private final static CoordinateTransform _wgs84 = new WGS84GeodeticTransform(100); private Node _worldNode; private Skybox _skybox; private final Matrix3 rotate = new Matrix3(); private double angle = 0; private boolean _doRotate = true; /** * We use one PolygonSet for each country since countries can have islands * and be composed of multiple polygons */ private ArrayList<PolygonSet> _countries = new ArrayList<PolygonSet>(); @Inject public WorldExample( LogicalLayer logicalLayer, FrameHandler frameHandler ) { super( logicalLayer, frameHandler ); } public static void main( String[] args ) throws Exception { try { start(WorldExample.class); } catch( RuntimeException e ) { logger.error( "WorldExample failed due to a runtime exception" ); } } @Override protected void updateExample( ReadOnlyTimer timer ) { if( _doRotate ) { angle += timer.getTimePerFrame() * 10; angle %= 360; rotate.fromAngleNormalAxis(angle * MathUtils.DEG_TO_RAD, Vector3.UNIT_Z); _worldNode.setRotation(rotate); } } @Override protected void initExample() { super.initExample(); try { importShape(100); } catch( IOException e ) { } _canvas.getCanvasRenderer().getCamera().setLocation(200, 200, 200); _canvas.getCanvasRenderer().getCamera().lookAt( 0, 0, 0, Vector3.UNIT_Z ); _worldNode = new Node("shape"); // _worldNode.setRenderState( new WireframeState() ); _node.attachChild( _worldNode ); buildSkyBox(); Sphere seas = new Sphere("seas", Vector3.ZERO, 64, 64, 100.2f); seas.setDefaultColor( new ColorRGBA(0,0,0.5f,0.25f) ); seas.getSceneHints().setRenderBucketType( RenderBucketType.Transparent ); BlendState bs = new BlendState(); bs.setBlendEnabled( true ); bs.setEnabled( true ); bs.setBlendEquationAlpha( BlendEquation.Max ); bs.setSourceFunction(BlendState.SourceFunction.SourceAlpha); bs.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha); seas.setRenderState( bs ); ZBufferState zb = new ZBufferState(); zb.setEnabled( true ); zb.setWritable( false ); seas.setRenderState( zb ); _worldNode.attachChild( seas ); Sphere core = new Sphere("seas", Vector3.ZERO, 16, 16, 10f); core.getSceneHints().setLightCombineMode( LightCombineMode.Replace ); MaterialState ms = new MaterialState(); ms.setEmissive( new ColorRGBA(0.8f,0.2f,0,0.9f) ); core.setRenderState( ms ); _worldNode.attachChild( core ); Mesh mesh; for( PolygonSet ps : _countries ) { Poly2Tri.triangulate( ps ); float value = 1-0.9f*(float)Math.random(); for( Polygon p : ps.getPolygons() ) { mesh = new Mesh(); mesh.setDefaultColor( new ColorRGBA( value, value, value, 1.0f ) ); _worldNode.attachChild( mesh ); ArdorMeshMapper.updateTriangleMesh( mesh, p, _wgs84 ); } } } protected void importShape( double rescale ) throws IOException { // URL url = WorldExample.class.getResource( "/z5UKI.shp" ); URL url = WorldExample.class.getResource( "/earth/countries.shp" ); url.getFile(); ShapefileDataStore ds = new ShapefileDataStore(url); FeatureSource featureSource = ds.getFeatureSource(); // for( int i=0; i < ds.getTypeNames().length; i++) // { // System.out.println("ShapefileDataStore.typename=" + ds.getTypeNames()[i] ); // } FeatureCollection fc = featureSource.getFeatures(); // System.out.println( "featureCollection.ID=" + fc.getID() ); // System.out.println( "featureCollection.schema=" + fc.getSchema() ); // System.out.println( "featureCollection.Bounds[minX,maxX,minY,maxY]=[" // + fc.getBounds().getMinX() + "," + // + fc.getBounds().getMaxX() + "," + // + fc.getBounds().getMinY() + "," + // + fc.getBounds().getMaxY() + "]" ); // double width, height, xScale, yScale, scale, dX, dY; // width = fc.getBounds().getMaxX() - fc.getBounds().getMinX(); // height = fc.getBounds().getMaxY() - fc.getBounds().getMinY(); // dX = fc.getBounds().getMinX() + width/2; // dY = fc.getBounds().getMinY() + height/2; // xScale = rescale * 1f / width; // yScale = rescale * 1f / height; // scale = xScale < yScale ? xScale : yScale; FeatureIterator fi; Feature f; GeometryAttribute geoAttrib; Polygon polygon; PolygonSet polygonSet; fi = fc.features(); while( fi.hasNext() ) { polygonSet = new PolygonSet(); f = fi.next(); geoAttrib = f.getDefaultGeometryProperty(); // System.out.println( "Feature.Identifier:" + f.getIdentifier() ); // System.out.println( "Feature.Name:" + f.getName() ); // System.out.println( "Feature.Type:" + f.getType() ); // System.out.println( "Feature.Descriptor:" + geoAttrib.getDescriptor() ); // System.out.println( "GeoAttrib.Identifier=" + geoAttrib.getIdentifier() ); // System.out.println( "GeoAttrib.Name=" + geoAttrib.getName() ); // System.out.println( "GeoAttrib.Type.Name=" + geoAttrib.getType().getName() ); // System.out.println( "GeoAttrib.Type.Binding=" + geoAttrib.getType().getBinding() ); // System.out.println( "GeoAttrib.Value=" + geoAttrib.getValue() ); if( geoAttrib.getType().getBinding() == MultiLineString.class ) { MultiLineString mls = (MultiLineString)geoAttrib.getValue(); Coordinate[] coords = mls.getCoordinates(); // System.out.println( "MultiLineString.coordinates=" + coords.length ); ArrayList<PolygonPoint> points = new ArrayList<PolygonPoint>(coords.length); for( int i=0; i<coords.length; i++) { points.add( new PolygonPoint(coords[i].x,coords[i].y) ); // System.out.println( "[x,y]=[" + coords[i].x + "," + coords[i].y + "]" ); } polygonSet.add( new Polygon(points) ); } else if( geoAttrib.getType().getBinding() == MultiPolygon.class ) { MultiPolygon mp = (MultiPolygon)geoAttrib.getValue(); // System.out.println( "MultiPolygon.NumGeometries=" + mp.getNumGeometries() ); for( int i=0; i<mp.getNumGeometries(); i++ ) { com.vividsolutions.jts.geom.Polygon jtsPolygon = (com.vividsolutions.jts.geom.Polygon)mp.getGeometryN(i); polygon = buildPolygon( jtsPolygon ); polygonSet.add( polygon ); } } _countries.add( polygonSet ); } } private static Polygon buildPolygon( com.vividsolutions.jts.geom.Polygon jtsPolygon ) { Polygon polygon; LinearRing shell; ArrayList<PolygonPoint> points; // Envelope envelope; // System.out.println( "MultiPolygon.points=" + jtsPolygon.getNumPoints() ); // System.out.println( "MultiPolygon.NumInteriorRing=" + jtsPolygon.getNumInteriorRing() ); // envelope = jtsPolygon.getEnvelopeInternal(); shell = (LinearRing)jtsPolygon.getExteriorRing(); Coordinate[] coords = shell.getCoordinates(); points = new ArrayList<PolygonPoint>(coords.length); // Skipping last coordinate since JTD defines a shell as a LineString that start with // same first and last coordinate for( int j=0; j<coords.length-1; j++) { points.add( new PolygonPoint(coords[j].x,coords[j].y) ); } polygon = new Polygon(points); return polygon; } // // private void refinePolygon() // { // // } /** * Builds the sky box. */ private void buildSkyBox() { _skybox = new Skybox("skybox", 300, 300, 300); try { SimpleResourceLocator sr2 = new SimpleResourceLocator(ExampleBase.class.getClassLoader().getResource("org/poly2tri/examples/geotools/textures/")); ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, sr2); } catch (final URISyntaxException ex) { ex.printStackTrace(); } final String dir = ""; final Texture stars = TextureManager.load(dir + "stars.gif", Texture.MinificationFilter.Trilinear, Image.Format.GuessNoCompression, true); _skybox.setTexture(Skybox.Face.North, stars); _skybox.setTexture(Skybox.Face.West, stars); _skybox.setTexture(Skybox.Face.South, stars); _skybox.setTexture(Skybox.Face.East, stars); _skybox.setTexture(Skybox.Face.Up, stars); _skybox.setTexture(Skybox.Face.Down, stars); _skybox.getTexture( Skybox.Face.North ).setWrap( WrapMode.Repeat ); for( Face f : Face.values() ) { FloatBufferData fbd = _skybox.getFace(f).getMeshData().getTextureCoords().get( 0 ); fbd.getBuffer().clear(); fbd.getBuffer().put( 0 ).put( 4 ); fbd.getBuffer().put( 0 ).put( 0 ); fbd.getBuffer().put( 4 ).put( 0 ); fbd.getBuffer().put( 4 ).put( 4 ); } _node.attachChild( _skybox ); } @Override public void registerInputTriggers() { super.registerInputTriggers(); // SPACE - toggle models _logicalLayer.registerTrigger( new InputTrigger( new MouseButtonClickedCondition(MouseButton.RIGHT), new TriggerAction() { public void perform( final Canvas canvas, final TwoInputStates inputState, final double tpf ) { _doRotate = _doRotate ? false : true; } } ) ); } /* * http://en.wikipedia.org/wiki/Longitude#Degree_length * http://www.colorado.edu/geography/gcraft/notes/datum/gif/llhxyz.gif * * x (in m) = Latitude * 60 * 1852 * y (in m) = (PI/180) * cos(Longitude) * (637813.7^2 / sqrt( (637813.7 * cos(Longitude))^2 + (635675.23 * sin(Longitude))^2 ) ) * z (in m) = Altitude * * The 'quick and dirty' method (assuming the Earth is a perfect sphere): * * x = longitude*60*1852*cos(latitude) * y = latitude*60*1852 * * Latitude and longitude must be in decimal degrees, x and y are in meters. * The origin of the xy-grid is the intersection of the 0-degree meridian * and the equator, where x is positive East and y is positive North. * * So, why the 1852? I'm using the (original) definition of a nautical mile * here: 1 nautical mile = the length of one arcminute on the equator (hence * the 60*1852; I'm converting the lat/lon degrees to lat/lon minutes). */ }
11025063-johndoe-betterperformance-pizibing
poly2tri-examples-geotools/src/main/java/org/poly2tri/examples/geotools/WorldExample.java
Java
bsd
14,409
package org.poly2tri.geometry.primitives; public abstract class Point { public abstract double getX(); public abstract double getY(); public abstract double getZ(); public abstract float getXf(); public abstract float getYf(); public abstract float getZf(); public abstract void set( double x, double y, double z ); protected static int calculateHashCode( double x, double y, double z) { int result = 17; final long a = Double.doubleToLongBits(x); result += 31 * result + (int) (a ^ (a >>> 32)); final long b = Double.doubleToLongBits(y); result += 31 * result + (int) (b ^ (b >>> 32)); final long c = Double.doubleToLongBits(z); result += 31 * result + (int) (c ^ (c >>> 32)); return result; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/geometry/primitives/Point.java
Java
bsd
853
package org.poly2tri.geometry.primitives; public abstract class Edge<A extends Point> { protected A p; protected A q; public A getP() { return p; } public A getQ() { return q; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/geometry/primitives/Edge.java
Java
bsd
248
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.geometry.polygon; import java.util.ArrayList; import java.util.List; public class PolygonSet { protected ArrayList<Polygon> _polygons = new ArrayList<Polygon>(); public PolygonSet() { } public PolygonSet( Polygon poly ) { _polygons.add( poly ); } public void add( Polygon p ) { _polygons.add( p ); } public List<Polygon> getPolygons() { return _polygons; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/geometry/polygon/PolygonSet.java
Java
bsd
2,149
package org.poly2tri.geometry.polygon; import org.poly2tri.triangulation.point.TPoint; public class PolygonPoint extends TPoint { protected PolygonPoint _next; protected PolygonPoint _previous; public PolygonPoint( double x, double y ) { super( x, y ); } public PolygonPoint( double x, double y, double z ) { super( x, y, z ); } public void setPrevious( PolygonPoint p ) { _previous = p; } public void setNext( PolygonPoint p ) { _next = p; } public PolygonPoint getNext() { return _next; } public PolygonPoint getPrevious() { return _previous; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/geometry/polygon/PolygonPoint.java
Java
bsd
728
package org.poly2tri.geometry.polygon; public class PolygonUtil { /** * TODO * @param polygon */ public static void validate( Polygon polygon ) { // TODO: implement // 1. Check for duplicate points // 2. Check for intersecting sides } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/geometry/polygon/PolygonUtil.java
Java
bsd
308
package org.poly2tri.geometry.polygon; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.poly2tri.triangulation.Triangulatable; import org.poly2tri.triangulation.TriangulationContext; import org.poly2tri.triangulation.TriangulationMode; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Polygon implements Triangulatable { private final static Logger logger = LoggerFactory.getLogger( Polygon.class ); protected ArrayList<TriangulationPoint> _points = new ArrayList<TriangulationPoint>(); protected ArrayList<TriangulationPoint> _steinerPoints; protected ArrayList<Polygon> _holes; protected List<DelaunayTriangle> m_triangles; protected PolygonPoint _last; /** * To create a polygon we need atleast 3 separate points * * @param p1 * @param p2 * @param p3 */ public Polygon( PolygonPoint p1, PolygonPoint p2, PolygonPoint p3 ) { p1._next = p2; p2._next = p3; p3._next = p1; p1._previous = p3; p2._previous = p1; p3._previous = p2; _points.add( p1 ); _points.add( p2 ); _points.add( p3 ); } /** * Requires atleast 3 points * @param points - ordered list of points forming the polygon. * No duplicates are allowed */ public Polygon( List<PolygonPoint> points ) { // Lets do one sanity check that first and last point hasn't got same position // Its something that often happen when importing polygon data from other formats if( points.get(0).equals( points.get(points.size()-1) ) ) { logger.warn( "Removed duplicate point"); points.remove( points.size()-1 ); } _points.addAll( points ); } /** * Requires atleast 3 points * * @param points */ public Polygon( PolygonPoint[] points ) { this( Arrays.asList( points ) ); } public TriangulationMode getTriangulationMode() { return TriangulationMode.POLYGON; } public int pointCount() { int count = _points.size(); if( _steinerPoints != null ) { count += _steinerPoints.size(); } return count; } public void addSteinerPoint( TriangulationPoint point ) { if( _steinerPoints == null ) { _steinerPoints = new ArrayList<TriangulationPoint>(); } _steinerPoints.add( point ); } public void addSteinerPoints( List<TriangulationPoint> points ) { if( _steinerPoints == null ) { _steinerPoints = new ArrayList<TriangulationPoint>(); } _steinerPoints.addAll( points ); } public void clearSteinerPoints() { if( _steinerPoints != null ) { _steinerPoints.clear(); } } /** * Assumes: that given polygon is fully inside the current polygon * @param poly - a subtraction polygon */ public void addHole( Polygon poly ) { if( _holes == null ) { _holes = new ArrayList<Polygon>(); } _holes.add( poly ); // XXX: tests could be made here to be sure it is fully inside // addSubtraction( poly.getPoints() ); } /** * Will insert a point in the polygon after given point * * @param a * @param b * @param p */ public void insertPointAfter( PolygonPoint a, PolygonPoint newPoint ) { // Validate that int index = _points.indexOf( a ); if( index != -1 ) { newPoint.setNext( a.getNext() ); newPoint.setPrevious( a ); a.getNext().setPrevious( newPoint ); a.setNext( newPoint ); _points.add( index+1, newPoint ); } else { throw new RuntimeException( "Tried to insert a point into a Polygon after a point not belonging to the Polygon" ); } } public void addPoints( List<PolygonPoint> list ) { PolygonPoint first; for( PolygonPoint p : list ) { p.setPrevious( _last ); if( _last != null ) { p.setNext( _last.getNext() ); _last.setNext( p ); } _last = p; _points.add( p ); } first = (PolygonPoint)_points.get(0); _last.setNext( first ); first.setPrevious( _last ); } /** * Will add a point after the last point added * * @param p */ public void addPoint(PolygonPoint p ) { p.setPrevious( _last ); p.setNext( _last.getNext() ); _last.setNext( p ); _points.add( p ); } public void removePoint( PolygonPoint p ) { PolygonPoint next, prev; next = p.getNext(); prev = p.getPrevious(); prev.setNext( next ); next.setPrevious( prev ); _points.remove( p ); } public PolygonPoint getPoint() { return _last; } public List<TriangulationPoint> getPoints() { return _points; } public List<DelaunayTriangle> getTriangles() { return m_triangles; } public void addTriangle( DelaunayTriangle t ) { m_triangles.add( t ); } public void addTriangles( List<DelaunayTriangle> list ) { m_triangles.addAll( list ); } public void clearTriangulation() { if( m_triangles != null ) { m_triangles.clear(); } } /** * Creates constraints and populates the context with points */ public void prepareTriangulation( TriangulationContext<?> tcx ) { if( m_triangles == null ) { m_triangles = new ArrayList<DelaunayTriangle>( _points.size() ); } else { m_triangles.clear(); } // Outer constraints for( int i = 0; i < _points.size()-1 ; i++ ) { tcx.newConstraint( _points.get( i ), _points.get( i+1 ) ); } tcx.newConstraint( _points.get( 0 ), _points.get( _points.size()-1 ) ); tcx.addPoints( _points ); // Hole constraints if( _holes != null ) { for( Polygon p : _holes ) { for( int i = 0; i < p._points.size()-1 ; i++ ) { tcx.newConstraint( p._points.get( i ), p._points.get( i+1 ) ); } tcx.newConstraint( p._points.get( 0 ), p._points.get( p._points.size()-1 ) ); tcx.addPoints( p._points ); } } if( _steinerPoints != null ) { tcx.addPoints( _steinerPoints ); } } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/geometry/polygon/Polygon.java
Java
bsd
7,329
package org.poly2tri.triangulation; public abstract class TriangulationDebugContext { protected TriangulationContext<?> _tcx; public TriangulationDebugContext( TriangulationContext<?> tcx ) { _tcx = tcx; } public abstract void clear(); }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/TriangulationDebugContext.java
Java
bsd
290
package org.poly2tri.triangulation; public enum TriangulationMode { UNCONSTRAINED,CONSTRAINED,POLYGON; }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/TriangulationMode.java
Java
bsd
116
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation.point; import org.poly2tri.triangulation.TriangulationPoint; public class TPoint extends TriangulationPoint { private double _x; private double _y; private double _z; public TPoint( double x, double y ) { this( x, y, 0 ); } public TPoint( double x, double y, double z ) { _x = x; _y = y; _z = z; } public double getX() { return _x; } public double getY() { return _y; } public double getZ() { return _z; } public float getXf() { return (float)_x; } public float getYf() { return (float)_y; } public float getZf() { return (float)_z; } @Override public void set( double x, double y, double z ) { _x = x; _y = y; _z = z; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/point/TPoint.java
Java
bsd
2,425
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation.point; import java.nio.FloatBuffer; import org.poly2tri.triangulation.TriangulationPoint; public class FloatBufferPoint extends TriangulationPoint { private final FloatBuffer _fb; private final int _ix,_iy,_iz; public FloatBufferPoint( FloatBuffer fb, int index ) { _fb = fb; _ix = index; _iy = index+1; _iz = index+2; } public final double getX() { return _fb.get( _ix ); } public final double getY() { return _fb.get( _iy ); } public final double getZ() { return _fb.get( _iz ); } public final float getXf() { return _fb.get( _ix ); } public final float getYf() { return _fb.get( _iy ); } public final float getZf() { return _fb.get( _iz ); } @Override public void set( double x, double y, double z ) { _fb.put( _ix, (float)x ); _fb.put( _iy, (float)y ); _fb.put( _iz, (float)z ); } public static TriangulationPoint[] toPoints( FloatBuffer fb ) { FloatBufferPoint[] points = new FloatBufferPoint[fb.limit()/3]; for( int i=0,j=0; i<points.length; i++, j+=3 ) { points[i] = new FloatBufferPoint(fb, j); } return points; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/point/FloatBufferPoint.java
Java
bsd
3,083
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation; import java.util.ArrayList; import java.util.List; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; public abstract class TriangulationContext<A extends TriangulationDebugContext> { protected A _debug; protected boolean _debugEnabled = false; protected ArrayList<DelaunayTriangle> _triList = new ArrayList<DelaunayTriangle>(); protected ArrayList<TriangulationPoint> _points = new ArrayList<TriangulationPoint>(200); protected TriangulationMode _triangulationMode; protected Triangulatable _triUnit; private boolean _terminated = false; private boolean _waitUntilNotified; private int _stepTime = -1; private int _stepCount = 0; public int getStepCount() { return _stepCount; } public void done() { _stepCount++; } public abstract TriangulationAlgorithm algorithm(); public void prepareTriangulation( Triangulatable t ) { _triUnit = t; _triangulationMode = t.getTriangulationMode(); t.prepareTriangulation( this ); } public abstract TriangulationConstraint newConstraint( TriangulationPoint a, TriangulationPoint b ); public void addToList( DelaunayTriangle triangle ) { _triList.add( triangle ); } public List<DelaunayTriangle> getTriangles() { return _triList; } public Triangulatable getTriangulatable() { return _triUnit; } public List<TriangulationPoint> getPoints() { return _points; } public synchronized void update(String message) { if( _debugEnabled ) { try { synchronized( this ) { _stepCount++; if( _stepTime > 0 ) { wait( (int)_stepTime ); /** Can we resume execution or are we expected to wait? */ if( _waitUntilNotified ) { wait(); } } else { wait(); } // We have been notified _waitUntilNotified = false; } } catch( InterruptedException e ) { update("Triangulation was interrupted"); } } if( _terminated ) { throw new RuntimeException( "Triangulation process terminated before completion"); } } public void clear() { _points.clear(); _terminated = false; if( _debug != null ) { _debug.clear(); } _stepCount=0; } public TriangulationMode getTriangulationMode() { return _triangulationMode; } public synchronized void waitUntilNotified(boolean b) { _waitUntilNotified = b; } public void terminateTriangulation() { _terminated=true; } public boolean isDebugEnabled() { return _debugEnabled; } public abstract void isDebugEnabled( boolean b ); public A getDebugContext() { return _debug; } public void addPoints( List<TriangulationPoint> points ) { _points.addAll( points ); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/TriangulationContext.java
Java
bsd
5,244
package org.poly2tri.triangulation; import java.util.List; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; public interface Triangulatable { /** * Preparations needed before triangulation start should be handled here * @param tcx */ public void prepareTriangulation( TriangulationContext<?> tcx ); public List<DelaunayTriangle> getTriangles(); public List<TriangulationPoint> getPoints(); public void addTriangle( DelaunayTriangle t ); public void addTriangles( List<DelaunayTriangle> list ); public void clearTriangulation(); public TriangulationMode getTriangulationMode(); }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/Triangulatable.java
Java
bsd
673
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation; import java.util.ArrayList; import org.poly2tri.geometry.primitives.Point; import org.poly2tri.triangulation.delaunay.sweep.DTSweepConstraint; public abstract class TriangulationPoint extends Point { // List of edges this point constitutes an upper ending point (CDT) private ArrayList<DTSweepConstraint> edges; @Override public String toString() { return "[" + getX() + "," + getY() + "]"; } public abstract double getX(); public abstract double getY(); public abstract double getZ(); public abstract float getXf(); public abstract float getYf(); public abstract float getZf(); public abstract void set( double x, double y, double z ); public ArrayList<DTSweepConstraint> getEdges() { return edges; } public void addEdge( DTSweepConstraint e ) { if( edges == null ) { edges = new ArrayList<DTSweepConstraint>(); } edges.add( e ); } public boolean hasEdges() { return edges != null; } /** * @param p - edge destination point * @return the edge from this point to given point */ public DTSweepConstraint getEdge( TriangulationPoint p ) { for( DTSweepConstraint c : edges ) { if( c.p == p ) { return c; } } return null; } public boolean equals(Object obj) { if( obj instanceof TriangulationPoint ) { TriangulationPoint p = (TriangulationPoint)obj; return getX() == p.getX() && getY() == p.getY(); } return super.equals( obj ); } public int hashCode() { long bits = java.lang.Double.doubleToLongBits(getX()); bits ^= java.lang.Double.doubleToLongBits(getY()) * 31; return (((int) bits) ^ ((int) (bits >> 32))); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/TriangulationPoint.java
Java
bsd
3,694
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation.delaunay; import java.util.ArrayList; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.delaunay.sweep.DTSweepConstraint; import org.poly2tri.triangulation.point.TPoint; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class DelaunayTriangle { private final static Logger logger = LoggerFactory.getLogger( DelaunayTriangle.class ); /** Neighbor pointers */ public final DelaunayTriangle[] neighbors = new DelaunayTriangle[3]; /** Flags to determine if an edge is a Constrained edge */ public final boolean[] cEdge = new boolean[] { false, false, false }; /** Flags to determine if an edge is a Delauney edge */ public final boolean[] dEdge = new boolean[] { false, false, false }; /** Has this triangle been marked as an interior triangle? */ protected boolean interior = false; public final TriangulationPoint[] points = new TriangulationPoint[3]; public DelaunayTriangle( TriangulationPoint p1, TriangulationPoint p2, TriangulationPoint p3 ) { points[0] = p1; points[1] = p2; points[2] = p3; } public int index( TriangulationPoint p ) { if( p == points[0] ) { return 0; } else if( p == points[1] ) { return 1; } else if( p == points[2] ) { return 2; } throw new RuntimeException("Calling index with a point that doesn't exist in triangle"); } public int indexCW( TriangulationPoint p ) { int index = index(p); switch( index ) { case 0: return 2; case 1: return 0; default: return 1; } } public int indexCCW( TriangulationPoint p ) { int index = index(p); switch( index ) { case 0: return 1; case 1: return 2; default: return 0; } } public boolean contains( TriangulationPoint p ) { return ( p == points[0] || p == points[1] || p == points[2] ); } public boolean contains( DTSweepConstraint e ) { return ( contains( e.p ) && contains( e.q ) ); } public boolean contains( TriangulationPoint p, TriangulationPoint q ) { return ( contains( p ) && contains( q ) ); } // Update neighbor pointers private void markNeighbor( TriangulationPoint p1, TriangulationPoint p2, DelaunayTriangle t ) { if( ( p1 == points[2] && p2 == points[1] ) || ( p1 == points[1] && p2 == points[2] ) ) { neighbors[0] = t; } else if( ( p1 == points[0] && p2 == points[2] ) || ( p1 == points[2] && p2 == points[0] ) ) { neighbors[1] = t; } else if( ( p1 == points[0] && p2 == points[1] ) || ( p1 == points[1] && p2 == points[0] ) ) { neighbors[2] = t; } else { logger.error( "Neighbor error, please report!" ); // throw new Exception("Neighbor error, please report!"); } } /* Exhaustive search to update neighbor pointers */ public void markNeighbor( DelaunayTriangle t ) { if( t.contains( points[1], points[2] ) ) { neighbors[0] = t; t.markNeighbor( points[1], points[2], this ); } else if( t.contains( points[0], points[2] ) ) { neighbors[1] = t; t.markNeighbor( points[0], points[2], this ); } else if( t.contains( points[0], points[1] ) ) { neighbors[2] = t; t.markNeighbor( points[0], points[1], this ); } else { logger.error( "markNeighbor failed" ); } } public void clearNeighbors() { neighbors[0] = neighbors[1] = neighbors[2] = null; } public void clearNeighbor( DelaunayTriangle triangle ) { if( neighbors[0] == triangle ) { neighbors[0] = null; } else if( neighbors[1] == triangle ) { neighbors[1] = null; } else { neighbors[2] = null; } } /** * Clears all references to all other triangles and points */ public void clear() { DelaunayTriangle t; for( int i=0; i<3; i++ ) { t = neighbors[i]; if( t != null ) { t.clearNeighbor( this ); } } clearNeighbors(); points[0]=points[1]=points[2]=null; } /** * @param t - opposite triangle * @param p - the point in t that isn't shared between the triangles * @return */ public TriangulationPoint oppositePoint( DelaunayTriangle t, TriangulationPoint p ) { assert t != this : "self-pointer error"; return pointCW( t.pointCW(p) ); } // The neighbor clockwise to given point public DelaunayTriangle neighborCW( TriangulationPoint point ) { if( point == points[0] ) { return neighbors[1]; } else if( point == points[1] ) { return neighbors[2]; } return neighbors[0]; } // The neighbor counter-clockwise to given point public DelaunayTriangle neighborCCW( TriangulationPoint point ) { if( point == points[0] ) { return neighbors[2]; } else if( point == points[1] ) { return neighbors[0]; } return neighbors[1]; } // The neighbor across to given point public DelaunayTriangle neighborAcross( TriangulationPoint opoint ) { if( opoint == points[0] ) { return neighbors[0]; } else if( opoint == points[1] ) { return neighbors[1]; } return neighbors[2]; } // The point counter-clockwise to given point public TriangulationPoint pointCCW( TriangulationPoint point ) { if( point == points[0] ) { return points[1]; } else if( point == points[1] ) { return points[2]; } else if( point == points[2] ) { return points[0]; } logger.error( "point location error" ); throw new RuntimeException("[FIXME] point location error"); } // The point counter-clockwise to given point public TriangulationPoint pointCW( TriangulationPoint point ) { if( point == points[0] ) { return points[2]; } else if( point == points[1] ) { return points[0]; } else if( point == points[2] ) { return points[1]; } logger.error( "point location error" ); throw new RuntimeException("[FIXME] point location error"); } // Legalize triangle by rotating clockwise around oPoint public void legalize( TriangulationPoint oPoint, TriangulationPoint nPoint ) { if( oPoint == points[0] ) { points[1] = points[0]; points[0] = points[2]; points[2] = nPoint; } else if( oPoint == points[1] ) { points[2] = points[1]; points[1] = points[0]; points[0] = nPoint; } else if( oPoint == points[2] ) { points[0] = points[2]; points[2] = points[1]; points[1] = nPoint; } else { logger.error( "legalization error" ); throw new RuntimeException("legalization bug"); } } public void printDebug() { System.out.println( points[0] + "," + points[1] + "," + points[2] ); } // Finalize edge marking public void markNeighborEdges() { for( int i = 0; i < 3; i++ ) { if( cEdge[i] ) { switch( i ) { case 0: if( neighbors[0] != null ) neighbors[0].markConstrainedEdge( points[1], points[2] ); break; case 1: if( neighbors[1] != null ) neighbors[1].markConstrainedEdge( points[0], points[2] ); break; case 2: if( neighbors[2] != null ) neighbors[2].markConstrainedEdge( points[0], points[1] ); break; } } } } public void markEdge( DelaunayTriangle triangle ) { for( int i = 0; i < 3; i++ ) { if( cEdge[i] ) { switch( i ) { case 0: triangle.markConstrainedEdge( points[1], points[2] ); break; case 1: triangle.markConstrainedEdge( points[0], points[2] ); break; case 2: triangle.markConstrainedEdge( points[0], points[1] ); break; } } } } public void markEdge( ArrayList<DelaunayTriangle> tList ) { for( DelaunayTriangle t : tList ) { for( int i = 0; i < 3; i++ ) { if( t.cEdge[i] ) { switch( i ) { case 0: markConstrainedEdge( t.points[1], t.points[2] ); break; case 1: markConstrainedEdge( t.points[0], t.points[2] ); break; case 2: markConstrainedEdge( t.points[0], t.points[1] ); break; } } } } } public void markConstrainedEdge( int index ) { cEdge[index] = true; } public void markConstrainedEdge( DTSweepConstraint edge ) { markConstrainedEdge( edge.p, edge.q ); if( ( edge.q == points[0] && edge.p == points[1] ) || ( edge.q == points[1] && edge.p == points[0] ) ) { cEdge[2] = true; } else if( ( edge.q == points[0] && edge.p == points[2] ) || ( edge.q == points[2] && edge.p == points[0] ) ) { cEdge[1] = true; } else if( ( edge.q == points[1] && edge.p == points[2] ) || ( edge.q == points[2] && edge.p == points[1] ) ) { cEdge[0] = true; } } // Mark edge as constrained public void markConstrainedEdge( TriangulationPoint p, TriangulationPoint q ) { if( ( q == points[0] && p == points[1] ) || ( q == points[1] && p == points[0] ) ) { cEdge[2] = true; } else if( ( q == points[0] && p == points[2] ) || ( q == points[2] && p == points[0] ) ) { cEdge[1] = true; } else if( ( q == points[1] && p == points[2] ) || ( q == points[2] && p == points[1] ) ) { cEdge[0] = true; } } public double area() { double a = (points[0].getX() - points[2].getX())*(points[1].getY() - points[0].getY()); double b = (points[0].getX() - points[1].getX())*(points[2].getY() - points[0].getY()); return 0.5*Math.abs( a - b ); } public TPoint centroid() { double cx = ( points[0].getX() + points[1].getX() + points[2].getX() ) / 3d; double cy = ( points[0].getY() + points[1].getY() + points[2].getY() ) / 3d; return new TPoint( cx, cy ); } /** * Get the neighbor that share this edge * * @param constrainedEdge * @return index of the shared edge or -1 if edge isn't shared */ public int edgeIndex( TriangulationPoint p1, TriangulationPoint p2 ) { if( points[0] == p1 ) { if( points[1] == p2 ) { return 2; } else if( points[2] == p2 ) { return 1; } } else if( points[1] == p1 ) { if( points[2] == p2 ) { return 0; } else if( points[0] == p2 ) { return 2; } } else if( points[2] == p1 ) { if( points[0] == p2 ) { return 1; } else if( points[1] == p2 ) { return 0; } } return -1; } public boolean getConstrainedEdgeCCW( TriangulationPoint p ) { if( p == points[0] ) { return cEdge[2]; } else if( p == points[1] ) { return cEdge[0]; } return cEdge[1]; } public boolean getConstrainedEdgeCW( TriangulationPoint p ) { if( p == points[0] ) { return cEdge[1]; } else if( p == points[1] ) { return cEdge[2]; } return cEdge[0]; } public boolean getConstrainedEdgeAcross( TriangulationPoint p ) { if( p == points[0] ) { return cEdge[0]; } else if( p == points[1] ) { return cEdge[1]; } return cEdge[2]; } public void setConstrainedEdgeCCW( TriangulationPoint p, boolean ce ) { if( p == points[0] ) { cEdge[2] = ce; } else if( p == points[1] ) { cEdge[0] = ce; } else { cEdge[1] = ce; } } public void setConstrainedEdgeCW( TriangulationPoint p, boolean ce ) { if( p == points[0] ) { cEdge[1] = ce; } else if( p == points[1] ) { cEdge[2] = ce; } else { cEdge[0] = ce; } } public void setConstrainedEdgeAcross( TriangulationPoint p, boolean ce ) { if( p == points[0] ) { cEdge[0] = ce; } else if( p == points[1] ) { cEdge[1] = ce; } else { cEdge[2] = ce; } } public boolean getDelunayEdgeCCW( TriangulationPoint p ) { if( p == points[0] ) { return dEdge[2]; } else if( p == points[1] ) { return dEdge[0]; } return dEdge[1]; } public boolean getDelunayEdgeCW( TriangulationPoint p ) { if( p == points[0] ) { return dEdge[1]; } else if( p == points[1] ) { return dEdge[2]; } return dEdge[0]; } public boolean getDelunayEdgeAcross( TriangulationPoint p ) { if( p == points[0] ) { return dEdge[0]; } else if( p == points[1] ) { return dEdge[1]; } return dEdge[2]; } public void setDelunayEdgeCCW( TriangulationPoint p, boolean e ) { if( p == points[0] ) { dEdge[2] = e; } else if( p == points[1] ) { dEdge[0] = e; } else { dEdge[1] = e; } } public void setDelunayEdgeCW( TriangulationPoint p, boolean e ) { if( p == points[0] ) { dEdge[1] = e; } else if( p == points[1] ) { dEdge[2] = e; } else { dEdge[0] = e; } } public void setDelunayEdgeAcross( TriangulationPoint p, boolean e ) { if( p == points[0] ) { dEdge[0] = e; } else if( p == points[1] ) { dEdge[1] = e; } else { dEdge[2] = e; } } public void clearDelunayEdges() { dEdge[0] = false; dEdge[1] = false; dEdge[2] = false; } public boolean isInterior() { return interior; } public void isInterior( boolean b ) { interior = b; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/delaunay/DelaunayTriangle.java
Java
bsd
18,530
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation.delaunay.sweep; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; public class AdvancingFrontNode { protected AdvancingFrontNode next = null; protected AdvancingFrontNode prev = null; protected final Double key; // XXX: BST protected final double value; protected final TriangulationPoint point; protected DelaunayTriangle triangle; public AdvancingFrontNode( TriangulationPoint point ) { this.point = point; value = point.getX(); key = Double.valueOf( value ); // XXX: BST } public AdvancingFrontNode getNext() { return next; } public AdvancingFrontNode getPrevious() { return prev; } public TriangulationPoint getPoint() { return point; } public DelaunayTriangle getTriangle() { return triangle; } public boolean hasNext() { return next != null; } public boolean hasPrevious() { return prev != null; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/delaunay/sweep/AdvancingFrontNode.java
Java
bsd
2,819
package org.poly2tri.triangulation.delaunay.sweep; import org.poly2tri.triangulation.TriangulationContext; import org.poly2tri.triangulation.TriangulationDebugContext; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; public class DTSweepDebugContext extends TriangulationDebugContext { /* * Fields used for visual representation of current triangulation */ protected DelaunayTriangle _primaryTriangle; protected DelaunayTriangle _secondaryTriangle; protected TriangulationPoint _activePoint; protected AdvancingFrontNode _activeNode; protected DTSweepConstraint _activeConstraint; public DTSweepDebugContext( DTSweepContext tcx ) { super( tcx ); } public boolean isDebugContext() { return true; } // private Tuple2<TPoint,Double> m_circumCircle = new Tuple2<TPoint,Double>( new TPoint(), new Double(0) ); // public Tuple2<TPoint,Double> getCircumCircle() { return m_circumCircle; } public DelaunayTriangle getPrimaryTriangle() { return _primaryTriangle; } public DelaunayTriangle getSecondaryTriangle() { return _secondaryTriangle; } public AdvancingFrontNode getActiveNode() { return _activeNode; } public DTSweepConstraint getActiveConstraint() { return _activeConstraint; } public TriangulationPoint getActivePoint() { return _activePoint; } public void setPrimaryTriangle( DelaunayTriangle triangle ) { _primaryTriangle = triangle; _tcx.update("setPrimaryTriangle"); } public void setSecondaryTriangle( DelaunayTriangle triangle ) { _secondaryTriangle = triangle; _tcx.update("setSecondaryTriangle"); } public void setActivePoint( TriangulationPoint point ) { _activePoint = point; } public void setActiveConstraint( DTSweepConstraint e ) { _activeConstraint = e; _tcx.update("setWorkingSegment"); } public void setActiveNode( AdvancingFrontNode node ) { _activeNode = node; _tcx.update("setWorkingNode"); } @Override public void clear() { _primaryTriangle = null; _secondaryTriangle = null; _activePoint = null; _activeNode = null; _activeConstraint = null; } // public void setWorkingCircumCircle( TPoint point, TPoint point2, TPoint point3 ) // { // double dx,dy; // // CircleXY.circumCenter( point, point2, point3, m_circumCircle.a ); // dx = m_circumCircle.a.getX()-point.getX(); // dy = m_circumCircle.a.getY()-point.getY(); // m_circumCircle.b = Double.valueOf( Math.sqrt( dx*dx + dy*dy ) ); // // } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/delaunay/sweep/DTSweepDebugContext.java
Java
bsd
3,002
package org.poly2tri.triangulation.delaunay.sweep; import java.util.Comparator; import org.poly2tri.triangulation.TriangulationPoint; public class DTSweepPointComparator implements Comparator<TriangulationPoint> { public int compare( TriangulationPoint p1, TriangulationPoint p2 ) { if(p1.getY() < p2.getY() ) { return -1; } else if( p1.getY() > p2.getY()) { return 1; } else { if(p1.getX() < p2.getX()) { return -1; } else if( p1.getX() > p2.getX() ) { return 1; } else { return 0; } } } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/delaunay/sweep/DTSweepPointComparator.java
Java
bsd
760
package org.poly2tri.triangulation.delaunay.sweep; public class PointOnEdgeException extends RuntimeException { /** * */ private static final long serialVersionUID = 1L; public PointOnEdgeException( String msg ) { super(msg); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/delaunay/sweep/PointOnEdgeException.java
Java
bsd
287
package org.poly2tri.triangulation.delaunay.sweep; public class AdvancingFrontIndex<A> { double _min,_max; IndexNode<A> _root; public AdvancingFrontIndex( double min, double max, int depth ) { if( depth > 5 ) depth = 5; _root = createIndex( depth ); } private IndexNode<A> createIndex( int n ) { IndexNode<A> node = null; if( n > 0 ) { node = new IndexNode<A>(); node.bigger = createIndex( n-1 ); node.smaller = createIndex( n-1 ); } return node; } public A fetchAndRemoveIndex( A key ) { return null; } public A fetchAndInsertIndex( A key ) { return null; } class IndexNode<A> { A value; IndexNode<A> smaller; IndexNode<A> bigger; double range; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/delaunay/sweep/AdvancingFrontIndex.java
Java
bsd
919
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation; public enum TriangulationAlgorithm { DTSweep }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/TriangulationAlgorithm.java
Java
bsd
1,745
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation; public enum TriangulationProcessEvent { Started,Waiting,Failed,Aborted,Done }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/TriangulationProcessEvent.java
Java
bsd
1,776
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation.sets; import java.util.ArrayList; import java.util.List; import org.poly2tri.triangulation.Triangulatable; import org.poly2tri.triangulation.TriangulationContext; import org.poly2tri.triangulation.TriangulationMode; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.delaunay.DelaunayTriangle; public class PointSet implements Triangulatable { List<TriangulationPoint> _points; List<DelaunayTriangle> _triangles; public PointSet( List<TriangulationPoint> points ) { _points = new ArrayList<TriangulationPoint>(); _points.addAll( points ); } public TriangulationMode getTriangulationMode() { return TriangulationMode.UNCONSTRAINED; } public List<TriangulationPoint> getPoints() { return _points; } public List<DelaunayTriangle> getTriangles() { return _triangles; } public void addTriangle( DelaunayTriangle t ) { _triangles.add( t ); } public void addTriangles( List<DelaunayTriangle> list ) { _triangles.addAll( list ); } public void clearTriangulation() { _triangles.clear(); } public void prepareTriangulation( TriangulationContext<?> tcx ) { if( _triangles == null ) { _triangles = new ArrayList<DelaunayTriangle>( _points.size() ); } else { _triangles.clear(); } tcx.addPoints( _points ); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/sets/PointSet.java
Java
bsd
3,309
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation.util; public class Tuple2<A,B> { public A a; public B b; public Tuple2(A a,B b) { this.a = a; this.b = b; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/util/Tuple2.java
Java
bsd
1,851
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation.util; public class Tuple3<A,B,C> { public A a; public B b; public C c; public Tuple3(A a,B b,C c) { this.a = a; this.b = b; this.c = c; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/util/Tuple3.java
Java
bsd
1,895
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation.util; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.geometry.polygon.PolygonPoint; public class PolygonGenerator { private static final double PI_2 = 2.0*Math.PI; public static Polygon RandomCircleSweep( double scale, int vertexCount ) { PolygonPoint point; PolygonPoint[] points; double radius = scale/4; points = new PolygonPoint[vertexCount]; for(int i=0; i<vertexCount; i++) { do { if( i%250 == 0 ) { radius += scale/2*(0.5 - Math.random()); } else if( i%50 == 0 ) { radius += scale/5*(0.5 - Math.random()); } else { radius += 25*scale/vertexCount*(0.5 - Math.random()); } radius = radius > scale/2 ? scale/2 : radius; radius = radius < scale/10 ? scale/10 : radius; } while( radius < scale/10 || radius > scale/2 ); point = new PolygonPoint( radius*Math.cos( (PI_2*i)/vertexCount ), radius*Math.sin( (PI_2*i)/vertexCount ) ); points[i] = point; } return new Polygon( points ); } public static Polygon RandomCircleSweep2( double scale, int vertexCount ) { PolygonPoint point; PolygonPoint[] points; double radius = scale/4; points = new PolygonPoint[vertexCount]; for(int i=0; i<vertexCount; i++) { do { radius += scale/5*(0.5 - Math.random()); radius = radius > scale/2 ? scale/2 : radius; radius = radius < scale/10 ? scale/10 : radius; } while( radius < scale/10 || radius > scale/2 ); point = new PolygonPoint( radius*Math.cos( (PI_2*i)/vertexCount ), radius*Math.sin( (PI_2*i)/vertexCount ) ); points[i] = point; } return new Polygon( points ); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/util/PolygonGenerator.java
Java
bsd
3,982
package org.poly2tri.triangulation.util; import java.util.ArrayList; import java.util.List; import org.poly2tri.triangulation.TriangulationPoint; import org.poly2tri.triangulation.point.TPoint; public class PointGenerator { public static List<TriangulationPoint> uniformDistribution( int n, double scale ) { ArrayList<TriangulationPoint> points = new ArrayList<TriangulationPoint>(); for( int i=0; i<n; i++ ) { points.add( new TPoint( scale*(0.5 - Math.random()), scale*(0.5 - Math.random()) ) ); } return points; } public static List<TriangulationPoint> uniformGrid( int n, double scale ) { double x=0; double size = scale/n; double halfScale = 0.5*scale; ArrayList<TriangulationPoint> points = new ArrayList<TriangulationPoint>(); for( int i=0; i<n+1; i++ ) { x = halfScale - i*size; for( int j=0; j<n+1; j++ ) { points.add( new TPoint( x, halfScale - j*size ) ); } } return points; } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/util/PointGenerator.java
Java
bsd
1,157
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri.triangulation; public interface TriangulationProcessListener { public void triangulationEvent( TriangulationProcessEvent e, Triangulatable unit ); }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/triangulation/TriangulationProcessListener.java
Java
bsd
1,832
package org.poly2tri.transform.coordinate; /** * A transform that aligns the XY plane normal [0,0,1] with any given target normal * * http://www.cs.brown.edu/~jfh/papers/Moller-EBA-1999/paper.pdf * * @author thahlen@gmail.com * */ public class XYToAnyTransform extends Matrix3Transform { /** * Assumes target normal is normalized */ public XYToAnyTransform( double nx, double ny, double nz ) { setTargetNormal( nx, ny, nz ); } /** * Assumes target normal is normalized * * @param nx * @param ny * @param nz */ public void setTargetNormal( double nx, double ny, double nz ) { double h,f,c,vx,vy,hvx; vx = ny; vy = -nx; c = nz; h = (1-c)/(1-c*c); hvx = h*vx; f = (c < 0) ? -c : c; if( f < 1.0 - 1.0E-4 ) { m00=c + hvx*vx; m01=hvx*vy; m02=-vy; m10=hvx*vy; m11=c + h*vy*vy; m12=vx; m20=vy; m21=-vx; m22=c; } else { // if "from" and "to" vectors are nearly parallel m00=1; m01=0; m02=0; m10=0; m11=1; m12=0; m20=0; m21=0; if( c > 0 ) { m22=1; } else { m22=-1; } } } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/transform/coordinate/XYToAnyTransform.java
Java
bsd
1,615
package org.poly2tri.transform.coordinate; import java.util.List; import org.poly2tri.geometry.primitives.Point; public class NoTransform implements CoordinateTransform { public void transform( Point p, Point store ) { store.set( p.getX(), p.getY(), p.getZ() ); } public void transform( Point p ) { } public void transform( List<? extends Point> list ) { } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/transform/coordinate/NoTransform.java
Java
bsd
429
package org.poly2tri.transform.coordinate; /** * A transform that aligns given source normal with the XY plane normal [0,0,1] * * @author thahlen@gmail.com */ public class AnyToXYTransform extends Matrix3Transform { /** * Assumes source normal is normalized */ public AnyToXYTransform( double nx, double ny, double nz ) { setSourceNormal( nx, ny, nz ); } /** * Assumes source normal is normalized * * @param nx * @param ny * @param nz */ public void setSourceNormal( double nx, double ny, double nz ) { double h,f,c,vx,vy,hvx; vx = -ny; vy = nx; c = nz; h = (1-c)/(1-c*c); hvx = h*vx; f = (c < 0) ? -c : c; if( f < 1.0 - 1.0E-4 ) { m00=c + hvx*vx; m01=hvx*vy; m02=-vy; m10=hvx*vy; m11=c + h*vy*vy; m12=vx; m20=vy; m21=-vx; m22=c; } else { // if "from" and "to" vectors are nearly parallel m00=1; m01=0; m02=0; m10=0; m11=1; m12=0; m20=0; m21=0; if( c > 0 ) { m22=1; } else { m22=-1; } } } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/transform/coordinate/AnyToXYTransform.java
Java
bsd
1,544
package org.poly2tri.transform.coordinate; import java.util.List; import org.poly2tri.geometry.primitives.Point; public abstract class Matrix3Transform implements CoordinateTransform { protected double m00,m01,m02,m10,m11,m12,m20,m21,m22; public void transform( Point p, Point store ) { final double px = p.getX(); final double py = p.getY(); final double pz = p.getZ(); store.set(m00 * px + m01 * py + m02 * pz, m10 * px + m11 * py + m12 * pz, m20 * px + m21 * py + m22 * pz ); } public void transform( Point p ) { final double px = p.getX(); final double py = p.getY(); final double pz = p.getZ(); p.set(m00 * px + m01 * py + m02 * pz, m10 * px + m11 * py + m12 * pz, m20 * px + m21 * py + m22 * pz ); } public void transform( List<? extends Point> list ) { for( Point p : list ) { transform( p ); } } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/transform/coordinate/Matrix3Transform.java
Java
bsd
1,054
package org.poly2tri.transform.coordinate; import java.util.List; import org.poly2tri.geometry.primitives.Point; public abstract interface CoordinateTransform { public abstract void transform( Point p, Point store ); public abstract void transform( Point p ); public abstract void transform( List<? extends Point> list ); }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/transform/coordinate/CoordinateTransform.java
Java
bsd
351
/* Poly2Tri * Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Poly2Tri nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.poly2tri; import org.poly2tri.geometry.polygon.Polygon; import org.poly2tri.geometry.polygon.PolygonSet; import org.poly2tri.triangulation.Triangulatable; import org.poly2tri.triangulation.TriangulationAlgorithm; import org.poly2tri.triangulation.TriangulationContext; import org.poly2tri.triangulation.TriangulationMode; import org.poly2tri.triangulation.TriangulationProcess; import org.poly2tri.triangulation.delaunay.sweep.DTSweep; import org.poly2tri.triangulation.delaunay.sweep.DTSweepContext; import org.poly2tri.triangulation.sets.ConstrainedPointSet; import org.poly2tri.triangulation.sets.PointSet; import org.poly2tri.triangulation.util.PolygonGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Poly2Tri { private final static Logger logger = LoggerFactory.getLogger( Poly2Tri.class ); private static final TriangulationAlgorithm _defaultAlgorithm = TriangulationAlgorithm.DTSweep; public static void triangulate( PolygonSet ps ) { TriangulationContext<?> tcx = createContext( _defaultAlgorithm ); for( Polygon p : ps.getPolygons() ) { tcx.prepareTriangulation( p ); triangulate( tcx ); tcx.clear(); } } public static void triangulate( Polygon p ) { triangulate( _defaultAlgorithm, p ); } public static void triangulate( ConstrainedPointSet cps ) { triangulate( _defaultAlgorithm, cps ); } public static void triangulate( PointSet ps ) { triangulate( _defaultAlgorithm, ps ); } public static TriangulationContext<?> createContext( TriangulationAlgorithm algorithm ) { switch( algorithm ) { case DTSweep: default: return new DTSweepContext(); } } public static void triangulate( TriangulationAlgorithm algorithm, Triangulatable t ) { TriangulationContext<?> tcx; // long time = System.nanoTime(); tcx = createContext( algorithm ); tcx.prepareTriangulation( t ); triangulate( tcx ); // logger.info( "Triangulation of {} points [{}ms]", tcx.getPoints().size(), ( System.nanoTime() - time ) / 1e6 ); } public static void triangulate( TriangulationContext<?> tcx ) { switch( tcx.algorithm() ) { case DTSweep: default: DTSweep.triangulate( (DTSweepContext)tcx ); } } /** * Will do a warmup run to let the JVM optimize the triangulation code */ public static void warmup() { /* * After a method is run 10000 times, the Hotspot compiler will compile * it into native code. Periodically, the Hotspot compiler may recompile * the method. After an unspecified amount of time, then the compilation * system should become quiet. */ Polygon poly = PolygonGenerator.RandomCircleSweep2( 50, 50000 ); TriangulationProcess process = new TriangulationProcess(); process.triangulate( poly ); } }
11025063-johndoe-betterperformance-pizibing
poly2tri-core/src/main/java/org/poly2tri/Poly2Tri.java
Java
bsd
4,971
package br.com.teckstoq.views.telasArquivos; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; import br.com.teckstoq.utilitarios.buscaCep; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; @SuppressWarnings("serial") public class tela_cad_filial extends JDialog { private final JPanel contentPanel = new JPanel(); private JTextField campoMatricula; private JTextField campoNomeFilial; private JTextField campoCnpjFilia; private JTextField campoInsEstaFilial; private JLabel lblMtricula; private JLabel lblNome; private JLabel lblCpf; private JLabel lblRg; private JLabel lblEndereo; private JTextField campoEnd; private JLabel lblNumero; private JTextField campaNu; private JLabel lblBairro; private JTextField campaBairro; private JLabel lblCidade; private JTextField campoCidade; private JLabel lblEstado; private JTextField CampoEstado; private JLabel lblFone; private JTextField campoFone1; private JLabel lblFone_1; private JTextField campoFone2; private JLabel lblEmail; private JTextField camapoEmail; private JTextField campoCep; private JLabel label; private JTextField campoSite; private JButton btnCadastrar; private JLabel lblEmpresaMatriz; @SuppressWarnings("rawtypes") private JComboBox comboBoxEmprasaMae; @SuppressWarnings("rawtypes") public tela_cad_filial() { setResizable(false); setIconImage(Toolkit.getDefaultToolkit().getImage(tela_cad_filial.class.getResource("/br/com/teckstoq/imagens/iconeBorda1.png"))); setTitle("Prefer\u00EAncias"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { campaBairro.setText(null); campoCep.setText(null); campoCidade.setText(null); campoEnd.setText(null); CampoEstado.setText(null); campoCnpjFilia.setText(null); campoMatricula.setText(null); campoInsEstaFilial.setText(null); campoNomeFilial.setText(null); campoFone1.setText(null); campoFone2.setText(null); campoSite.setText(null); camapoEmail.setText(null); tela_cad_filial.this.dispose(); } }); setBounds(100, 100, 725, 518); setResizable(false); setModal(true); setLocationRelativeTo(null); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPanel.setBackground(new Color(13, 88, 114)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(null); JLabel lblCadastroEFuncionrio = new JLabel("CADASTRO DE EMPRESA"); lblCadastroEFuncionrio.setFont(new Font("Agency FB", Font.BOLD, 23)); lblCadastroEFuncionrio.setForeground(Color.WHITE); lblCadastroEFuncionrio.setBounds(10, 11, 202, 28); contentPanel.add(lblCadastroEFuncionrio); campoMatricula = new JTextField(); campoMatricula.setBounds(10, 74, 86, 20); contentPanel.add(campoMatricula); campoMatricula.setColumns(10); campoNomeFilial = new JTextField(); campoNomeFilial.setColumns(10); campoNomeFilial.setBounds(10, 123, 470, 20); contentPanel.add(campoNomeFilial); campoCnpjFilia = new JTextField(); campoCnpjFilia.setColumns(10); campoCnpjFilia.setBounds(10, 171, 110, 20); contentPanel.add(campoCnpjFilia); campoInsEstaFilial = new JTextField(); campoInsEstaFilial.setColumns(10); campoInsEstaFilial.setBounds(130, 171, 110, 20); contentPanel.add(campoInsEstaFilial); lblMtricula = new JLabel("M\u00E1tricula"); lblMtricula.setForeground(Color.WHITE); lblMtricula.setFont(new Font("Arial", Font.BOLD, 15)); lblMtricula.setBounds(10, 56, 65, 18); contentPanel.add(lblMtricula); lblNome = new JLabel("Nome"); lblNome.setForeground(Color.WHITE); lblNome.setFont(new Font("Arial", Font.BOLD, 15)); lblNome.setBounds(10, 105, 41, 18); contentPanel.add(lblNome); lblCpf = new JLabel("CNPJ"); lblCpf.setForeground(Color.WHITE); lblCpf.setFont(new Font("Arial", Font.BOLD, 15)); lblCpf.setBounds(10, 154, 40, 18); contentPanel.add(lblCpf); lblRg = new JLabel("Inscri\u00E7\u00E3o Estadual"); lblRg.setForeground(Color.WHITE); lblRg.setFont(new Font("Arial", Font.BOLD, 15)); lblRg.setBounds(130, 154, 129, 18); contentPanel.add(lblRg); lblEndereo = new JLabel("CEP"); lblEndereo.setForeground(Color.WHITE); lblEndereo.setFont(new Font("Arial", Font.BOLD, 15)); lblEndereo.setBounds(10, 202, 31, 18); contentPanel.add(lblEndereo); campoEnd = new JTextField(); campoEnd.setColumns(10); campoEnd.setBounds(222, 225, 258, 20); contentPanel.add(campoEnd); lblNumero = new JLabel("Numero"); lblNumero.setForeground(Color.WHITE); lblNumero.setFont(new Font("Arial", Font.BOLD, 15)); lblNumero.setBounds(10, 256, 56, 18); contentPanel.add(lblNumero); campaNu = new JTextField(); campaNu.setColumns(10); campaNu.setBounds(10, 279, 65, 20); contentPanel.add(campaNu); lblBairro = new JLabel("Bairro"); lblBairro.setForeground(Color.WHITE); lblBairro.setFont(new Font("Arial", Font.BOLD, 15)); lblBairro.setBounds(85, 256, 44, 18); contentPanel.add(lblBairro); campaBairro = new JTextField(); campaBairro.setColumns(10); campaBairro.setBounds(85, 279, 184, 20); contentPanel.add(campaBairro); lblCidade = new JLabel("Cidade"); lblCidade.setForeground(Color.WHITE); lblCidade.setFont(new Font("Arial", Font.BOLD, 15)); lblCidade.setBounds(279, 256, 50, 18); contentPanel.add(lblCidade); campoCidade = new JTextField(); campoCidade.setColumns(10); campoCidade.setBounds(279, 279, 118, 20); contentPanel.add(campoCidade); lblEstado = new JLabel("Estado"); lblEstado.setForeground(Color.WHITE); lblEstado.setFont(new Font("Arial", Font.BOLD, 15)); lblEstado.setBounds(407, 256, 49, 18); contentPanel.add(lblEstado); CampoEstado = new JTextField(); CampoEstado.setColumns(10); CampoEstado.setBounds(407, 279, 73, 20); contentPanel.add(CampoEstado); lblFone = new JLabel("Fone 1"); lblFone.setForeground(Color.WHITE); lblFone.setFont(new Font("Arial", Font.BOLD, 15)); lblFone.setBounds(10, 310, 48, 18); contentPanel.add(lblFone); campoFone1 = new JTextField(); campoFone1.setColumns(10); campoFone1.setBounds(10, 333, 110, 20); contentPanel.add(campoFone1); lblFone_1 = new JLabel("Fone 2"); lblFone_1.setForeground(Color.WHITE); lblFone_1.setFont(new Font("Arial", Font.BOLD, 15)); lblFone_1.setBounds(130, 310, 48, 18); contentPanel.add(lblFone_1); campoFone2 = new JTextField(); campoFone2.setColumns(10); campoFone2.setBounds(130, 333, 110, 20); contentPanel.add(campoFone2); lblEmail = new JLabel("E-mail"); lblEmail.setForeground(Color.WHITE); lblEmail.setFont(new Font("Arial", Font.BOLD, 15)); lblEmail.setBounds(250, 310, 43, 18); contentPanel.add(lblEmail); camapoEmail = new JTextField(); camapoEmail.setColumns(10); camapoEmail.setBounds(250, 333, 230, 20); contentPanel.add(camapoEmail); campoCep = new JTextField(); campoCep.setColumns(10); campoCep.setBounds(10, 225, 110, 20); contentPanel.add(campoCep); label = new JLabel("Endere\u00E7o"); label.setForeground(Color.WHITE); label.setFont(new Font("Arial", Font.BOLD, 15)); label.setBounds(222, 202, 69, 18); contentPanel.add(label); JButton btnBuscar = new JButton("Buscar"); btnBuscar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { buscaCep cep = new buscaCep(); String cepdigitado = campoCep.getText().toString(); campoEnd.setText(cep.getEndereco(cepdigitado)); campaBairro.setText(cep.getBairro(cepdigitado)); campoCidade.setText(cep.getCidade(cepdigitado)); CampoEstado.setText(cep.getUF(cepdigitado)); campaNu.setFocusable(true); } catch (Exception e) { e.printStackTrace(); } } }); btnBuscar.setBounds(127, 224, 85, 23); contentPanel.add(btnBuscar); JLabel lblLogin = new JLabel("Site"); lblLogin.setForeground(Color.WHITE); lblLogin.setFont(new Font("Arial", Font.BOLD, 15)); lblLogin.setBounds(10, 364, 28, 18); contentPanel.add(lblLogin); campoSite = new JTextField(); campoSite.setColumns(10); campoSite.setBounds(10, 387, 470, 20); contentPanel.add(campoSite); btnCadastrar = new JButton("Cadastrar"); btnCadastrar.setBounds(10, 446, 110, 23); contentPanel.add(btnCadastrar); JComboBox comboBoxStatus = new JComboBox(); comboBoxStatus.setBounds(596, 11, 113, 20); contentPanel.add(comboBoxStatus); JLabel lblStatus = new JLabel("Status"); lblStatus.setForeground(Color.WHITE); lblStatus.setFont(new Font("Arial", Font.BOLD, 15)); lblStatus.setBounds(541, 11, 45, 18); contentPanel.add(lblStatus); lblEmpresaMatriz = new JLabel("Empresa Matriz"); lblEmpresaMatriz.setForeground(Color.WHITE); lblEmpresaMatriz.setFont(new Font("Arial", Font.BOLD, 15)); lblEmpresaMatriz.setBounds(106, 56, 110, 18); contentPanel.add(lblEmpresaMatriz); comboBoxEmprasaMae = new JComboBox(); comboBoxEmprasaMae.setBounds(106, 74, 374, 20); contentPanel.add(comboBoxEmprasaMae); } }
09012015teckstoq09012015
src/br/com/teckstoq/views/telasArquivos/tela_cad_filial.java
Java
oos
9,827
package br.com.teckstoq.views.interfacesListener; import br.com.teckstoq.models.Fornecedor; public interface IFornecedorListener { public void fornecedor(Fornecedor fornecedor); }
09012015teckstoq09012015
src/br/com/teckstoq/views/interfacesListener/IFornecedorListener.java
Java
oos
197
package br.com.teckstoq.views.interfacesListener; import br.com.teckstoq.models.Setor; public interface ISetorListener { public void setor(Setor setor); }
09012015teckstoq09012015
src/br/com/teckstoq/views/interfacesListener/ISetorListener.java
Java
oos
170
package br.com.teckstoq.views.interfacesListener; import br.com.teckstoq.models.Peca; public interface IPecaListener { public void peca(Peca peca); }
09012015teckstoq09012015
src/br/com/teckstoq/views/interfacesListener/IPecaListener.java
Java
oos
165
package br.com.teckstoq.views.interfacesListener; import br.com.teckstoq.models.Equipamento; public interface IEquipamentoListener { public void equipamento(Equipamento equipamento); }
09012015teckstoq09012015
src/br/com/teckstoq/views/interfacesListener/IEquipamentoListener.java
Java
oos
200
package br.com.teckstoq.views.interfacesListener; import br.com.teckstoq.models.Comodatario; public interface IComodatarioListener { public void comodatario(Comodatario comodatario); }
09012015teckstoq09012015
src/br/com/teckstoq/views/interfacesListener/IComodatarioListener.java
Java
oos
200
package br.com.teckstoq.views.interfacesListener; import br.com.teckstoq.models.Funcionario; public interface IFuncionarioListener { public void funcionario(Funcionario funcionario); }
09012015teckstoq09012015
src/br/com/teckstoq/views/interfacesListener/IFuncionarioListener.java
Java
oos
203
package br.com.teckstoq.hibernate; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; /** * @author Paulo Lima * @category Projeto TeckEstoq Java SE * @since 05/09/2014 * @version 1.0 * */ @SuppressWarnings("deprecation") public class HibernateUtil { private static final SessionFactory sessionFactory; private static ThreadLocal<Session> sessions = new ThreadLocal<Session>(); static { sessionFactory = new Configuration().configure().buildSessionFactory(); } public static Session getSession() { if (sessions.get() != null) { } sessions.set(sessionFactory.openSession()); return sessions.get(); } public static void closeCurrentSession() { sessions.get().close(); sessions.set(null); } public static Session currentSession() { return sessions.get(); } public static SessionFactory getSessionFactory() { return sessionFactory; } }
09012015teckstoq09012015
src/br/com/teckstoq/hibernate/HibernateUtil.java
Java
oos
1,162
package br.com.teckstoq.hibernate; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Configuration; import org.hibernate.tool.hbm2ddl.SchemaExport; import br.com.teckstoq.models.Comodatario; public class HibernateUtilP { private static SessionFactory factory; public static Configuration getInitializedConfiguration() { AnnotationConfiguration config = new AnnotationConfiguration(); /* add all of your JPA annotated classes here!!! */ config.addAnnotatedClass(Comodatario.class); config.configure(); return config; } public static Session getSession() { if (factory == null) { Configuration config = HibernateUtilP.getInitializedConfiguration(); factory = config.buildSessionFactory(); } Session hibernateSession = factory.getCurrentSession(); return hibernateSession; } public static void closeSession() { HibernateUtilP.getSession().close(); } public static void recreateDatabase() { Configuration config; config = HibernateUtilP.getInitializedConfiguration(); new SchemaExport(config).create(true, true); } public static Session beginTransaction() { Session hibernateSession; hibernateSession = HibernateUtil.getSession(); hibernateSession.beginTransaction(); return hibernateSession; } public static void commitTransaction() { HibernateUtilP.getSession().getTransaction().commit(); } public static void rollbackTransaction() { HibernateUtilP.getSession().getTransaction().rollback(); } public static void main(String args[]) { HibernateUtilP.recreateDatabase(); } }
09012015teckstoq09012015
src/br/com/teckstoq/hibernate/HibernateUtilP.java
Java
oos
1,704
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioLogHistorico; import br.com.teckstoq.models.LogHistorico; public class RepositorioLogHistorico implements IRepositorioLogHistorico { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //------------------------------------------------------------------- public void inserirLogHistorico(LogHistorico logHistorico) throws SQLException { dao.save(logHistorico); } //-------------------------------------------------------------------- public void atualizarLogHistorico(LogHistorico logHistorico) throws SQLException { dao.update(logHistorico); } //-------------------------------------------------------------------- public void removerLogHistorico(LogHistorico logHistorico) throws SQLException { dao.delete(logHistorico); } //-------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<LogHistorico> listarLogHistorico() throws SQLException { return (ArrayList<LogHistorico>) dao.list(LogHistorico.class); } //--------------------------------------------------------------------- public LogHistorico retornaLogHistorico(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM LogHistorico WHERE idLogHistorico =:chave"); selecao.setLong("chave", chave); LogHistorico logHistorico = (LogHistorico) selecao.uniqueResult(); sessao.close(); return logHistorico; } //---------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioLogHistorico.java
Java
oos
1,950
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioEquipamento; import br.com.teckstoq.models.Equipamento; import br.com.teckstoq.models.Fornecedor; public class RepositorioEquipamento implements IRepositorioEquipamento { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //------------------------------------------------------------------- public void inserirEquipamento(Equipamento equipamento) throws SQLException { dao.save(equipamento); } //------------------------------------------------------------------- public void atualizarEquipamento(Equipamento equipamento) throws SQLException { dao.update(equipamento); } //------------------------------------------------------------------- public void removerEquipamento(Equipamento equipamento) throws SQLException { dao.delete(equipamento); } //------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Equipamento> listarEquipamento() throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Equipamento> equipamentos = new ArrayList<Equipamento>(); Query selecao = sessao.createQuery("FROM Equipamento WHERE status='ATIVO'"); equipamentos = (ArrayList<Equipamento>) selecao.list(); sessao.close(); return equipamentos; } //------------------------------------------------------------------- public Equipamento retornaEquipamento(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Equipamento WHERE idMaquina =:chave AND status='ATIVO'"); selecao.setLong("chave", chave); Equipamento equipamento = (Equipamento) selecao.uniqueResult(); sessao.close(); return equipamento; } //------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Equipamento> buscarEquipamento(String chave, String tipo) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Equipamento> equipamentos = new ArrayList<Equipamento>(); if (tipo.equals("CODIGO")){ Query selecao = sessao.createQuery("FROM Equipamento WHERE codigoFabrica like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); equipamentos = (ArrayList<Equipamento>) selecao.list(); sessao.close(); } else if(tipo.equals("NOME")){ Query selecao = sessao.createQuery("FROM Equipamento WHERE nomeMaquina like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); equipamentos = (ArrayList<Equipamento>) selecao.list(); sessao.close(); } else{ //------------------------------------------------------------------------------- Fornecedor fornecedor = new Fornecedor(); sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Fornecedor WHERE nome like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); fornecedor = (Fornecedor) selecao.uniqueResult(); if (!(fornecedor == null)){ long idFornecedor = fornecedor.getIdFornecedor(); Query selecao2 = sessao.createQuery("FROM Equipamento WHERE fornecedor =:chave2 AND status='ATIVO'"); selecao2.setLong("chave2", idFornecedor); equipamentos = (ArrayList<Equipamento>) selecao2.list(); sessao.close(); } //------------------------------------------------------------------------------- } return equipamentos; } //------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioEquipamento.java
Java
oos
4,142
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioEntradaEstoque; import br.com.teckstoq.models.EntradaEstoque; public class RepositorioEntradaEstoque implements IRepositorioEntradaEstoque { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //------------------------------------------------------------------- public void inserirEntradaEstoque(EntradaEstoque entradaEstoque) throws SQLException { dao.save(entradaEstoque); } //------------------------------------------------------------------- public void atualizarEntradaEstoque(EntradaEstoque entradaEstoque) throws SQLException { dao.update(entradaEstoque); } //------------------------------------------------------------------- public void removerEntradaEstoque(EntradaEstoque entradaEstoque) throws SQLException { dao.delete(entradaEstoque); } //------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<EntradaEstoque> listarEntradaEstoque() throws SQLException { return (ArrayList<EntradaEstoque>) dao.list(EntradaEstoque.class); } //------------------------------------------------------------------- public EntradaEstoque retornaEntradaEstoque(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM EntradaEstoque WHERE idEntradaEstoque =:chave"); selecao.setLong("chave", chave); EntradaEstoque entradaEstoque = (EntradaEstoque) selecao.uniqueResult(); sessao.close(); return entradaEstoque; } //------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioEntradaEstoque.java
Java
oos
2,003
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioFornecedor; import br.com.teckstoq.models.Fornecedor; import br.com.teckstoq.models.Funcionario; @SuppressWarnings("unused") public class RepositorioFornecedor implements IRepositorioFornecedor { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //------------------------------------------------------------------------- public void inserirFornecedor(Fornecedor fornecedor) throws SQLException { dao.save(fornecedor); } //------------------------------------------------------------------------- public void atualizarFornecedor(Fornecedor fornecedor) throws SQLException { dao.update(fornecedor); } //------------------------------------------------------------------------- public void removerFornecedor(Fornecedor fornecedor) throws SQLException { dao.delete(fornecedor); } //------------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Fornecedor> listarFornecedor() throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Fornecedor> fornecedores = new ArrayList<Fornecedor>(); Query selecao = sessao.createQuery("FROM Fornecedor WHERE status='ATIVO'"); fornecedores = (ArrayList<Fornecedor>) selecao.list(); sessao.close(); return fornecedores; } //------------------------------------------------------------------------- public Fornecedor retornaFornecedor(long chave) { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Fornecedor WHERE idFornecedor =:chave"); selecao.setLong("chave", chave); Fornecedor fornecedor = (Fornecedor) selecao.uniqueResult(); sessao.close(); return fornecedor; } //------------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Fornecedor> buscarFornecedor(String chave, String tipo) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Fornecedor> fornecedores = new ArrayList<Fornecedor>(); if (tipo.equals("CODIGO")){ Query selecao = sessao.createQuery("FROM Fornecedor WHERE idFornecedor like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); fornecedores = (ArrayList<Fornecedor>) selecao.list(); sessao.close(); } else if(tipo.equals("NOME")){ Query selecao = sessao.createQuery("FROM Fornecedor WHERE nome like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); fornecedores = (ArrayList<Fornecedor>) selecao.list(); sessao.close(); } else if(tipo.equals("CNPJ")){ Query selecao = sessao.createQuery("FROM Fornecedor WHERE cnpj like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); fornecedores = (ArrayList<Fornecedor>) selecao.list(); sessao.close(); } else{ Query selecao = sessao.createQuery("FROM Fornecedor WHERE inscricaoEstadual like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); fornecedores = (ArrayList<Fornecedor>) selecao.list(); sessao.close(); } return fornecedores; } //------------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioFornecedor.java
Java
oos
3,793
package br.com.teckstoq.repositorio; import java.sql.SQLException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioAcesso; import br.com.teckstoq.models.ValidarAcesso; public class RepositorioAcesso implements IRepositorioAcesso { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; // ---------------------------------------------------------- public void inserirAcesso(ValidarAcesso acesso) throws SQLException { dao.save(acesso); } // ---------------------------------------------------------- public void atualizarAcesso(ValidarAcesso acesso) throws SQLException { dao.update(acesso); } // ---------------------------------------------------------- public ValidarAcesso retornaAcesso(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM ValidarAcesso WHERE idAcesso =:chave"); selecao.setLong("chave", chave); ValidarAcesso acesso = (ValidarAcesso) selecao.uniqueResult(); sessao.close(); return acesso; } }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioAcesso.java
Java
oos
1,300
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioEstoque; import br.com.teckstoq.models.Estoque; import br.com.teckstoq.models.Peca; public class RepositorioEstoque implements IRepositorioEstoque { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //---------------------------------------------------------------- public void inserirEstoque(Estoque estoque) throws SQLException { dao.save(estoque); } //---------------------------------------------------------------- public void atualizarEstoque(Estoque estoque) throws SQLException { dao.update(estoque); } //---------------------------------------------------------------- public void removerEstoque(Estoque estoque) throws SQLException { dao.delete(estoque); } //---------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Estoque> listarEstoque() throws SQLException { return (ArrayList<Estoque>) dao.list(Estoque.class); } //---------------------------------------------------------------- public Estoque retornaEstoquePorProduto(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Estoque WHERE idEstoque =:chave"); selecao.setLong("chave", chave); Estoque estoque = (Estoque) selecao.uniqueResult(); sessao.close(); return estoque; } //--------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Estoque> buscarQuantidadeMinima() throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Estoque> estoque = new ArrayList<Estoque>(); Query selecao = sessao .createQuery("FROM Estoque WHERE quantidade <= quantidadeMinima"); estoque = (ArrayList<Estoque>) selecao.list(); sessao.close(); return estoque; } //--------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioEstoque.java
Java
oos
2,344
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioSaidaEmprestimo; import br.com.teckstoq.models.Fornecedor; import br.com.teckstoq.models.Peca; import br.com.teckstoq.models.SaidaEmprestimo; public class RepositorioSaidaEmprestimo implements IRepositorioSaidaEmprestimo { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //--------------------------------------------------------------------- public void inserirSaidaEmprestimo(SaidaEmprestimo saidaEmprestimo) throws SQLException { dao.save(saidaEmprestimo); } //---------------------------------------------------------------------- public void atualizarSaidaEmprestimo(SaidaEmprestimo saidaEmprestimo) throws SQLException { dao.update(saidaEmprestimo); } //---------------------------------------------------------------------- public void removerSaidaEmprestimo(SaidaEmprestimo saidaEmprestimo) throws SQLException { dao.delete(saidaEmprestimo); } //---------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<SaidaEmprestimo> listarSaidaEmprestimo() throws SQLException { return (ArrayList<SaidaEmprestimo>) dao.list(SaidaEmprestimo.class); } //---------------------------------------------------------------------- public SaidaEmprestimo retornaSaidaEmprestimo(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM SaidaEmprestimo WHERE idSaidaEmprestimo =:chave"); selecao.setLong("chave", chave); SaidaEmprestimo saidaEmprestimo = (SaidaEmprestimo) selecao.uniqueResult(); sessao.close(); return saidaEmprestimo; } //---------------------------------------------------------------------- public ArrayList<SaidaEmprestimo> buscarSaidaEmprestimos(String chave, String tipo) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<SaidaEmprestimo> saidaEmprestimos = new ArrayList<SaidaEmprestimo>(); Query selecao = sessao.createQuery("FROM SaidaEmprestimo WHERE idSaidaEmprestimo like :chave AND WHERE Status='ATIVO'"); selecao.setString("chave", chave+"%"); saidaEmprestimos = (ArrayList<SaidaEmprestimo>) selecao.list(); sessao.close(); return saidaEmprestimos; } //---------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<SaidaEmprestimo> buscarSaidaEmprestimosData() throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<SaidaEmprestimo> saidaEmprestimos = new ArrayList<SaidaEmprestimo>(); Query selecao = sessao.createQuery("FROM SaidaEmprestimo WHERE status='ativo'"); saidaEmprestimos = (ArrayList<SaidaEmprestimo>) selecao.list(); sessao.close(); return saidaEmprestimos; } //---------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioSaidaEmprestimo.java
Java
oos
3,395
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioEntradaEmprestimo; import br.com.teckstoq.models.EntradaEmprestimo; public class RepositorioEntradaEmprestimo implements IRepositorioEntradaEmprestimo { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //-------------------------------------------------------------------------- public void inserirEntradaEmprestimo(EntradaEmprestimo entradaEmprestimo) throws SQLException { dao.save(entradaEmprestimo); } //-------------------------------------------------------------------------- public void atualizarEntradaEmprestimo(EntradaEmprestimo entradaEmprestimo) throws SQLException { dao.update(entradaEmprestimo); } //-------------------------------------------------------------------------- public void removerEntradaEmprestimo(EntradaEmprestimo entradaEmprestimo) throws SQLException { dao.delete(entradaEmprestimo); } //-------------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<EntradaEmprestimo> listarEntradaEmprestimo() throws SQLException { return (ArrayList<EntradaEmprestimo>) dao.list(EntradaEmprestimo.class); } //-------------------------------------------------------------------------- public EntradaEmprestimo retornaEntradaEmprestimo(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM EntradaEmprestimo WHERE idEntradaEmprestim =:chave"); selecao.setLong("chave", chave); EntradaEmprestimo entradaEmprestimo = (EntradaEmprestimo) selecao.uniqueResult(); sessao.close(); return entradaEmprestimo; } //--------------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioEntradaEmprestimo.java
Java
oos
2,134
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioComodatario; import br.com.teckstoq.models.Comodatario; import br.com.teckstoq.models.Setor; public class RepositorioComodatario implements IRepositorioComodatario { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //--------------------------------------------------------------------------- public void inserirComodatario(Comodatario comodatario) throws SQLException { dao.save(comodatario); } //--------------------------------------------------------------------------- public void atualizarComodatario(Comodatario comodatario) throws SQLException { dao.update(comodatario); } //--------------------------------------------------------------------------- public void removerComodatario(Comodatario comodatario) throws SQLException { dao.delete(comodatario); } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Comodatario> listarComodatario() throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Comodatario> comodatarios = new ArrayList<Comodatario>(); Query selecao = sessao.createQuery("FROM Comodatario WHERE status='ATIVO'"); comodatarios = (ArrayList<Comodatario>) selecao.list(); sessao.close(); return comodatarios; } //--------------------------------------------------------------------------- public Comodatario retornaComodatario(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Comodatario WHERE idComodatario =:chave"); selecao.setLong("chave", chave); Comodatario comodatario = (Comodatario) selecao.uniqueResult(); sessao.close(); return comodatario; } //-------------------------------------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Comodatario> buscarComodatarios(String chave, String tipo) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Comodatario> comodatarios = new ArrayList<Comodatario>(); if (tipo.equals("CODIGO")){ Query selecao = sessao.createQuery("FROM Comodatario WHERE idComodatario like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); comodatarios = (ArrayList<Comodatario>) selecao.list(); sessao.close(); } else{ Query selecao = sessao.createQuery("FROM Comodatario WHERE nomeComodatario like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); comodatarios = (ArrayList<Comodatario>) selecao.list(); sessao.close(); } return comodatarios; } //------------------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioComodatario.java
Java
oos
3,295
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioSaidaEstoque; import br.com.teckstoq.models.SaidaEstoque; public class RepositorioSaidaEstoque implements IRepositorioSaidaEstoque { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //--------------------------------------------------------- public void inserirSaidaEstoque(SaidaEstoque saidaEstoque) throws SQLException { dao.save(saidaEstoque); } //--------------------------------------------------------- public void atualizarSaidaEstoque(SaidaEstoque saidaEstoque) throws SQLException { dao.update(saidaEstoque); } //--------------------------------------------------------- public void removerSaidaEstoque(SaidaEstoque saidaEstoque) throws SQLException { dao.delete(saidaEstoque); } //--------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<SaidaEstoque> listarSaidaEstoque() throws SQLException { return (ArrayList<SaidaEstoque>) dao.list(SaidaEstoque.class); } //--------------------------------------------------------- public SaidaEstoque retornaSaidaEstoque(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM SaidaEstoque WHERE idSaidaEstoque =:chave"); selecao.setLong("chave", chave); SaidaEstoque saidaEstoque = (SaidaEstoque) selecao.uniqueResult(); sessao.close(); return saidaEstoque; } //--------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioSaidaEstoque.java
Java
oos
1,882
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioEmpresa; import br.com.teckstoq.models.Empresa; public class RepositorioEmpresa implements IRepositorioEmpresa { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //------------------------------------------------------------------------- public void inserirEmpresa(Empresa empresa) throws SQLException { dao.save(empresa); } //------------------------------------------------------------------------- public void atualizarEmpresa(Empresa empresa) throws SQLException { dao.update(empresa); } //------------------------------------------------------------------------- public void removerEmpresa(Empresa empresa) throws SQLException { dao.delete(empresa); } //------------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Empresa> listarEmpresa() throws SQLException { return (ArrayList<Empresa>) dao.list(Empresa.class); } //------------------------------------------------------------------------- public Empresa retornaEmpresa(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Empresa WHERE id =:chave"); selecao.setLong("chave", chave); Empresa empresa = (Empresa) selecao.uniqueResult(); sessao.close(); return empresa; } //---------------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioEmpresa.java
Java
oos
1,840
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioSolicitacaoCompra; import br.com.teckstoq.models.Comodatario; import br.com.teckstoq.models.Compra; import br.com.teckstoq.models.SolicitacaoCompra; @SuppressWarnings("unused") public class RepositorioSolicitacaoCompra implements IRepositorioSolicitacaoCompra { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //--------------------------------------------------------------------------- public void inserirSolicitacaoCompra(SolicitacaoCompra solicitacaoCompra) throws SQLException { dao.save(solicitacaoCompra); } //--------------------------------------------------------------------------- public void atualizarSolicitacaoCompra(SolicitacaoCompra solicitacaoCompra) throws SQLException { dao.update(solicitacaoCompra); } //--------------------------------------------------------------------------- public void removerSolicitacaoCompra(SolicitacaoCompra solicitacaoCompra) throws SQLException { dao.delete(solicitacaoCompra); } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<SolicitacaoCompra> listarSolicitacaoCompra() throws SQLException { return (ArrayList<SolicitacaoCompra>) dao.list(SolicitacaoCompra.class); } //--------------------------------------------------------------------------- public SolicitacaoCompra retornaSolicitacaoCompra(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM SolicitacaoCompra WHERE idSolicitacaoCompra =:chave"); selecao.setLong("chave", chave); SolicitacaoCompra solicitacaoCompra = (SolicitacaoCompra) selecao.uniqueResult(); sessao.close(); return solicitacaoCompra; } //--------------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<SolicitacaoCompra> buscarSolicitacaoCompra(String chave, String tipo) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<SolicitacaoCompra> solicitacoes = new ArrayList<SolicitacaoCompra>(); if (tipo.equals("CODIGO")){ Query selecao = sessao.createQuery("FROM SolicitacaoCompra WHERE idSolicitacaoCompra like :chave"); selecao.setString("chave", chave+"%"); solicitacoes = (ArrayList<SolicitacaoCompra>) selecao.list(); sessao.close(); } else{ Query selecao = sessao.createQuery("FROM SolicitacaoCompra WHERE nomSolicitacao like :chave"); selecao.setString("chave", chave+"%"); solicitacoes = (ArrayList<SolicitacaoCompra>) selecao.list(); sessao.close(); } return solicitacoes; } //--------------------------------------------------------------------------- public ArrayList<SolicitacaoCompra> buscarSolicitacoesCompra() throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<SolicitacaoCompra> solicitacoes = new ArrayList<SolicitacaoCompra>(); Query selecao = sessao.createQuery("FROM SolicitacaoCompra WHERE Status='Solicitar'"); solicitacoes = (ArrayList<SolicitacaoCompra>) selecao.list(); sessao.close(); return solicitacoes; } //--------------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioSolicitacaoCompra.java
Java
oos
3,781
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioCompra; import br.com.teckstoq.models.Compra; public class RepositorioCompra implements IRepositorioCompra { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //---------------------------------------------------------------- public void inserirCompra(Compra compra) throws SQLException { dao.save(compra); } //---------------------------------------------------------------- public void atualizarCompra(Compra compra) throws SQLException { dao.update(compra); } //---------------------------------------------------------------- public void removerCompra(Compra compra) throws SQLException { dao.delete(compra); } //---------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Compra> listarCompra() throws SQLException { return (ArrayList<Compra>) dao.list(Compra.class); } //---------------------------------------------------------------- public Compra retornaCompra(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Compra WHERE idCompra =:chave"); selecao.setLong("chave", chave); Compra compra = (Compra) selecao.uniqueResult(); sessao.close(); return compra; } //---------------------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Compra> buscarCompra(String chave, String tipo) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Compra> compras = new ArrayList<Compra>(); if (tipo.equals("CODIGO")){ Query selecao = sessao.createQuery("FROM Compra WHERE idCompra like :chave"); selecao.setString("chave", chave+"%"); compras = (ArrayList<Compra>) selecao.list(); sessao.close(); } else if(tipo.equals("DATA")){ Query selecao = sessao.createQuery("FROM Compra WHERE dataSolicitacao like :chave"); selecao.setString("chave", chave+"%"); compras = (ArrayList<Compra>) selecao.list(); sessao.close(); } else{ //------------------------------------------------------------------------------- Query selecao = sessao.createQuery("FROM Compra WHERE status like :chave"); selecao.setString("chave", chave+"%"); compras = (ArrayList<Compra>) selecao.list(); sessao.close(); } return compras; } //---------------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioCompra.java
Java
oos
2,978
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioPeca; import br.com.teckstoq.models.Fornecedor; import br.com.teckstoq.models.Peca; /** * @author Paulo Lima * @category Projeto TeckEstoq Java SE * @since 27/10/2014 * @version 1.0 * */ public class RepositorioPeca implements IRepositorioPeca { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; // --------------------------------------------------------------- public void inserirPeca(Peca peca) throws SQLException { dao.save(peca); } // --------------------------------------------------------------- public void atualizarPeca(Peca peca) throws SQLException { dao.update(peca); } // --------------------------------------------------------------- public void removerPeca(Peca peca) throws SQLException { dao.delete(peca); } // --------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Peca> listarPeca() throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Peca> pecas = new ArrayList<Peca>(); Query selecao = sessao .createQuery("FROM Peca WHERE status='ATIVO'"); pecas = (ArrayList<Peca>) selecao.list(); sessao.close(); return pecas; } // --------------------------------------------------------------- public Peca retornaPeca(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Peca WHERE idPeca =:chave AND status='ATIVO'"); selecao.setLong("chave", chave); Peca peca = (Peca) selecao.uniqueResult(); sessao.close(); return peca; } // --------------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Peca> buscarPeca(String chave, String tipo) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Peca> pecas = new ArrayList<Peca>(); if (tipo.equals("CODIGO")) { Query selecao = sessao .createQuery("FROM Peca WHERE codigoFabrica like :chave AND status='ATIVO'"); selecao.setString("chave", chave + "%"); pecas = (ArrayList<Peca>) selecao.list(); sessao.close(); } else if (tipo.equals("DESCRICAO")) { Query selecao = sessao .createQuery("FROM Peca WHERE descricao like :chave AND status='ATIVO'"); selecao.setString("chave", chave + "%"); pecas = (ArrayList<Peca>) selecao.list(); sessao.close(); } else { Query selecao = sessao .createQuery("FROM Peca WHERE codigoFornecedor like :chave AND status='ATIVO'"); selecao.setString("chave", chave + "%"); pecas = (ArrayList<Peca>) selecao.list(); sessao.close(); } return pecas; } // ----------------------------------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioPeca.java
Java
oos
3,276
package br.com.teckstoq.repositorio; import java.security.Permission; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioPermissoes; import br.com.teckstoq.irepositorio.IRepositorioSetor; import br.com.teckstoq.models.Permissoes; import br.com.teckstoq.models.Setor; public class RepositorioPermissoes implements IRepositorioPermissoes { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; // ---------------------------------------------------------- public void inserirPermissoes(Permissoes permissoes) throws SQLException { dao.save(permissoes); } // ---------------------------------------------------------- public void atualizarPermissoes(Permissoes permissoes) throws SQLException { dao.update(permissoes); } // ---------------------------------------------------------- public void removerPermissoes(Permissoes permissoes) throws SQLException { dao.delete(permissoes); } // ---------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Permissoes> listarPermissoes() throws SQLException { return (ArrayList<Permissoes>) dao.list(Permissoes.class); } // ---------------------------------------------------------- public Permissoes retornaPermissoes(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Permissoes WHERE idPermissoes =:chave"); selecao.setLong("chave", chave); Permissoes permissoes = (Permissoes) selecao.uniqueResult(); sessao.close(); return permissoes; } }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioPermissoes.java
Java
oos
1,895
package br.com.teckstoq.repositorio; import java.sql.SQLException; import java.util.ArrayList; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import br.com.teckstoq.dao.Dao; import br.com.teckstoq.hibernate.HibernateUtil; import br.com.teckstoq.irepositorio.IRepositorioSetor; import br.com.teckstoq.models.Setor; public class RepositorioSetor implements IRepositorioSetor { private Dao dao = Dao.getInstance(); private Session sessao; private Transaction tx; //---------------------------------------------------------- public void inserirSetor(Setor setor) throws SQLException { dao.save(setor); } //---------------------------------------------------------- public void atualizarSetor(Setor setor) throws SQLException { dao.update(setor); } //---------------------------------------------------------- public void removerSetor(Setor setor) throws SQLException { dao.delete(setor); } //---------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Setor> listarSetor() throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Setor> setores = new ArrayList<Setor>(); Query selecao = sessao.createQuery("FROM Setor WHERE status='ATIVO'"); setores = (ArrayList<Setor>) selecao.list(); sessao.close(); return setores; } //---------------------------------------------------------- public Setor retornaSetor(long chave) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); Query selecao = sessao.createQuery("FROM Setor WHERE idSetor =:chave AND status='ATIVO'"); selecao.setLong("chave", chave); Setor setor = (Setor) selecao.uniqueResult(); sessao.close(); return setor; } //---------------------------------------------------------- @SuppressWarnings("unchecked") public ArrayList<Setor> buscarSetor(String chave, String tipo) throws SQLException { sessao = HibernateUtil.getSession(); tx = sessao.beginTransaction(); ArrayList<Setor> setores = new ArrayList<Setor>(); if (tipo.equals("CODIGO")){ Query selecao = sessao.createQuery("FROM Setor WHERE idSetor like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); setores = (ArrayList<Setor>) selecao.list(); sessao.close(); } else{ Query selecao = sessao.createQuery("FROM Setor WHERE descricao like :chave AND status='ATIVO'"); selecao.setString("chave", chave+"%"); setores = (ArrayList<Setor>) selecao.list(); sessao.close(); } return setores; } //---------------------------------------------------------- }
09012015teckstoq09012015
src/br/com/teckstoq/repositorio/RepositorioSetor.java
Java
oos
2,843