YASLI_INLINE bool YASLI_SERIALIZE_OVERRIDE(Archive& ar, FileSave& value, const char* name, const char* label) { if (ar.isEdit()) return ar(Serializer(value), name, label); else return ar(value.path, name, label); }
// // 匹配 // void CGateServer::OnMatch(CIOContext *pContext, WORD size) { ProtoGateClient::Match requestMatch; ProtoGateServer::Match responseMatch; BYTE buffer[PACK_BUFFER_SIZE]; CCacheBuffer writeBuffer(sizeof(buffer), buffer); // // 1. 解析消息 // if (Parser(&pContext->GetRecvBuffer(), &requestMatch, size) == FALSE) { return; } // // 2. 检查 // ProtoGateServer::ERROR_CODE err = ProtoGateServer::ERROR_CODE::ERR_NONE; if (pContext->guid == 0xffffffff) { err = ProtoGateServer::ERROR_CODE::ERR_PLAYER_NOT_LOGIN; goto ERR; } if (requestMatch.evaluation() < m_minEvaluation || requestMatch.evaluation() > m_maxEvaluation) { err = ProtoGateServer::ERROR_CODE::ERR_MATCH_INVALID_EVALUATION; goto ERR; } goto NEXT; ERR: responseMatch.set_err(err); // // 3. 序列化消息 // Serializer(&writeBuffer, &responseMatch, ProtoGateServer::RESPONSE_MSG::MATCH); // // 4. 发送 // SendTo(pContext, buffer, writeBuffer.GetActiveBufferSize()); return; NEXT: // // 5. 添加到待匹配玩家集合 // if (pContext->dwUserData == 0xffffffff) { std::map<DWORD, PlayerStatus>::const_iterator itPlayer = m_evaluations[requestMatch.evaluation()].find(pContext->guid); if (itPlayer != m_evaluations[requestMatch.evaluation()].end()) return; m_evaluations[requestMatch.evaluation()][pContext->guid].pContext = pContext; m_evaluations[requestMatch.evaluation()][pContext->guid].timeout = 0.0f; m_evaluations[requestMatch.evaluation()][pContext->guid].minEvaluation = requestMatch.evaluation(); m_evaluations[requestMatch.evaluation()][pContext->guid].maxEvaluation = requestMatch.evaluation(); pContext->dwUserData = requestMatch.evaluation(); } }
Serializer ArrayVariant::ValueImplV::createSerializer(const DataType& type) const { if (!members.empty()) return ArraySerializer(members.front().createSerializer(), numMembers); else return ArraySerializer(Serializer(), 0); }
void cMapManager::LoadMapData(void) { cCSLock Lock(m_CS); cIDCountSerializer IDSerializer(m_World->GetName()); if (!IDSerializer.Load()) { return; } unsigned int MapCount = IDSerializer.GetMapCount(); m_MapData.clear(); for (unsigned int i = 0; i < MapCount; ++i) { cMap Map(i, m_World); cMapSerializer Serializer(m_World->GetName(), &Map); if (!Serializer.Load()) { LOGWARN("Could not load map #%i", Map.GetID()); } m_MapData.push_back(Map); } }
void cMapManager::SaveMapData(void) { cCSLock Lock(m_CS); if (m_MapData.empty()) { return; } cIDCountSerializer IDSerializer(m_World->GetName()); IDSerializer.SetMapCount((unsigned)m_MapData.size()); if (!IDSerializer.Save()) { LOGERROR("Could not save idcounts.dat"); return; } for (cMapList::iterator it = m_MapData.begin(); it != m_MapData.end(); ++it) { cMap & Map = *it; cMapSerializer Serializer(m_World->GetName(), &Map); if (!Serializer.Save()) { LOGWARN("Could not save map #%i", Map.GetID()); } } }
// // 心跳 // void CGateServer::OnHeart(CIOContext *pContext, WORD size) { ProtoGateClient::Heart requestHeart; ProtoGateServer::Heart responseHeart; BYTE buffer[PACK_BUFFER_SIZE]; CCacheBuffer writeBuffer(sizeof(buffer), buffer); // // 1. 解析消息 // if (Parser(&pContext->GetRecvBuffer(), &requestHeart, size) == FALSE) { return; } // // 2. 心跳 // responseHeart.set_timestamp(requestHeart.timestamp()); // // 3. 序列化消息 // Serializer(&writeBuffer, &responseHeart, ProtoGateServer::RESPONSE_MSG::HEART); // // 4. 发送 // SendTo(pContext, buffer, writeBuffer.GetActiveBufferSize()); }
FArchive& FArray::Serialize(FArchive &Ar, void (*Serializer)(FArchive&, void*), int elementSize) { int i = 0; guard(TArray::Serialize); //-- if (Ar.IsLoading) Empty(); -- cleanup is done in TArray serializer (do not need // -- to pass array eraser/destructor to this function) // Here: // 1) when loading: 'this' array is empty (cleared from TArray's operator<<) // 2) when saving : data is not modified by this function // serialize data count int Count = DataCount; if (GameUsesFCompactIndex(Ar)) Ar << AR_INDEX(Count); else Ar << Count; if (Ar.IsLoading) { // loading array items - should prepare array Empty(Count, elementSize); DataCount = Count; } // perform serialization itself void *ptr; for (i = 0, ptr = DataPtr; i < Count; i++, ptr = OffsetPointer(ptr, elementSize)) Serializer(Ar, ptr); return Ar; unguardf("%d/%d", i, DataCount); }
void FTransaction::FObjectRecord::SerializeContents( FArchive& Ar, int32 InOper ) { if( Array ) { //UE_LOG( LogEditorTransaction, Log, TEXT("Array %s %i*%i: %i"), Object ? *Object->GetFullName() : TEXT("Invalid Object"), Index, ElementSize, InOper); check((SIZE_T)Array >= (SIZE_T)Object.Get() + sizeof(UObject)); check((SIZE_T)Array + sizeof(FScriptArray) <= (SIZE_T)Object.Get() + Object->GetClass()->GetPropertiesSize()); check(ElementSize!=0); check(DefaultConstructor!=NULL); check(Serializer!=NULL); check(Index>=0); check(Count>=0); if( InOper==1 ) { // "Saving add order" or "Undoing add order" or "Redoing remove order". if( Ar.IsLoading() ) { checkSlow(Index+Count<=Array->Num()); for( int32 i=Index; i<Index+Count; i++ ) { Destructor( (uint8*)Array->GetData() + i*ElementSize ); } Array->Remove( Index, Count, ElementSize ); } } else { // "Undo/Redo Modify" or "Saving remove order" or "Undoing remove order" or "Redoing add order". if( InOper==-1 && Ar.IsLoading() ) { Array->InsertZeroed( Index, Count, ElementSize ); for( int32 i=Index; i<Index+Count; i++ ) { DefaultConstructor( (uint8*)Array->GetData() + i*ElementSize ); } } // Serialize changed items. check(Index+Count<=Array->Num()); for( int32 i=Index; i<Index+Count; i++ ) { Serializer( Ar, (uint8*)Array->GetData() + i*ElementSize ); } } } else { //UE_LOG(LogEditorTransaction, Log, TEXT("Object %s"), *Object->GetFullName()); check(Index==0); check(ElementSize==0); check(DefaultConstructor==NULL); check(Serializer==NULL); Object->Serialize( Ar ); } }
bool cWSSAnvil::SaveChunkToNBT(const cChunkCoords & a_Chunk, cFastNBTWriter & a_Writer) { a_Writer.BeginCompound("Level"); a_Writer.AddInt("xPos", a_Chunk.m_ChunkX); a_Writer.AddInt("zPos", a_Chunk.m_ChunkZ); cNBTChunkSerializer Serializer(a_Writer); if (!m_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, Serializer)) { LOGWARNING("Cannot get chunk [%d, %d] data for NBT saving", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } Serializer.Finish(); // Close NBT tags // Save biomes, both MCS (IntArray) and MC-vanilla (ByteArray): if (Serializer.m_BiomesAreValid) { a_Writer.AddByteArray("Biomes", (const char *)(Serializer.m_VanillaBiomes), ARRAYCOUNT(Serializer.m_VanillaBiomes)); a_Writer.AddIntArray ("MCSBiomes", (const int *)(Serializer.m_Biomes), ARRAYCOUNT(Serializer.m_Biomes)); } // Save blockdata: a_Writer.BeginList("Sections", TAG_Compound); int SliceSizeBlock = cChunkDef::Width * cChunkDef::Width * 16; int SliceSizeNibble = SliceSizeBlock / 2; const char * BlockTypes = (const char *)(Serializer.m_BlockTypes); const char * BlockMetas = (const char *)(Serializer.m_BlockMetas); #ifdef DEBUG_SKYLIGHT const char * BlockLight = (const char *)(Serializer.m_BlockSkyLight); #else const char * BlockLight = (const char *)(Serializer.m_BlockLight); #endif const char * BlockSkyLight = (const char *)(Serializer.m_BlockSkyLight); for (int Y = 0; Y < 16; Y++) { a_Writer.BeginCompound(""); a_Writer.AddByteArray("Blocks", BlockTypes + Y * SliceSizeBlock, SliceSizeBlock); a_Writer.AddByteArray("Data", BlockMetas + Y * SliceSizeNibble, SliceSizeNibble); a_Writer.AddByteArray("SkyLight", BlockSkyLight + Y * SliceSizeNibble, SliceSizeNibble); a_Writer.AddByteArray("BlockLight", BlockLight + Y * SliceSizeNibble, SliceSizeNibble); a_Writer.AddByte("Y", (unsigned char)Y); a_Writer.EndCompound(); } a_Writer.EndList(); // "Sections" // Store the information that the lighting is valid. // For compatibility reason, the default is "invalid" (missing) - this means older data is re-lighted upon loading. if (Serializer.IsLightValid()) { a_Writer.AddByte("MCSIsLightValid", 1); } a_Writer.EndCompound(); // "Level" return true; }
// // 发送指定玩家 // void CGateServer::OnSendToPlayer(CIOContext *pContext, WORD size) { ProtoGateClient::SendToPlayer requestSendToPlayer; ProtoGateServer::SendToPlayer responseSendToPlayer; BYTE buffer[PACK_BUFFER_SIZE]; CCacheBuffer writeBuffer(sizeof(buffer), buffer); // // 1. 解析消息 // if (Parser(&pContext->GetRecvBuffer(), &requestSendToPlayer, size) == FALSE) { return; } // // 2. 转发协议 // if (pContext->guid == 0xffffffff) { return; } responseSendToPlayer.set_size(requestSendToPlayer.size()); responseSendToPlayer.set_data(requestSendToPlayer.data().c_str(), requestSendToPlayer.size()); // // 3. 序列化消息 // Serializer(&writeBuffer, &responseSendToPlayer, ProtoGateServer::RESPONSE_MSG::SEND_TO_PLAYER); // // 4. 发送指定玩家 // if (requestSendToPlayer.guids_size() > 0) { for (int index = 0; index < requestSendToPlayer.guids_size(); index++) { if (CIOContext *pContextSendTo = QueryContext(requestSendToPlayer.guids(index))) { if (pContext != pContextSendTo) { SendTo(pContextSendTo, buffer, writeBuffer.GetActiveBufferSize()); } } } } else { for (PlayerMap::const_iterator itPlayer = m_players.begin(); itPlayer != m_players.end(); ++itPlayer) { if (pContext != itPlayer->second) { SendTo(itPlayer->second, buffer, writeBuffer.GetActiveBufferSize()); } } } }
// // 登陆 // void CGateServer::OnLogin(CIOContext *pContext, WORD size) { ProtoGateClient::Login requestLogin; ProtoGateServer::Login responseLogin; BYTE buffer[PACK_BUFFER_SIZE]; CCacheBuffer writeBuffer(sizeof(buffer), buffer); // // 1. 解析消息 // if (Parser(&pContext->GetRecvBuffer(), &requestLogin, size) == FALSE) { return; } // // 2. 登陆 // ProtoGateServer::ERROR_CODE err = ProtoGateServer::ERROR_CODE::ERR_NONE; if (requestLogin.version() != ProtoGateServer::VERSION_NUMBER::VERSION) { err = ProtoGateServer::ERROR_CODE::ERR_VERSION_INVALID; goto ERR; } if (pContext->guid != 0xffffffff) { err = ProtoGateServer::ERROR_CODE::ERR_PLAYER_NOT_NONE; goto ERR; } if (Login(pContext, requestLogin.guid()) == FALSE) { err = ProtoGateServer::ERROR_CODE::ERR_PLAYER_INVALID_GUID; goto ERR; } responseLogin.set_guid(pContext->guid); goto NEXT; ERR: NEXT: responseLogin.set_err(err); // // 3. 序列化消息 // Serializer(&writeBuffer, &responseLogin, ProtoGateServer::RESPONSE_MSG::LOGIN); // // 4. 发送 // SendTo(pContext, buffer, writeBuffer.GetActiveBufferSize()); }
// // 游戏服务器列表 // void CGateServer::OnListGameServer(CIOContext *pContext, WORD size) { ProtoGateClient::ListGameServer requestListGameServer; ProtoGateServer::ListGameServer responseListGameServer; BYTE buffer[PACK_BUFFER_SIZE]; CCacheBuffer writeBuffer(sizeof(buffer), buffer); // // 1. 解析消息 // if (Parser(&pContext->GetRecvBuffer(), &requestListGameServer, size) == FALSE) { return; } // // 2. 获得游戏服务器列表 // ProtoGateServer::ERROR_CODE err = ProtoGateServer::ERROR_CODE::ERR_NONE; if (pContext->guid == 0xffffffff) { err = ProtoGateServer::ERROR_CODE::ERR_PLAYER_NOT_LOGIN; goto ERR; } for (GameServerMap::const_iterator itGameServer = m_servers.begin(); itGameServer != m_servers.end(); ++itGameServer) { if (ProtoGateServer::ListGameServer_GameServer *pGameServer = responseListGameServer.add_servers()) { pGameServer->set_ip(itGameServer->second.ip); pGameServer->set_port(itGameServer->second.port); pGameServer->set_curgames(itGameServer->second.curGames); pGameServer->set_maxgames(itGameServer->second.maxGames); } } goto NEXT; ERR: NEXT: responseListGameServer.set_err(err); // // 3. 序列化消息 // Serializer(&writeBuffer, &responseListGameServer, ProtoGateServer::RESPONSE_MSG::LIST_GAME_SERVER); // // 4. 发送 // SendTo(pContext, buffer, writeBuffer.GetActiveBufferSize()); }
int main(int argc, char **argv) { time_t currentTime; struct tm *_tm; time(¤tTime); _tm = localtime(¤tTime); std::cout << "Starting Medzmate Process...\n"; usleep(2000000); // InitializeStrawConfigurationFiles(); // initialize serializer Serializer serializer = Serializer(); // read patient information PatientInformation patient_info = serializer.DeserilizeFromJsonPatientInformation("Documents/patient_information.json"); patient_info.Print(); // read general configuration MedzmateConfiguration medz_config = serializer.DeserializeFromJsonMedzmateConfiguration("Documents/medzmate_config.json"); medz_config.Print(); list<DispenserConfiguration> disp_configs = list < DispenserConfiguration>(); char buffer [30]; std::string filename; for (int i = 0; i < STRAWSCOUNT; i++) { sprintf(buffer, file_name_template, letters[i]); filename.assign(buffer); DispenserConfiguration med = serializer.DeserializeFromJsonDispenserConfiguration(filename); if (!med.MedicineName.empty()) { disp_configs.push_front(med); med.Print(); } } AlertsManager alert_mngr = AlertsManager(); SchedulerProcess scheduler = SchedulerProcess(&medz_config, disp_configs, &alert_mngr); scheduler.Run(); return 0; }
static SPTR(DATATYPE) getAttribute( xmlNodePtr source, const std::string & name , bool isMandatory = true ) { SPTR(DATATYPE) castedData; xmlNodePtr fatherNode = XMLParser::findChildNamed( source, name ); if ( fatherNode ) { OSLM_ASSERT("Sorry, node '"<< name <<"' not instanced", fatherNode); xmlNodePtr node = ::fwXML::XMLParser::getChildrenXMLElement( fatherNode ); OSLM_ASSERT("Sorry, child node of '"<< name <<"' node not instanced", node); ::fwData::Object::sptr obj; obj = Serializer().ObjectsFromXml( node ); castedData = ::boost::dynamic_pointer_cast<DATATYPE>( obj ); OSLM_ASSERT("DynamicCast "<< ::fwCore::TypeDemangler<DATATYPE>().getFullClassname()<<" failed", castedData); } else if ( isMandatory ) { FW_RAISE("Sorry, attribute " << name << " is mandatory."); } return castedData; }
// // 取消匹配 // void CGateServer::OnCancelMatch(CIOContext *pContext, WORD size) { ProtoGateClient::CancelMatch requestCancelMatch; ProtoGateServer::CancelMatch responseCancelMatch; BYTE buffer[PACK_BUFFER_SIZE]; CCacheBuffer writeBuffer(sizeof(buffer), buffer); // // 1. 解析消息 // if (Parser(&pContext->GetRecvBuffer(), &requestCancelMatch, size) == FALSE) { return; } // // 2. 取消匹配 // if (pContext->dwUserData != 0xffffffff) { PlayerEvaluationMap::iterator itPlayerMap = m_evaluations.find(pContext->dwUserData); if (itPlayerMap != m_evaluations.end()) { std::map<DWORD, PlayerStatus>::iterator itPlayer = itPlayerMap->second.find(pContext->guid); if (itPlayer != itPlayerMap->second.end()) itPlayerMap->second.erase(itPlayer); if (itPlayerMap->second.empty()) m_evaluations.erase(itPlayerMap); } pContext->dwUserData = 0xffffffff; } // // 3. 序列化消息 // Serializer(&writeBuffer, &responseCancelMatch, ProtoGateServer::RESPONSE_MSG::CANCEL_MATCH); // // 4. 发送 // SendTo(pContext, buffer, writeBuffer.GetActiveBufferSize()); }
static void mapping(IO &IO, pdb::yaml::PdbTpiFieldListRecord &Obj, pdb::yaml::SerializationContext &Context) { codeview::TypeVisitorCallbackPipeline Pipeline; codeview::TypeDeserializer Deserializer; codeview::TypeSerializationVisitor Serializer(Context.FieldListBuilder, Context.TypeTableBuilder); pdb::TpiHashUpdater Hasher; if (IO.outputting()) { // For PDB to Yaml, deserialize into a high level record type, then dump // it. Pipeline.addCallbackToPipeline(Deserializer); Pipeline.addCallbackToPipeline(Context.Dumper); } else { // For Yaml to PDB, extract from the high level record type, then write it // to bytes. Pipeline.addCallbackToPipeline(Context.Dumper); Pipeline.addCallbackToPipeline(Serializer); Pipeline.addCallbackToPipeline(Hasher); } codeview::CVTypeVisitor Visitor(Pipeline); consumeError(Visitor.visitMemberRecord(Obj.Record)); }
ServerMessenger::ServerMessenger(ConnectionHandler* connection, const HeadOfficeAdmin* admin) : connection(connection), admin(admin), serializer(Serializer()) { }
ServerMessenger::ServerMessenger() : connection(NULL), admin(NULL), serializer(Serializer()) { }
static void MainLoop(void) { uint ip = 0; if(!DoLock()) return; removeFileIfExist(ParamsFile); removeFileIfExist(AnswerFile); mutexRelease(MutexHandle); SockStartup(); cout("START\n"); while(!collectEvents(StopAppEventHandle, 0)) { collectEvents(StartEventHandle, 3000); if(!DoLock()) break; if(existFile(ParamsFile)) { char *ansFile; if(Serializer) { char *wrkFile = makeTempFile(NULL); Serializer(ParamsFile, wrkFile); removeFile(ParamsFile); moveFile(wrkFile, ParamsFile); memFree(wrkFile); } removeFileIfExist(AnswerFile); // Cleanup mutexRelease(MutexHandle); cout("REQUEST START %I64u\n", getFileSize(ParamsFile)); ansFile = sockClient((uchar *)&ip, ServerDomain, ServerPort, ParamsFile, Idle); cout("REQUEST END %08x\n", ansFile); if(StopAppEventCaught || !DoLock()) { if(ansFile) { removeFile(ansFile); memFree(ansFile); } break; } removeFileIfExist(AnswerFile); // Cleanup (2bs) if(ansFile) { if(Deserializer) { Deserializer(ansFile, AnswerFile); removeFile(ansFile); } else moveFile(ansFile, AnswerFile); memFree(ansFile); cout("ANSWER %I64u\n", getFileSize(AnswerFile)); } removeFileIfExist(ParamsFile); // Cleanup eventSet(AnswerEventHandle); // リクエストの完了(応答)を通知 } mutexRelease(MutexHandle); } cout("END\n"); SockCleanup(); if(handleWaitForMillis(MutexHandle, 2000)) { // Cleanup removeFileIfExist(ParamsFile); removeFileIfExist(AnswerFile); mutexRelease(MutexHandle); } }
// // 汇报线程 // DWORD WINAPI CGameServer::ReportThread(LPVOID lpParam) { if (CGameServer *pServer = (CGameServer *)lpParam) { SOCKET sock = INVALID_SOCKET; while (WAIT_OBJECT_0 != WaitForSingleObject(pServer->m_hShutdownEvent, 0)) { Sleep(10 * 1000); int rcode = NO_ERROR; BYTE buffer[PACK_BUFFER_SIZE]; CCacheBuffer writeBuffer(sizeof(buffer), buffer); ProtoGameServer::ServerStatus requestServerStatus; // // 1. 链接网关服务器 // if (sock == INVALID_SOCKET) { sockaddr_in sockAddr; sockAddr.sin_family = AF_INET; sockAddr.sin_addr.s_addr = inet_addr(pServer->m_szGateServerIP); sockAddr.sin_port = htons(pServer->m_nGateServerPort); sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) goto RETRY; rcode = connect(sock, (const struct sockaddr *)&sockAddr, sizeof(sockAddr)); if (rcode != NO_ERROR) goto RETRY; } // // 2. 向网关服务器报告当前游戏列表 // EnterCriticalSection(&pServer->m_sectionContext); { requestServerStatus.set_ip(pServer->m_ip); requestServerStatus.set_port(pServer->m_port); requestServerStatus.set_curgames(pServer->m_curGames); requestServerStatus.set_maxgames(pServer->m_maxGames); for (int index = 0; index < pServer->m_maxGames; index++) { if (const CGame *pGame = pServer->m_games[index]) { // if ((pGame->IsEmpty() == TRUE) || // (pGame->IsFull() == FALSE && pGame->IsPrivate() == FALSE)) { if ((pGame->IsEmpty() == TRUE)) { ProtoGameServer::ServerStatus_Game *pGameStatus = requestServerStatus.add_games(); pGameStatus->set_empty(pGame->IsEmpty() ? true : false); pGameStatus->set_gameid(pGame->id); pGameStatus->set_mode(pGame->GetMode()); pGameStatus->set_mapid(pGame->GetMapID()); pGameStatus->set_evaluation(pGame->GetEvaluation()); } } } } LeaveCriticalSection(&pServer->m_sectionContext); Serializer(&writeBuffer, &requestServerStatus, ProtoGameServer::REQUEST_MSG::SERVER_STATUS); rcode = SendData((int)sock, (char *)buffer, (int)writeBuffer.GetActiveBufferSize()); if (rcode < 0) goto RETRY; continue; // // 3. 断线重连 // RETRY: if (sock != INVALID_SOCKET) { shutdown(sock, SD_BOTH); closesocket(sock); sock = INVALID_SOCKET; } } if (sock != INVALID_SOCKET) { shutdown(sock, SD_BOTH); closesocket(sock); sock = INVALID_SOCKET; } } return 0L; }
void Imposition::booklet4p(QList<int>* pages) { /* 4 page imposition looks like this: front: back: -------------------- -------------------- | | | | | | | | | | | | | | | | | | | 4 | 1 | | 2 | 3 | | | | | | | | | | | | | | | | | | | -------------------- -------------------- */ //fill the pages, so that it could be divided by for while ( (pages->count() % 4) != 0) { pages->append(0); } //create pages int targetSheets = (int)ceil(pages->count() / 4.0); //how many sheets do we have int targetPages = targetSheets * 2; //how many pages do we have targetDoc->createNewDocPages(targetPages); targetDoc->changeLayerName(0,srcDoc->layerName(0)); for (int i = 1; i < srcDoc->layerCount(); i++) { targetDoc->addLayer(srcDoc->layerName(i)); } //make guides for (int i = 0; i < targetDoc->Pages->count(); i++) { Page* p = targetDoc->Pages->at(i); //count the left guide: double guide_x = (p->width() - 2 * srcDoc->pageWidth)/2; p->guides.addVertical(guide_x, p->guides.Standard); //middle guide: guide_x += srcDoc->pageWidth; p->guides.addVertical(guide_x, p->guides.Standard); //and the right one: guide_x += srcDoc->pageWidth; p->guides.addVertical(guide_x, p->guides.Standard); //now, the top guide: double guide_y = (p->height() - srcDoc->pageHeight)/2; p->guides.addHorizontal(guide_y, p->guides.Standard); //and the bottom one: guide_y += srcDoc->pageHeight; p->guides.addHorizontal(guide_y, p->guides.Standard); } //start copying ScribusMainWindow* scMW = ScCore->primaryMainWindow(); scMW->slotSelect(); Selection* s = new Selection(scMW); //first, do the frontsides for (int i = 0; i < targetDoc->Pages->count(); i = i + 2) { targetDoc->setCurrentPage(targetDoc->Pages->at(i)); //copy the page to the clipboard //right side //make selections for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(i)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(1, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //left lower corner - right lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), 100, 100, 100, 100, //right lower corner - right upper corner 100, 100, 100, 100, 0, 100, 0, 100, //right upper corner - left upper corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 0; k < 12; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } for (int k = 28; k < 32; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } //left side for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(pages->count()-i-1)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(0, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); //clipping layerwise for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner 0, 0, 0, 0, 0, 100, 0, 100, //left lower corner - right lower corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //right lower corner - right upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), //right upper corner - left upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), 0, 0, 0, 0 }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 13; k < 28; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } } //backsides for (int i = 1; i < targetDoc->Pages->count(); i = i + 2) { targetDoc->setCurrentPage(targetDoc->Pages->at(i)); //copy the page to the clipboard //left side //make selections for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(i)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(0, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); //clipping layerwise for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner 0, 0, 0, 0, 0, 100, 0, 100, //left lower corner - right lower corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //right lower corner - right upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), //right upper corner - left upper corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), 0, 0, 0, 0 }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 13; k < 28; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } //right side for (int j = 0; j < srcDoc->Items->count(); j++) { if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(pages->count()-i-1)-1)) { s->addItem(srcDoc->Items->at(j),false); } } if (s->count() > 0) { std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste page from clipboard Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( targetDoc->Pages->at(i)->guides.vertical(1, targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard), false, &pastedObjects ); s->clear(); for (int j = 0; j < targetDoc->layerCount(); j++) { //create group out of all the items in the layer Selection* gs = new Selection(scMW); for (int k = 0; k < pastedObjects.count(); k++) { if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k)); } if (gs->count() > 0) { //create group targetDoc->itemSelection_GroupObjects(false, false, gs); //get group control signed int groupid = gs->itemAt(0)->Groups.at(0); PageItem* groupcontrol = NULL; for (int k = 0; k < targetDoc->Items->count(); k++) { if ( targetDoc->Items->at(k)->Groups.count() > 0 && targetDoc->Items->at(k)->Groups.at(0) == groupid && targetDoc->Items->at(k)->isGroupControl ) { groupcontrol = targetDoc->Items->at(k); break; } } groupcontrol->SetRectFrame(); double points[32] = { //left upper corner - left lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), //left lower corner - right lower corner targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard), 100, 100, 100, 100, //right lower corner - right upper corner 100, 100, 100, 100, 0, 100, 0, 100, //right upper corner - left upper corner 0, 100, 0, 100, targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard), targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard), }; double groupX = groupcontrol->xPos(); double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset(); double groupWidth = groupcontrol->width(); double groupHeight = groupcontrol->height(); qDebug() << groupX << groupY << groupWidth << groupHeight; for (int k = 0; k < 12; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } for (int k = 28; k < 32; k += 2) { if (points[k] < groupX) { points[k] = 0; } else if (points[k] - groupX > 100) { points[k] = 100; } else { points[k] = 100* (points[k] - groupX) / groupWidth; } if (points[k+1] < groupY) { points[k+1] = 0; } else if (points[k+1] - groupY > 100) { points[k+1] = 100; } else { points[k+1] = 100* (points[k+1] - groupY) / groupHeight; } qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n"; qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n"; } groupcontrol->SetFrameShape(32,points); } } } } }
void Imposition::changeDocGrid() { //get first copied page Page* src = srcDoc->Pages->at(cbFront->currentIndex()); double realSrcWidth = src->width() + srcDoc->bleeds.Left + srcDoc->bleeds.Right; double realSrcHeight = src->height() + srcDoc->bleeds.Top + srcDoc->bleeds.Bottom; //check whether width fits if (isOK == true) { //count how many rows and cols will be needed int cols = (int)((targetDoc->pageWidth)/realSrcWidth); // how many columns do we have on page? int rows = (int)((targetDoc->pageHeight)/realSrcHeight); // how many rows do we have on page? //now count how many pages are needed and create them int countPages=0; countPages = (int)(boxCopies->value() / (cols * rows)) + 1; if ((boxCopies->value() % (cols * rows) ) == 0) countPages--; if (chb2Sides->checkState() == Qt::Checked) countPages = countPages * 2; //double pages! targetDoc->createNewDocPages(countPages); targetDoc->changeLayerName(0,srcDoc->layerName(0)); for (int i = 1; i < srcDoc->layerCount(); i++) { targetDoc->addLayer(srcDoc->layerName(i)); } // make guides for (int i = 0; i < countPages; i++) { Page* p = targetDoc->Pages->at(i); //vertical guides double vertDist = (p->width() - p->Margins.Left - p->Margins.Right - cols*src->width())/cols; p->guides.addVertical(p->Margins.Left + 0.5*vertDist, p->guides.Standard); p->guides.addVertical(p->width() - p->Margins.Right - 0.5*vertDist, p->guides.Standard); double left = p->Margins.Left + 0.5*vertDist; double right = p->width() - p->Margins.Right - 0.5*vertDist; for (int j = 0; j < cols; j++) { left = left + src->width() + vertDist; p->guides.addVertical(left, p->guides.Standard); right = right - src->width() - vertDist; p->guides.addVertical(right, p->guides.Standard); } //horizontal guides double horizDist = (p->height() - p->Margins.Top - p->Margins.Bottom - rows*src->height())/rows; p->guides.addHorizontal(p->Margins.Top + 0.5*horizDist, p->guides.Standard); p->guides.addHorizontal(p->height() - p->Margins.Bottom - 0.5*horizDist, p->guides.Standard); double top = p->Margins.Top + 0.5*horizDist; double bottom = p->height() - p->Margins.Bottom - 0.5*horizDist; for (int j = 0; j < rows; j++) { top = top + src->height() + horizDist; p->guides.addHorizontal(top, p->guides.Standard); bottom = bottom - src->height() - horizDist; p->guides.addHorizontal(bottom, p->guides.Standard); } } //copy the first page to the clipboard ScribusMainWindow* scMW = ScCore->primaryMainWindow(); scMW->view->requestMode(modeNormal); Selection* s = new Selection(scMW); //select items to copy for (int i = 0; i < srcDoc->Items->count(); i++) { if (srcDoc->OnPage(srcDoc->Items->at(i)) == src->pageNr()) s->addItem(srcDoc->Items->at(i),false); } //Now, as all the relevant items have been copied, move the selection to the clipboard // new version: std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); int currow = 0; int curcol = 0; targetDoc->setCurrentPage(targetDoc->Pages->at(0)); Page* cur = targetDoc->currentPage(); //now, start placing for (int j = 0; j < boxCopies->value(); j++) { Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( cur->guides.vertical(curcol*2, cur->guides.Standard), cur->guides.horizontal(currow*2, cur->guides.Standard), true, &pastedObjects ); if ((curcol + 1) == cols) { curcol = 0; if ((currow + 1) == rows && (j+1 < boxCopies->value())) { currow = 0; if (chb2Sides->checkState() == Qt::Checked) { targetDoc->setCurrentPage(targetDoc->Pages->at(cur->pageNr()+2)); } else { targetDoc->setCurrentPage(targetDoc->Pages->at(cur->pageNr()+1)); } cur = targetDoc->currentPage(); } else { currow++; } } else { curcol++; } } delete s; if (chb2Sides->checkState() == Qt::Checked) { s = new Selection(scMW); targetDoc->setCurrentPage(targetDoc->Pages->at(1)); cur = targetDoc->currentPage(); src = srcDoc->Pages->at(cbBack->currentIndex()); //select items to copy for (int i = 0; i < srcDoc->Items->count(); i++) { if (srcDoc->OnPage(srcDoc->Items->at(i)) == src->pageNr()) s->addItem(srcDoc->Items->at(i),false); } //Now, as all the relevant items have been copied, move the selection to the clipboard // new version: std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //start copying from the second page currow = 0; curcol = cols-1; for ( int j = 0; j < boxCopies->value(); j++ ) { Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( cur->guides.vertical(curcol*2, cur->guides.Standard), cur->guides.horizontal(currow*2, cur->guides.Standard), true, &pastedObjects ); if ( curcol == 0 ) { curcol = cols - 1; if ( ( currow + 1 ) == rows && ( j+1 < boxCopies->value() ) ) { currow = 0; targetDoc->setCurrentPage ( targetDoc->Pages->at ( cur->pageNr() +2 ) ); cur = targetDoc->currentPage(); } else { currow++; } } else { curcol--; } } delete s; } view->Deselect(); srcDoc->view()->Deselect(); view->DrawNew(); srcDoc->view()->DrawNew(); } }
void Imposition::changeDocFold() { if (isOK == true) { //create page if (foldIsBackSide->checkState() == Qt::Checked) targetDoc->createNewDocPages(2); else targetDoc->createNewDocPages(1); //copy layers for (int i = 1; i < srcDoc->layerCount(); i++) { targetDoc->addLayer(srcDoc->layerName(i)); } targetDoc->setCurrentPage(targetDoc->Pages->at(0)); Page* p = targetDoc->currentPage(); int firstPage = foldFrontPage->currentText().toInt() - 1; int lastPage = 0; if (foldFrontPage->currentIndex() < (foldFrontPage->count()-1)) { lastPage = foldFrontPage->itemText(foldFrontPage->currentIndex()+1).toInt() - 2; } else { lastPage = firstPage + srcDoc->currentPageLayout; } //make guides double allWidth = srcDoc->pageWidth * (srcDoc->currentPageLayout+1); double allHeight = srcDoc->pageHeight; double guide_x = (p->width() - allWidth)/2; //initial (left) guide p->guides.addVertical(guide_x, p->guides.Standard); for (int i = firstPage; i <= lastPage; i++) { guide_x += srcDoc->Pages->at(i)->width(); p->guides.addVertical(guide_x,p->guides.Standard); } double guide_y = (p->height() - allHeight)/2; p->guides.addHorizontal(guide_y, p->guides.Standard); guide_y += allHeight; p->guides.addHorizontal(guide_y, p->guides.Standard); //do the copying ScribusMainWindow* scMW = ScCore->primaryMainWindow(); scMW->view->requestMode(modeNormal); Selection* s = new Selection(scMW); //select items to copy for the first page for (int i = 0; i < srcDoc->Items->count(); i++) { if ( (srcDoc->OnPage(srcDoc->Items->at(i)) >= firstPage) && (srcDoc->OnPage(srcDoc->Items->at(i)) <= lastPage) ) s->addItem(srcDoc->Items->at(i),false); } if (s->count() > 0) { //move the selection to the clipboard std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( p->guides.vertical(0, p->guides.Standard), p->guides.horizontal(0, p->guides.Standard), true, &pastedObjects ); } if (foldIsBackSide->checkState() != Qt::Checked) return; //do the second page s->clear(); firstPage = foldBackPage->currentText().toInt() - 1; if (foldBackPage->currentIndex() < (foldBackPage->count()-1)) { lastPage = foldBackPage->itemText(foldBackPage->currentIndex()+1).toInt() - 2; } else { lastPage = firstPage + srcDoc->currentPageLayout; } targetDoc->setCurrentPage(targetDoc->Pages->at(1)); p = targetDoc->currentPage(); guide_x = (p->width() - allWidth)/2; //initial (left) guide p->guides.addVertical(guide_x, p->guides.Standard); for (int i = firstPage; i <= lastPage; i++) { guide_x += srcDoc->Pages->at(i)->width(); p->guides.addVertical(guide_x,p->guides.Standard); } guide_y = (p->height() - allHeight)/2; p->guides.addHorizontal(guide_y, p->guides.Standard); guide_y += allHeight; p->guides.addHorizontal(guide_y, p->guides.Standard); for (int i = 0; i < srcDoc->Items->count(); i++) { if ( (srcDoc->OnPage(srcDoc->Items->at(i)) >= firstPage) && (srcDoc->OnPage(srcDoc->Items->at(i)) <= lastPage) ) s->addItem(srcDoc->Items->at(i),false); } if (s->count() > 0) { //move the selection to the clipboard std::ostringstream xmlString; SaxXML xmlStream(xmlString); Serializer::serializeObjects(*s, xmlStream); std::string xml(xmlString.str()); QByteArray ba(QByteArray(xml.c_str(), xml.length())); //paste Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba); targetDoc->moveGroup( p->guides.vertical(0, p->guides.Standard), p->guides.horizontal(0, p->guides.Standard), true, &pastedObjects ); } } }
bool SaveToFile(const char* filename, const Animation& animation) { Serialize(Serializer(filename), const_cast<Animation&>(animation), 0); return true; }