Пример #1
0
mitk::InteractionPositionEvent::InteractionPositionEvent(mitk::BaseRenderer* baseRenderer,
    const mitk::Point2D mousePosition,
    const std::string eventClass)
: InteractionEvent(baseRenderer, eventClass)
, m_PointerPosition(mousePosition)
{
  if (GetSender() != NULL)
  {
    m_WorldPosition = GetSender()->Map2DRendererPositionTo3DWorldPosition(&m_PointerPosition);
  }
  else
  {
    m_WorldPosition.Fill(0);
  }
}
Пример #2
0
extern "C" __declspec(dllexport) BOOL __cdecl load(HGLOBAL i_data, long i_data_len)
{
	string the_base_folder((char*)::GlobalLock(i_data), i_data_len);
	::GlobalFree(i_data);
	GetSender().sender() << the_base_folder << std::endl;
	return SakuraDLLHost::I()->load(the_base_folder);
}
Пример #3
0
extern "C" int load(char* i_data, long i_data_len) {
//	GetSender().initialize();
    string the_base_folder(i_data, i_data_len);
    free(i_data);
    GetSender().sender() << the_base_folder << endl;
    return SakuraDLLHost::I()->load(the_base_folder);
}
Пример #4
0
void
War2Wiz::Receive
	(
	JBroadcaster*	sender,
	const Message&	message
	)
{
	if (message.Is(JMessageProtocolT::kMessageReady))
		{
		JIndex senderIndex;
		WarSocket* socket = GetSender(sender, &senderIndex);
		ReceiveMessage(senderIndex, *socket);
		}

	else if (message.Is(JMessageProtocolT::kReceivedDisconnect))
		{
		ReceiveDisconnect(sender, kJFalse);
		}
	else if (message.Is(WarSocket::kTimeout))
		{
		ReceiveDisconnect(sender, kJTrue);
		}

	else
		{
		JBroadcaster::Receive(sender, message);
		}
}
//---------------------------------------------------------------------------
bool	Satori::unload() {
	GetSender().next_event();

	// ファイルに保存
	if ( is_dic_loaded ) {
		this->Save(true);
	}
	is_dic_loaded = false;

	// プラグイン解放
	mShioriPlugins->unload();

	GetSender().sender() << "■SATORI::Unload ---------------------" << std::endl;
	GetSender().flush();

	return	true;
}
BOOL CALLBACK MonitorEnumFunc(HMONITOR hMonitor,HDC hdc,LPRECT rect,LPARAM lParam) {

    MONITORINFOEX MonitorInfoEx;
    MonitorInfoEx.cbSize=sizeof(MonitorInfoEx);

	static BOOL (WINAPI* pGetMonitorInfo)(HMONITOR,LPMONITORINFO) = NULL;
	if ( ! pGetMonitorInfo ) {
		(FARPROC&)pGetMonitorInfo = ::GetProcAddress(::GetModuleHandle("user32.dll"), "GetMonitorInfoA");
	}

	if ( pGetMonitorInfo==NULL )
		return	FALSE;
	if ( !(*pGetMonitorInfo)(hMonitor,&MonitorInfoEx) ) {
		GetSender().sender() << "'GetMonitorInfo' was failed." << std::endl;
        return FALSE;
    }


	RECT* pRect = ((RECT*)lParam);

	if ( MonitorInfoEx.dwFlags & MONITORINFOF_PRIMARY ) {
		pRect[1] = *rect;
		GetSender().sender() << "モニタ: " << MonitorInfoEx.szDevice << " / (" << 
			rect->left << "," << rect->top << "," << rect->right << "," << rect->bottom << ") / primary" << std::endl;
	}
	else {
		GetSender().sender() << "モニタ: " << MonitorInfoEx.szDevice << " / (" << 
			rect->left << "," << rect->top << "," << rect->right << "," << rect->bottom << ") / extra" << std::endl;
	}

	RECT&	max_screen_rect = pRect[0];
	if ( rect->left < max_screen_rect.left )
		max_screen_rect.left = rect->left;
	if ( rect->top < max_screen_rect.top )
		max_screen_rect.top = rect->top;
	if ( rect->right > max_screen_rect.right )
		max_screen_rect.right = rect->right;
	if ( rect->bottom > max_screen_rect.bottom )
		max_screen_rect.bottom = rect->bottom;

    return TRUE;
}
// The state machine is wired up with this Paint method. We wrote a few helper
// functions at the top of this files to keep this method clear and easy to
// read.
void ExampleImageInteractor::Paint(mitk::StateMachineAction*, mitk::InteractionEvent* event)
{
  try
  {
    auto renderer = event->GetSender();

    auto image = GetImage(this->GetDataNode());
    auto timeStep = renderer->GetTimeStep();
    auto geometry = GetGeometry(image, timeStep);

    // This method is wired up to mouse events. Thus, we can safely assume
    // that the following cast will succeed and we have access to the mouse
    // position and the first intersection point of a ray originating at the
    // mouse position and shot into the scene. Convenient, isn't it? :-)
    auto positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>(event);
    auto position = positionEvent->GetPositionInWorld();

    if (!geometry->IsInside(position))
      return; // Nothing to paint, as we're not inside the image bounds.

    // Okay, we're safe. Convert the mouse position to the index of the pixel
    // we're pointing at.
    itk::Index<3> index;
    geometry->WorldToIndex<3>(position, index);

    // We don't need to paint over and over again while moving the mouse
    // pointer inside the same pixel. That's especially relevant when operating
    // on zoomed images.
    if (index != m_LastPixelIndex)
    {
      // And finally...
      ::Paint(image, index, timeStep);

      // Nearly done. We request the renderer to update the render window in
      // order to see the result immediately. Actually, we should update all
      // of the render windows by caling RequestUpdateAll() instead, as the
      // painted pixels are possibly visible in other render windows, too.
      // However, we decided to prefer performance here.
      mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow());
      MITK_INFO << index[0] << " " << index[1] << " " << index[2];

      m_LastPixelIndex = index;
    }
  }
  catch (...)
  {
    return;
  }
}
Пример #8
0
void
War2Wiz::ReceiveDisconnect
	(
	JBroadcaster*	sender,
	const JBoolean	timeout
	)
{
	JIndex senderIndex;
	GetSender(sender, &senderIndex);
	DeletePlayer(senderIndex);

	ostrstream data;
	data << senderIndex << ' ' << timeout;
	SendMessage(kWWAllPlayersIndex, kWWPlayerLeft, data);
}
Пример #9
0
void mitk::GizmoInteractor::MoveFreely(StateMachineAction*, InteractionEvent* interactionEvent)
{
  auto positionEvent = dynamic_cast<const InteractionPositionEvent*>(interactionEvent);
  if(positionEvent == NULL)
  {
    return;
  }

  Point2D currentPosition2D = positionEvent->GetPointerPositionOnScreen();

  // re-use the initial z value to really move parallel to the camera plane
  auto renderer = positionEvent->GetSender()->GetVtkRenderer();
  renderer->SetDisplayPoint(currentPosition2D[0], currentPosition2D[1], m_InitialClickPosition2DZ);
  renderer->DisplayToWorld();
  vtkVector3d worldPointVTK(renderer->GetWorldPoint());
  Point3D worldPointITK(worldPointVTK.GetData());
  Vector3D movementITK( worldPointITK - m_InitialClickPosition3D );

  ApplyTranslationToManipulatedObject(movementITK);
  RenderingManager::GetInstance()->ForceImmediateUpdateAll();
}
Пример #10
0
unsigned int NetworkSink::GetMaxWaitObjectCount() const
{
	return LimitedBandwidth::GetMaxWaitObjectCount() + GetSender().GetMaxWaitObjectCount();
}
int	Satori::request(
	const string& i_protocol,
	const string& i_protocol_version,
	const string& i_command,
	const strpairvec& i_data,
	
	string& o_protocol,
	string& o_protocol_version,
	strpairvec& o_data)
{
	SenderEnableBuffering seb(GetSender());

	//-------------------------------------------------
	// リクエスト単位のクラスメンバを初期化

	mRequestMap.clear();
	mRequestID = "";
	mReferences.clear();
	mReferences.reserve(8); // 最小値

	// 引数をクラスメンバに設定
	mRequestCommand = i_command;
	mRequestType = i_protocol;
	mRequestVersion = i_protocol_version;
	mStatusLine = i_command + " " + i_protocol + "/" + i_protocol_version;

	// 返すプロトコルのデフォルト値
	o_protocol = "SHIORI";
	o_protocol_version = "3.0";

	// 喋るごとに初期化する変数
	return_empty = false;

	surface_restore_at_talk_onetime = SR_INVALID;
	auto_anchor_enable_onetime = auto_anchor_enable;

	is_quick_section = false;

	// スクリプトヘッダ
	header_script = "";

	// プロトコルを判別
	if ( i_protocol=="SAORI" && i_protocol_version[0]>='1' )
	{
		o_protocol = i_protocol;
		o_protocol_version = "1.0";
		mRequestMode = SAORI;
	}
	else if ( i_protocol=="SHIORI" && i_protocol_version[0]>='3' )
	{
		mRequestMode = SHIORI3;
	}
	else if ( i_protocol=="SHIORI" && i_protocol_version[0]=='2' )
	{
		mRequestMode = SHIORI2;
			// 2.xにもバージョンとしては3.0を返す
	}
	else if ( i_protocol=="MAKOTO" && i_protocol_version[0]>='2' )
	{
		o_protocol = i_protocol;
		o_protocol_version = "2.0";
		mRequestMode = MAKOTO2;
	}
	else if ( i_protocol=="UNKNOWN" )
	{
		mRequestMode = UNKNOWN;
	}
	else
	{
		// 未対応のプロトコルだった。
		return	400;
	}

	// データ部をmRequestMapに格納。
	// SHOIRI/3.0以外のプロトコルの場合、SHOIRI/3.0に変換を行う。
	for ( strpairvec::const_iterator it = i_data.begin() ; it != i_data.end() ; ++it )
	{
		string key = it->first;
		const string& value = it->second;

		switch ( mRequestMode ) {
		case SAORI:
			if ( compare_head(key, "Argument") ) {
				int	n = stoi_internal(key.c_str()+8);
				if ( n==0 )
					key = "ID";
				else
					key = "Reference" + itos(n-1);
			}
			break;
		case SHIORI2:	// こっちはてきとー
			if ( key=="Event" )
				key="ID";
			break;
		case MAKOTO2:
			if ( key=="String" )
				key="Reference0";
			break;
		default:
			break;
		}

		mRequestMap[key] = value;
		if ( compare_head(key, "Reference") ) {
			int	n = stoi_internal(key.c_str()+9);
			if ( n>=0 && n<65536 ) {
				if ( n>=mReferences.size() )
					mReferences.resize(n+1);
				mReferences[n]=value;
			}
		}
	}

	if ( mRequestMode == MAKOTO2 )
	{
		mRequestMap["ID"] = "OnMakoto";
	}

	mRequestID = mRequestMap["ID"];
	mIsMateria = ( mRequestMap["Sender"] == "embryo" );
	mIsStatusHeaderExist = ( mRequestMap["Sender"] == "SSP" );

	//-------------------------------------------------
	// リクエストを解釈

	if ( mRequestCommand=="GET Version" )
	{
		if ( mRequestMode == SHIORI2 )
		{
			o_data.push_back( strpair("ID", gSatoriName) );
			o_data.push_back( strpair("Craftman", gSatoriCraftman) );
			o_data.push_back( strpair("Version", gSatoriVersion) );
		}
		return 200;
	}


	// 選択分岐記録を変数に代入。ref0を元に戻す。
	if ( compare_head(mRequestID, "OnChoice") ) // OnChoiceSelect/OnChoiceEnterの両方
	{
		strvec	vec;
		int	ref_no = ( mRequestID=="OnChoiceEnter" || mRequestID=="OnChoiceSelectEx" )?1:0;
		string&	info = mRequestMap[string("Reference")+itos(ref_no)];
		if ( split(info, byte1_dlmt, vec)==3 ) // \1区切りの3文字列であるならば
		{
			info=mReferences[ref_no]=variables["選択ID"]=vec[0];
			variables["選択ラベル"]=vec[1];
			variables["選択番号"]=vec[2];
		}
	}

	// ログについて色々
	bool log_disable_soft = ( mRequestID=="OnSurfaceChange" || mRequestID=="OnSecondChange" || mRequestID=="OnMinuteChange"
		|| mRequestID=="OnMouseMove" || mRequestID=="OnTranslate");

	bool log_disable_hard = ( /*compare_tail(mRequestID, "caption") || */compare_tail(mRequestID, "visible")
		|| compare_head(mRequestID, "menu.") || mRequestID.find(".color.")!=string::npos );

	GetSender().next_event();

	if(fRequestLog)
	{
		GetSender().sender() << "--- Request ---" << std::endl << mStatusLine <<std::endl; // << iRequest <<std::endl;
		for(strmap::const_iterator i=mRequestMap.begin() ; i!=mRequestMap.end() ; ++i)
			if ( !i->first.empty() && !i->second.empty()
				&& i->first!="SecurityLevel" 
				&& i->first!="Sender" 
				&& i->first!="Charset" ) {
				GetSender().sender() << i->first << ": " << i->second <<std::endl;
			}
	}

	// せきゅあ?
	strmap::const_iterator it = mRequestMap.find("SecurityLevel");
	secure_flag = ( it!=mRequestMap.end() && stricmp(it->second.c_str(), "local")==0 );

	// メイン処理
	GetSender().sender() << "--- Operation ---" << std::endl;

	int status_code = 500;
	if ( mRequestID=="enable_log" || mRequestID=="enable_debug" ) {
		if ( secure_flag ) {
			bool flag = false;
			if ( mReferences.size() > 0 ) {
				flag = atoi(mReferences[0].c_str()) != 0;
			}

			if ( mRequestID=="enable_debug" ) {
				fDebugMode = flag;
			}
			else {
				GetSender().validate(flag);
			}
			status_code = 200;
		}
		else {
			GetSender().sender() << "local/Localでないので蹴りました: ShioriEcho" <<std::endl;
			status_code = 403;
		}
	}
	else if ( mRequestID=="ShioriEcho" ) {
		// ShioriEcho実装
		if ( fDebugMode && secure_flag ) {
			string result = SentenceToSakuraScriptExec_with_PreProcess(mReferences);
			if ( result.length() ) {
				static const char* const dangerous_tag[] = {"\\![updatebymyself]",
					"\\![vanishbymyself]",
					"\\![enter,passivemode]",
					"\\![enter,inductionmode]",
					"\\![leave,passivemode]",
					"\\![leave,inductionmode]",
					"\\![lock,repaint]",
					"\\![unlock,repaint]",
					"\\![biff]",
					"\\![open,browser",
					"\\![open,mailer",
					"\\![raise",
					"\\j["};

				std::string replace_to;
				for ( int i = 0 ; i < (sizeof(dangerous_tag)/sizeof(dangerous_tag[0])) ; ++i ) {
					replace_to = "¥[";
					replace_to += dangerous_tag[i]+2; //\をヌキ
					replace(result,dangerous_tag[i],replace_to);
				}

				//Translate(result); - Translateは後でかかる
				mResponseMap["Value"] = result;
				status_code = 200;
			}
			else {
				status_code = 204;
			}
		}
		else {
			if ( fDebugMode ) {
				GetSender().sender() << "local/Localでないので蹴りました: ShioriEcho" <<std::endl;
				status_code = 403;
			}
			else {
				static const std::string dbgmsg = "デバッグモードが無効です。使用するためには$デバッグ=有効にしてください。: ShioriEcho";
				GetSender().sender() << dbgmsg <<std::endl;

				mResponseMap["Value"] = "\\0" + dbgmsg + "\\e";
				status_code = 200;
			}
		}
	}
	else if (mRequestID == "SatolistEcho"){
#ifndef POSIX
		// さとりすとデバッガ実装
		if (fDebugMode && secure_flag) {

			//R0は除去される
			strvec customRef;
			for (int i = 1; i < mReferences.size(); i++){
				customRef.push_back(mReferences[i]);
			}

			string result = SentenceToSakuraScriptExec_with_PreProcess(customRef);
			if (result.length()) {
				result = string("SSTP 200 OK\r\nCharset: Shift_JIS\r\nResult: ") + result + "\r\n\r\n";
			}
			else{
				//情報なし
				result = string("SSTP 204 No Content\r\nCharset: Shift_JIS\r\n\r\n");
			}

			char* copyData = new char[result.length() + 1];
			strcpy(copyData, result.c_str());

			COPYDATASTRUCT cds;
			cds.dwData = 0;
			cds.cbData = result.length() + 1;
			cds.lpData = copyData;
			DWORD ret;

			SendMessageTimeout((HWND)stoi_internal(mReferences[0]), WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds, 0, 1000, &ret);

			//ここで204を返すと非対応時のエラーを出すので200で通知メッセージを表示する
			status_code = 200;
			mResponseMap["Value"] = "\\0\\_q■情報を送信しました。\\e";
		}
		else {
			if (fDebugMode) {
				GetSender().sender() << "local/Localでないので蹴りました: SatolistEcho" <<std::endl;
				status_code = 403;
			}
			else {
				static const std::string dbgmsg = "デバッグモードが無効です。使用するためには$デバッグ=有効にしてください。: SatolistEcho";
				GetSender().sender() << dbgmsg <<std::endl;

				mResponseMap["Value"] = "\\0" + dbgmsg + "\\e";
				status_code = 200;
			}
		}
#endif // POSIX
	}
	else {
		status_code = CreateResponse(mResponseMap);
	}

	// 後処理1
	default_surface = next_default_surface;

	//--------------------------------------------------------------------

	// Valueに対する最終処理
	if ( status_code==200 ) {	// && compare_head(mRequestID, "On")
		strmap::iterator i = mResponseMap.find("Value");
		if ( i!=mResponseMap.end() ) {
			if ( return_empty ) {
				status_code = 204;
				mResponseMap.erase(i);
			}
			else {
				if ( !Translate(i->second) ) {
					status_code = 204;
					mResponseMap.erase(i);
				} 
				else {
					second_from_last_talk = 0;
					if ( compare_head(mRequestID, "On") ) {
						mResponseHistory.push_front(i->second);
						if ( mResponseHistory.size() >= RESPONSE_HISTORY_SIZE )
							mResponseHistory.pop_back();
					}
				}
			}
		}
	}

	GetSender().sender() << "status code : " << itos(status_code) <<std::endl;

	//--------------------------------------------------------------------

	for(strmap::const_iterator i=mResponseMap.begin() ; i!=mResponseMap.end() ; ++i)
	{
		string	key=i->first, value=i->second;

		switch ( mRequestMode ) {
		case SAORI:
			if ( key=="Value" ) {
				key = "Result";
				value = header_script + value;
			}
			else if ( compare_head(key, "Reference") ) {
				key = string() + "Value" + (key.c_str()+9);
			}
			break;
		case SHIORI2:
			if ( key=="Value" ) {
				key = "Sentence";
				value = header_script + value;
			}
			break;
		case MAKOTO2:
			if ( key=="Value" ) {
				key = "String";
				value = header_script + value;
			}
			break;
		default:
			if ( key=="Value" ) {
				value = header_script + value;
			}
			break;
		}
		o_data.push_back( strpair(key, value) );
	}

	if ( GetSender().errsender().get_log_mode() ) {
		const std::vector<string> &errlog = GetSender().errsender().get_log();

		std::string errmsg;
		std::string errlevel;

		for ( std::vector<string>::const_iterator itr = errlog.begin() ; itr != errlog.end(); ++itr ) {
			errmsg += "SATORI - ";
			errmsg += mRequestID;
			errmsg += " > ";
			errmsg += *itr;
			errmsg += "\1";
			errlevel += "critical\1";
		}

		if ( errmsg.length() ) {
			errmsg.erase(errmsg.end()-1,errmsg.end());
			errlevel.erase(errlevel.end()-1,errlevel.end());

			o_data.push_back( strpair("ErrorLevel",errlevel) );
			o_data.push_back( strpair("ErrorDescription",errmsg) );
		}
		GetSender().errsender().clear_log();
	}

	GetSender().validate();
	if(fResponseLog)
	{
		GetSender().sender() << "--- Response ---" <<std::endl << mResponseMap <<std::endl;
	}
	mResponseMap.clear();

	if ( log_disable_hard ) {
		GetSender().delete_last_request();
	}
	else if ( log_disable_soft ) {
		if ( status_code != 200 ) {
			GetSender().delete_last_request();
		}
	}

	GetSender().flush();

	//--------------------------------------------------------------------

	// リロード処理
	if ( reload_flag )
	{
		reload_flag = false;
		string	tmp = mBaseFolder;
		GetSender().sender() << "■■reloading." <<std::endl;
		unload();
		load(tmp);
		GetSender().sender() << "■■reloaded." <<std::endl;

		GetSender().flush();
	}

	return	status_code;
}
bool	Satori::Save(bool isOnUnload) {
	GetSender().next_event();

	// メンバ変数を里々変数化
	for (std::map<int, string>::iterator it=reserved_talk.begin(); it!=reserved_talk.end() ; ++it)
		variables[string("次から")+itos(it->first)+"回目のトーク"] = it->second;

	// 起動時間累計を設定
	variables["ゴースト起動時間累計秒"] =
	    uitos(posix_get_current_sec() - sec_count_at_load + sec_count_total,"%lu");
	// (互換用)
	variables["ゴースト起動時間累計ミリ秒"] =
	    uitos((posix_get_current_sec() - sec_count_at_load + sec_count_total)*1000,"%lu");
	variables["ゴースト起動時間累計(ms)"] =
	    uitos((posix_get_current_sec() - sec_count_at_load + sec_count_total)*1000,"%lu");

	if ( isOnUnload ) {
		secure_flag = true;
		(void)GetSentence("OnSatoriUnload");
	}

	string	theFullPath = mBaseFolder + "satori_savedata.tmp";

	std::ofstream	out(theFullPath.c_str());
	bool	temp = GetSender().is_validated();
	GetSender().validate();
	GetSender().sender() << "saving " << theFullPath << "... " ;
	GetSender().validate(temp);
	if ( !out.is_open() )
	{
		GetSender().sender() << "failed." << std::endl;
		return	false;
	}

	string	line = "*セーブデータ";
	string  data;

	out << ENCODE(line) << std::endl;
	for (strmap::const_iterator it=variables.begin() ; it!=variables.end() ; ++it) {
		string	str = zen2han(it->first);
		if ( str[0]=='S' && aredigits(str.c_str()+1) ) {
			continue;
		}
		if ( str == "今回は喋らない" || str == "今回は会話時サーフェス戻し" || str == "今回は会話時サーフィス戻し" || str == "今回は自動アンカー" ) {
			continue;
		}

		data = it->second;
		
		replace(data,"φ","φφ");
		replace(data,"(","φ(");
		replace(data,")","φ)");
		m_escaper.unescape_for_dic(data);

		string	line = string("$")+it->first+"\t"+data; // 変数を保存
		out << ENCODE(line) << std::endl;
	}

	for (std::map<string, std::vector<Word> >::const_iterator i=mAppendedWords.begin() ; i!=mAppendedWords.end() ; ++i )
	{
		if ( ! i->second.empty() ) {
			out << std::endl << ENCODE( string("@") + i->first ) << std::endl;
			for (std::vector<Word>::const_iterator j=i->second.begin() ; j!=i->second.end() ; ++j )
			{
				out << ENCODE( *j ) << std::endl;
			}
		}
	}

	out.flush();
	out.close();

	GetSender().sender() << "ok." << std::endl;

	//バックアップ
	string	realFullPath = mBaseFolder + "satori_savedata." + (fEncodeSavedata?"sat":"txt");
	string	realFullPathBackup = mBaseFolder + "satori_savebackup." + (fEncodeSavedata?"sat":"txt");
#ifdef POSIX
	unlink(realFullPathBackup.c_str());
	rename(realFullPath.c_str(),realFullPathBackup.c_str());
	rename(theFullPath.c_str(),realFullPath.c_str());
#else
	::DeleteFile(realFullPathBackup.c_str());
	::MoveFile(realFullPath.c_str(),realFullPathBackup.c_str());
	::MoveFile(theFullPath.c_str(),realFullPath.c_str());
#endif

	//いらないほうを消す
	string	delFullPath = mBaseFolder + "satori_savedata." + (fEncodeSavedata?"txt":"sat");
	string	delFullPathBackup = mBaseFolder + "satori_savebackup." + (fEncodeSavedata?"txt":"sat");
#ifdef POSIX
	unlink(delFullPath.c_str());
	unlink(delFullPathBackup.c_str());
#else
	::DeleteFile(delFullPath.c_str());
	::DeleteFile(delFullPathBackup.c_str());
#endif

	return	true;
}
bool	Satori::load(const string& iBaseFolder)
{
	GetSender().next_event();

	setlocale(LC_ALL, "Japanese");
#ifdef _WINDOWS
	_setmbcp(_MB_CP_LOCALE);
#endif

	mBaseFolder = iBaseFolder;
	GetSender().sender() << "■SATORI::Load on " << mBaseFolder << "" << std::endl;

#if POSIX
	// 「/」で終わっていなければ付ける。
	if (mBaseFolder[mBaseFolder.size() - 1] != '/') {
	    mBaseFolder += '/';
	}
#else
	// 「\」で終わっていなければ付ける。
	if (mBaseFolder[mBaseFolder.size() - 1] != '\\') {
	    mBaseFolder += '\\';
	}
#endif


#ifdef	_MSC_VER
	// 本体のあるフォルダをサーチ
	{
		TCHAR	buf[MAX_PATH+1];
		::GetModuleFileName(NULL, buf, MAX_PATH);
		char*	p = FindFinalChar(buf, DIR_CHAR);
		if ( p==NULL )
			mExeFolder = "";
		else {
			*(++p) = '\0';
			mExeFolder = buf;
		}
	}
	GetSender().sender() << "本体の所在: " << mExeFolder << "" << std::endl;
#endif // _MSC_VER

	// メンバ初期化
	InitMembers();

#ifdef	_MSC_VER
	// システムの設定を読んでおく
    OSVERSIONINFO	ovi;
    ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	::GetVersionEx(&ovi);
	string	os;
	if ( ovi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) {
		if ( ovi.dwMinorVersion == 0 ) { mOSType=SATORI_OS_WIN95; os="Windows 95"; }
		else if ( ovi.dwMinorVersion == 10 ) { mOSType=SATORI_OS_WIN98; os="Windows 98"; }
		else if ( ovi.dwMinorVersion == 90 ) { mOSType=SATORI_OS_WINME; os="Windows Me"; }
		else { mOSType = SATORI_OS_UNDEFINED; os="undefined"; }
	} else {
		if ( ovi.dwMinorVersion == 0 ) {
			if ( ovi.dwMajorVersion == 4 ) { mOSType=SATORI_OS_WINNT; os="Windows NT"; }
			else if ( ovi.dwMajorVersion == 5 ) { mOSType=SATORI_OS_WIN2K; os="Windows 2000"; }
		}
		else { mOSType = SATORI_OS_WINXP; os="Windows XP or later"; }
	}
	GetSender().sender() << "OS種別: " << os << std::endl;
	if ( mOSType==SATORI_OS_WIN95 ) {
		is_single_monitor = true;
	} else {
		BOOL (WINAPI* pEnumDisplayMonitors)(HDC,LPRECT,MONITORENUMPROC,LPARAM);
		(FARPROC&)pEnumDisplayMonitors = ::GetProcAddress(::GetModuleHandle("user32.dll"), "EnumDisplayMonitors");
		if ( pEnumDisplayMonitors==NULL ) {
			is_single_monitor = true;
		}
		else {
			RECT rectData[2];
			memset(rectData,0,sizeof(rectData));
			(*pEnumDisplayMonitors)(NULL,NULL,(MONITORENUMPROC)MonitorEnumFunc,(LPARAM)(rectData));

			max_screen_rect = rectData[0];
			desktop_rect = rectData[1];

			RECT*	rect;
			rect = &desktop_rect;
			GetSender().sender() << "プライマリデスクトップ: (" << 
				rect->left << "," << rect->top << "," << rect->right << "," << rect->bottom << ")" << std::endl;
			rect = &max_screen_rect;
			GetSender().sender() << "仮想デスクトップ: (" << 
				rect->left << "," << rect->top << "," << rect->right << "," << rect->bottom << ")" << std::endl;
			is_single_monitor = ( ::EqualRect(&max_screen_rect, &desktop_rect)!=FALSE );
			GetSender().sender() << (is_single_monitor ? 
				"モニタは一つだけと判断、見切れ判定を呼び出し元に任せます。" : 
				"複数のモニタが接続されていると判断、見切れ判定は里々が行います。") << std::endl;
		}
	}
#endif // _MSC_VER

	// 置換辞書読み取り
	strmap_from_file(replace_before_dic, mBaseFolder+"replace.txt", "\t");
	strmap_from_file(replace_after_dic, mBaseFolder+"replace_after.txt", "\t");

	// キャラデータ読み込み
	mCharacters.load(mBaseFolder + "characters.ini");
	for ( inimap::const_iterator i=mCharacters.begin() ; i!=mCharacters.end() ; ++i ) {
		const strmap& m = i->second;
		strmap::const_iterator j;

		// 置換辞書に追加
		j = m.find("popular-name");
		if ( j != m.end() && j->second.size()>0 ) 
			replace_before_dic[j->second + ":"] = string("\xff\x01") + zen2han(i->first); //0xff0x01はあとで変換
		j = m.find("initial-letter");
		if ( j != m.end() && j->second.size()>0 ) 
			replace_before_dic[j->second + ":"] = string("\xff\x01") + zen2han(i->first); //0xff0x01はあとで変換

		j = m.find("base-surface");
		if ( j != m.end() && j->second.size()>0 )
			system_variable_operation( string("サーフェス加算値") + i->first, j->second);
	}

	//for ( strmap::const_iterator j=replace_before_dic.begin() ; j!=replace_before_dic.end() ; ++j )
	//	cout << j->first << ": " << j->second << endl;

	// ランダマイズ
	randomize();


	//------------------------------------------

	// コンフィグ読み込み
	LoadDictionary(mBaseFolder + "satori_conf.txt", false);

	// 変数初期化実行
	GetSentence("初期化");	

	// SAORI読み込み
	Family<Word>* f = words.get_family("SAORI");

	mShioriPlugins->load(mBaseFolder);
	
	if ( f != NULL )
	{
		std::vector<const Word*> els;
		f->get_elements_pointers(els);

		for (std::vector<const Word*>::const_iterator i=els.begin(); i!=els.end() ; ++i)
		{
			if ( (*i)->size()>0 && !mShioriPlugins->load_a_plugin(**i) )
			{
				GetSender().sender() << "SAORI読み込み中にエラーが発生: " << **i << std::endl;
			}
		}

	}
	mShioriPlugins->load_default_entry();

	talks.clear();
	words.clear();

	//------------------------------------------

	// セーブデータ読み込み
	//bool oldConf = fEncodeSavedata;

	bool loadResult = LoadDictionary(mBaseFolder + "satori_savedata." + (fEncodeSavedata?"sat":"txt"), false);
	GetSentence("セーブデータ");
	bool execResult = talks.get_family("セーブデータ") != NULL;

	if ( ! loadResult || ! execResult ) {
		loadResult = LoadDictionary(mBaseFolder + "satori_savebackup." + (fEncodeSavedata?"sat":"txt"), false);
		GetSentence("セーブデータ");
		execResult = talks.get_family("セーブデータ") != NULL;
	}

	talks.clear();
	
	reload_flag = false;

	if ( variables.find("ゴースト起動時間累計秒") != variables.end() ) {
		sec_count_total = zen2ul(variables["ゴースト起動時間累計秒"]);
	}
	else if ( variables.find("ゴースト起動時間累計ミリ秒") != variables.end() ) {
		sec_count_total = zen2ul(variables["ゴースト起動時間累計ミリ秒"]) / 1000;
	}
	else {
		sec_count_total = zen2ul(variables["ゴースト起動時間累計(ms)"]) / 1000;
	}
	variables["起動回数"] = itos( zen2int(variables["起動回数"])+1 );

	// 「単語の追加」で登録された単語を覚えておく
	const std::map< string, Family<Word> >& m = words.compatible();
	for (std::map< string, Family<Word> >::const_iterator it = m.begin() ; it != m.end() ; ++it )
	{
		std::vector<const Word*> v;
		it->second.get_elements_pointers(v);
		for (std::vector<const Word*>::const_iterator itx = v.begin() ; itx < v.end() ; ++itx ) {
			mAppendedWords[it->first].push_back(**itx);
		}
	}

	//------------------------------------------

	// 指定フォルダの辞書を読み込み
	int loadcount = 0;
	strvec::iterator i = dic_folder.begin();
	if ( i==dic_folder.end() ) {
		loadcount += LoadDicFolder(mBaseFolder);	// ルートフォルダの辞書
	} else {
		for ( ; i!=dic_folder.end() ; ++i )
			loadcount += LoadDicFolder(mBaseFolder + *i + DIR_CHAR);	// サブフォルダの辞書
	}

	is_dic_loaded = loadcount != 0;

	//------------------------------------------

	secure_flag = true;

	system_variable_operation("単語群「*」の重複回避", "有効、トーク中");
	system_variable_operation("文「*」の重複回避", "有効");
	//system_variable_operation("単語群「季節の食べ物」の重複回避", "有効、トーク中");

	GetSentence("OnSatoriLoad");
	on_loaded_script = GetSentence("OnSatoriBoot");
	diet_script(on_loaded_script);

	GetSender().sender() << "loaded." << std::endl;

	GetSender().flush();
	return	true;
}
Пример #14
0
bool mitk::GizmoInteractor::HasPickedHandle(const InteractionEvent* interactionEvent)
{
  auto positionEvent = dynamic_cast<const InteractionPositionEvent*>(interactionEvent);
  if(positionEvent == NULL)
  {
    return false;
  }

  DataNode::Pointer gizmoNode = this->GetDataNode();

  if (m_Gizmo.IsNull())
  {
    return false;
  }

  if (m_ManipulatedObjectGeometry.IsNull())
  {
    return false;
  }

  if (interactionEvent->GetSender()->GetRenderWindow()->GetNeverRendered())
  {
    return false;
  }

  if (interactionEvent->GetSender()->GetMapperID() == BaseRenderer::Standard2D)
  {
    m_PickedHandle = PickFrom2D(positionEvent);
  }
  else
  {
    m_PickedHandle = PickFrom3D(positionEvent);
  }


  if (m_PickedHandle != Gizmo::NoHandle)
  {
    // if something relevant was picked, we calculate a number of
    // important points and axes for the upcoming geometry manipulations

    // note initial state
    m_InitialClickPosition2D = positionEvent->GetPointerPositionOnScreen();
    m_InitialClickPosition3D = positionEvent->GetPositionInWorld();

    auto renderer = positionEvent->GetSender()->GetVtkRenderer();
    renderer->SetWorldPoint(m_InitialClickPosition3D[0],
                            m_InitialClickPosition3D[1],
                            m_InitialClickPosition3D[2],
                            0);
    renderer->WorldToDisplay();
    m_InitialClickPosition2DZ = renderer->GetDisplayPoint()[2];


    m_InitialGizmoCenter3D = m_Gizmo->GetCenter();
    positionEvent->GetSender()->WorldToDisplay( m_InitialGizmoCenter3D, m_InitialGizmoCenter2D );

    m_InitialManipulatedObjectGeometry = m_ManipulatedObjectGeometry->Clone();

    switch (m_PickedHandle)
    {
      case Gizmo::MoveAlongAxisX:
      case Gizmo::RotateAroundAxisX:
      case Gizmo::ScaleX:
        m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(0);
        break;
      case Gizmo::MoveAlongAxisY:
      case Gizmo::RotateAroundAxisY:
      case Gizmo::ScaleY:
        m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(1);
        break;
      case Gizmo::MoveAlongAxisZ:
      case Gizmo::RotateAroundAxisZ:
      case Gizmo::ScaleZ:
        m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(2);
        break;
      default:
        break;
    }
    m_AxisOfMovement.Normalize();
    m_AxisOfRotation = m_AxisOfMovement;

    // for translation: test whether the user clicked into the "object's real" axis direction
    //                  or into the other one
    Vector3D intendedAxis = m_InitialClickPosition3D - m_InitialGizmoCenter3D;

    if ( intendedAxis * m_AxisOfMovement < 0 )
    {
      m_AxisOfMovement *= -1.0;
    }

    // for rotation: test whether the axis of rotation is more looking in the direction
    //               of the camera or in the opposite
    vtkCamera* camera = renderer->GetActiveCamera();
    vtkVector3d cameraDirection( camera->GetDirectionOfProjection() );

    double angle_rad = vtkMath::AngleBetweenVectors( cameraDirection.GetData(),
                                                     m_AxisOfRotation.GetDataPointer() );

    if ( angle_rad < vtkMath::Pi() / 2.0 )
    {
        m_AxisOfRotation *= -1.0;
    }

    return true;
  }
  else
  {
    return false;
  }
}
Пример #15
0
/*  AppendMsgs - append the passed message list to the passed file stream.
 *
 *  arguments:
 *      hWnd        window for error messages.
 *      pMsgList    pointer to a message list.
 *      pDestName   pointer to destination file name.
 *      options     F_TABMSG set => adds tab (4 spaces) to beginning of line
 *                  F_INDENTMSG set => use RFAIndent at beginning of line
 *                  F_FIXFROM set => replace "From" with ">From"
 *                  F_BRKLN set => print seperating line after each file
 *                  F_HEADERS set => print only headers
 *
 *  return value:
 *      FALSE (0)   append worked fine.
 *      TRUE (-1)   error during append.
 */
