123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- #include "appmodel.h"
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #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 <part_api.hxx>
- #include "HTools.h"
- #include "ha_rend_options.h"
- #include "HIOManager.h"
- #include "varray.h"
- #include "HBaseView.h"
- #include "kernapi.hxx"
- #include <QtCore/QDebug>
- 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);
- }
- }
- }
|