#include "appmodel.h" #include #include #include #include "ha_part.h" #include "ha_part_util.h" #include "roll_hm.hxx" // HOOPS includes #include "hc.h" #include "HStream.h" #include "HOpcodeShell.h" #include "HUtility.h" #include #include "HTools.h" #include "ha_rend_options.h" #include "HIOManager.h" #include "varray.h" #include "HBaseView.h" #include "kernapi.hxx" #include AppModel::AppModel() { m_bSolidModel = true; SetBRepGeometry(true); m_mi=0; // initialize_ha_part(); m_pHAPart = ACIS_NEW HA_Part(); api_part_set_distribution_mode( TRUE );//设置历史分布打开或关闭。 // distributed_history(TRUE,TRUE); char buffer[1024]; char pbuffer[POINTER_BUFFER_SIZE]; PART* pPart = m_pHAPart->GetPart(); sprintf(buffer,"?Include Library/%s",ptoax(pPart->history_stream(), pbuffer)); qDebug() << "appmodde buffer" << buffer; m_ModelKey = HA_KCreate_Segment(0, buffer); HA_Set_Rendering_Options("segment pattern = ?Include Library/history/entity");//提供对如何通过HOOPS/ACIS网格管理器将ACIS对象渲染为HOOPS对象的控制 } AppModel::~AppModel() { // Model cleanup : delete all the entities from the // partition associated with this model DeleteAllEntities(); if(m_pHAPart) { ACIS_DELETE m_pHAPart; m_pHAPart = NULL; } // terminate_ha_part(); if(m_mi) { delete m_mi; m_mi = 0; } } // Delete all the entities in the current model from the // modeler and associated HOOPS geometry void AppModel::DeleteAllEntities() { // HA_Delete_Entity_Geometry(m_entityList); // api_del_entity_list(m_entityList); // m_entityList.clear(); ENTITY_LIST elist; m_pHAPart->GetPart()->get_entities(elist); elist.init(); ENTITY* pEnt = NULL; while((pEnt= elist.next())!= NULL) { m_pHAPart->RemoveEntity(pEnt); } api_del_entity_list(elist); elist.clear(); } void AppModel::AddAcisEntity( ENTITY* entity ) { if(m_pHAPart) { api_facet_entity( entity); m_pHAPart->AddEntity(entity); } } void AppModel::AddAcisEntitiesToPart( ENTITY_LIST& list) { if(m_pHAPart) { api_facet_bodies( list); ENTITY* entity = list.first(); while (entity) { m_pHAPart->AddEntity(entity); entity = list.next(); } } } void AppModel::RemoveAcisEntity( ENTITY* entity ) { if(m_pHAPart) { m_pHAPart->RemoveEntity(entity); } } void AppModel::UpdateAcisEntity( ENTITY* entity ) { if(m_pHAPart) { m_pHAPart->UpdateEntity(entity); } } void AppModel::AddAcisEntities( const ENTITY_LIST& entityList ) { if(m_pHAPart) { m_pHAPart->AddEntities(entityList); } } void AppModel::DeleteAcisEntity( ENTITY* entity) { // delete from ACIS if (m_pHAPart) { m_pHAPart->RemoveEntity(entity); } api_del_entity(entity); } void AppModel::DeleteAcisEntities( ENTITY_LIST& elist) { // delete from HOOPS // HA_Delete_Entity_Geometry(elist); // delete from ACIS elist.init(); ENTITY* pEnt = NULL; while((pEnt = elist.next()) != NULL) { m_pHAPart->RemoveEntity(pEnt); } api_del_entity_list(elist); } // our application-specific read function HFileInputResult AppModel::Read(const char * FileName) { unsigned int i; HFileInputResult success = InputOK; // get the file extension char extension[120]; HUtility::FindFileNameExtension(FileName, extension); // read the file into the model object's model segment HC_Open_Segment_By_Key(m_ModelKey); HC_Open_Segment("main"); if (streq(extension,"sat")) { m_bSolidModel = true; SetBRepGeometry(true); // m_pHAPart->LoadFile(FileName,true); int depth = 0; outcome result; api_part_start_state(depth); { API_BEGIN { ENTITY_LIST elist; FILE * fp = NULL; logical res = TRUE; fp = fopen(FileName, "r"); res = (fp != NULL); if (res) { result = api_restore_entity_list(fp, TRUE, elist); res = result.ok(); } if (fp) fclose(fp); if (res) { ENTITY* entity = 0; elist.init(); while ((entity = elist.next()) != 0) AddAcisEntity(entity); } } API_END } api_part_note_state(result, depth); } else if (streq(extension,"sab")) { m_bSolidModel = true; SetBRepGeometry(true); // m_pHAPart->LoadFile(FileName,false); int depth = 0; outcome result; api_part_start_state(depth); { API_BEGIN { ENTITY_LIST elist; FILE * fp = NULL; logical res = TRUE; fp = fopen(FileName, "r"); res = (fp != NULL); if (res) { result = api_restore_entity_list(fp, FALSE, elist); res = result.ok(); } if (fp) fclose(fp); if (res) { ENTITY* entity = 0; elist.init(); while ((entity = elist.next()) != 0) AddAcisEntity(entity); } } API_END } api_part_note_state(result, depth); } else if (streq(extension,"asf")) { m_bSolidModel = true; SetBRepGeometry(true); HStreamFileToolkit tk; // tk.SetOpcodeHandler (TKE_Comment, new TK_PSComment(this)); TK_Status status = HTK_Read_Stream_File( FileName, &tk ); if( status != TK_Complete ) success = InputFail; } else { // No special read - let the base class handle m_bSolidModel = false; success = HBaseModel::Read(FileName); } HC_Close_Segment(); HC_Close_Segment(); return success; } // our application-specific write function bool AppModel::Write(const char * FileName, HBaseView * view, int version, int width, int height) { unsigned int i; bool success = true; // get the file extension char extension[120]; HUtility::FindFileNameExtension(FileName, extension); if (streq(extension,"sat")) { ENTITY_LIST savelist; GetEntityList(savelist); if (savelist.count() > 0) HA_Write_Sat_File(FileName, savelist); } else if (streq(extension,"png")) { HOutputHandlerOptions options; VCharArray width_str(128), height_str(128), temp(128), xpixels_str(128); HC_Open_Segment_By_Key(view->GetViewKey()); /* Get the size in milimeters. */ HC_Show_Device_Info(".", "size", temp); HC_Parse_String(temp, ",", 0, width_str); HC_Parse_String(temp, ",", 1, height_str); /* Get the pixels in the x direction so we can find DPI. */ HC_Show_Device_Info(".", "pixels", temp); HC_Parse_String(temp, ",", 0, xpixels_str); HC_Close_Segment(); /* Save off the window width and height in inches. */ options.WindowWidth(atof(width_str)/2.54f); options.WindowHeight(atof(height_str)/2.54f); /* DPI = xpixels / width in inches; */ options.ImageDpi(atoi(xpixels_str) / options.WindowWidth()); HBaseModel::WriteWithOptions(FileName, view, &options); } else { if(!HBaseModel::Write(FileName, view, width, height)) success = false; } return success; } logical AppModel::Undo() { return m_pHAPart->RollBack(); } logical AppModel::Redo() { return m_pHAPart->RollForward(); } logical AppModel::CanUndo() { PART* pPart = m_pHAPart->GetPart(); HISTORY_STREAM* hs = pPart->history_stream(); if (hs) return (hs->can_roll_back()!=0); return false; } logical AppModel::CanRedo() { PART* pPart = m_pHAPart->GetPart(); HISTORY_STREAM* hs = pPart->history_stream(); if (hs) return (hs->can_roll_forward()!=0); return false; } void AppModel::GetEntityList(ENTITY_LIST& elist) { if (m_pHAPart != NULL) { PART* pPart = m_pHAPart->GetPart(); if(pPart != NULL) { pPart->get_entities(elist); } } }