FLAG PASCAL INTERNAL AppendMsgs ( HW hWnd, PSTR pMsgList, PSTR pDestName, UINT options )
{
    struct vectorType *pVec = NULL;
    INT         i = -1;
    IDOC        idoc;
    FLAG        fTemp;
    FILE        *fp     = NULL;
    PSTR        pTmpFN  = NULL;
    PSTR        p       = NULL;

    if ( !( MsgList ( &pVec, &pMsgList, TRUE ) ) )
        SendMessage ( hWnd, DISPLAY, "There is an error in the message list." );
    else
    if ( ( pVec == NULL ) || ( pVec->count == 0 ) )
        SendMessage ( hWnd, DISPLAY, "No matching message set found" );
    else {
        if (TESTFLAG (options, F_HEADERS | F_SENDER | F_NUMFROM))
            fp = fopen ( pDestName, "a" );
        for ( i = 0; i < pVec->count; i++) {
            idoc = (INT) pVec->elem[i];
            if ( TESTFLAG (options, F_HEADERS)) {
                p = hdrLine ( NULL, idoc );
                fprintf ( fp, "%s\n", p );
                ZMfree ( p );
                }
            else
            if ( TESTFLAG (options, F_SENDER | F_NUMFROM)) {
                GenerateFlags ( idoc );
                p = GetSender (rgDoc[idoc].hdr, strEMPTY);
                fprintf ( fp, "%-15s", p );
                ZMfree ( p );
                if ( TESTFLAG (options, F_NUMFROM))
                    fprintf ( fp, " %4ld", (LONG)idoc+1 );
                fprintf ( fp, "\n" );
                }
            else {
                pTmpFN = mktmpnam ( );
                if ( IdocToFile ( idoc, pTmpFN, 0 ) != ERROR ) {
                    fTemp = FileFixTab ( hWnd, pTmpFN, pDestName, options,
                        idoc + 1 );
                    _unlink ( pTmpFN );
                    ZMfree ( pTmpFN );
                    if ( fTemp ) {
                        SendMessage ( hWnd, DISPLAY, "I couldn't 'fix' a message." );
                        pVec->count = i;
                        break;
                        }
                    }
                else {
                    ZMfree ( pTmpFN );
                    pVec->count = i;
                    break;
                    }
                }
            }
        PrintMsgList (hWnd, pVec);
        WndPrintf (hWnd, "\r\n");
        }
    if ( pVec != PARSEERROR )
        ZMfree ( ( PSTR ) pVec );
    if (fp != NULL)
        fclose ( fp );

    return i == -1 || i < pVec->count;
}